📄 filterclause.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//////////// 27.05.2002 NK added in Jahiapackage org.jahia.data.containers;import org.jahia.utils.JahiaConsole;/** * Hold information about a filtering clause. * * @see ContainerFilterBean * @author Khue Nguyen <a href="mailto:khue@jahia.org">khue@jahia.org</a> */class FilterClause { private static final String CLASS_NAME = FilterClause.class.getName(); /** The lower comparator or simple comparator **/ private String lowerComp; /** The upper comparator **/ private String upperComp; /** The array of values **/ private String[] values; /** The valid state of this clause instance **/ private boolean isValid = false; /** If this clause a range clause ( with two comparators ) **/ private boolean isRangeClause = false; //-------------------------------------------------------------------------- /** * Constructor for a simple comparison clause with a single value. * * @param String comparator, the comparator * @param String value, the value */ public FilterClause(String comp, String value){ if ( value != null && comp != null ) { String[] values = {value}; this.values = values; this.lowerComp = comp; this.isValid = true; } } //-------------------------------------------------------------------------- /** * Constructor for a simple comparison clause with a multiple values. * * @param String comparator, the comparator * @param String[] values, the values */ public FilterClause(String comp, String[] values){ if ( (values != null) && (values.length>0)&& (comp != null) ) { this.values = values; this.lowerComp = comp; this.isValid = true; } } //-------------------------------------------------------------------------- /** * Constructor for a range comparison clause. * * @param String lowerComp, the lower comparator * @param String upperComp, the upper comparator * @param String lowerValue, the lower value * @param String upperValue, the upper value */ public FilterClause( String lowerComp, String upperComp, String lowerVal, String upperVal ){ if ( (lowerVal != null) && (upperVal != null) && (lowerComp != null) && (upperComp != null) ) { String[] values = {lowerVal,upperVal}; this.values = values; this.lowerComp = lowerComp; this.upperComp = upperComp; this.isValid = true; this.isRangeClause = true; } } /** * Return true if this clause is valid. */ public boolean isValid(){ return this.isValid; } /** * Return true if this clause is a range clause ( with two comparators ) */ public boolean isRangeClause(){ return this.isRangeClause; } /** * Return the values. */ public String[] getValues(){ return this.values; } /** * Return the single value (= the first value [0] in the values array). */ public String getValue(){ return this.values[0]; } /** * return the lower value (= the first value [0] in the values array). */ public String getLowerValue(){ return this.values[0]; } /** * return the upper value (= the second value [1] in the values array). */ public String getUpperValue(){ return this.values[1]; } /** * return the comparator for a simple clause. */ public String getComp(){ return this.lowerComp; } /** * return the lower comparator for a range clause. */ public String getLowerComp(){ return this.lowerComp; } /** * return the upper comparator for a range clause. */ public String getUpperComp(){ return this.upperComp; } //-------------------------------------------------------------------------- /** * Return true if the given Long value match this clause * Here, the clause's values are converted to long and a number comparison is performed * * @param long value * @return boolean , the comparison result. */ public boolean compare(long value){ if ( !isValid ){ return false; } boolean result = false; try { String comp = getComp(); Long L = Long.valueOf(getValue()); result = compare(value,L.longValue(),comp); if ( result && isRangeClause() ) { L = Long.valueOf(getUpperValue()); result = compare(value,L.longValue(),getUpperComp()); } } catch ( Throwable t ){ t.printStackTrace(); } return result; } //-------------------------------------------------------------------------- /** * Return true if the given long valueA (left) match the given valueB (right) * * @param String valueA * @param String valueB * @param String comp, the comparator * @return boolean , the comparison result. */ private boolean compare(long valueA, long valueB, String comp){ boolean result = false; if ( comp.equals(ContainerFilterBean.COMP_EQUAL) ){ result = ( valueA == valueB ); } else if ( comp.equals(ContainerFilterBean.COMP_SMALLER) ){ result = ( valueA < valueB ); } else if ( comp.equals(ContainerFilterBean.COMP_SMALLER_OR_EQUAL) ){ result = ( valueA <= valueB ); } else if ( comp.equals(ContainerFilterBean.COMP_BIGGER_OR_EQUAL) ){ result = ( valueA >= valueB ); } else if ( comp.equals(ContainerFilterBean.COMP_BIGGER) ){ result = ( valueA > valueB ); } //JahiaConsole.println(CLASS_NAME+".compare","valueA["+ valueA +"] " + comp + " valueB[" + valueB + "] result=" + result); return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -