Java tutorial
/** * Copyright (c) 2005-2009 springside.org.cn * * Licensed under the Apache License, Version 2.0 (the "License"); * * $Id: PropertyFilter.java,v 1.1 2009/09/22 00:55:29 test Exp $ */ package com.xyz.util; import org.apache.commons.lang.StringUtils; /** * ORM??. * * PropertyFilter????? * * TODO:?????. * * @author calvin */ public class PropertyFilter { /** * OR. */ private static final String OR_SEPARATOR = "_OR_"; /** * . */ public enum MatchType { EQ, LIKE, LT, GT, LE, GE; } private String[] propertyNames = null; private Object value; private MatchType matchType = MatchType.EQ; public PropertyFilter() { } /** * * @param filterName EQ_S_NAME * @param value */ public PropertyFilter(final String filterName, final Object value) { String matchTypeCode = StringUtils.substringBefore(filterName, "_"); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode.toUpperCase()); } catch (RuntimeException e) { throw new IllegalArgumentException("filter??,.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.value = value; } /** * ? */ public boolean isMultiProperty() { return (propertyNames.length > 1); } /** * ???. */ public String getPropertyName() { if (propertyNames.length > 1) throw new IllegalArgumentException("There are not only one property"); return propertyNames[0]; } /** * ???. */ public String[] getPropertyNames() { return propertyNames; } public Object getValue() { return value; } public MatchType getMatchType() { return matchType; } }