Package org.zkoss.zul
Class FieldComparator
- java.lang.Object
-
- org.zkoss.zul.FieldComparator
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.Comparator
public class FieldComparator extends java.lang.Object implements java.util.Comparator, java.io.Serializable
Based on the the given field names to compare the field value of the object that is passed in
compare(java.lang.Object, java.lang.Object)
method.The field names accept compound "a.b.c" expression. It also accept multiple field names that you can give expression in the form of e.g. "name, age, salary" and this comparator will compare in that sequence.
- Since:
- 3.6.0
- Author:
- henrichen
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description FieldComparator(java.lang.String orderBy, boolean ascending)
Compares with the fields per the given "ORDER BY" clause.FieldComparator(java.lang.String orderBy, boolean ascending, boolean nullAsMax)
Compares with the fields per the given "ORDER BY" clause.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(java.lang.Object o1, java.lang.Object o2)
boolean
equals(java.lang.Object o)
java.lang.String
getOrderBy()
Returns the order-by clause.java.lang.String
getRawOrderBy()
Returns the original order-by clause passed to the constructor.int
hashCode()
boolean
isAscending()
Returns whether the sorting is ascending.
-
-
-
Constructor Detail
-
FieldComparator
public FieldComparator(java.lang.String orderBy, boolean ascending)
Compares with the fields per the given "ORDER BY" clause.Note: It assumes null as minimum value. If not, use
FieldComparator(String, boolean, boolean)
instead.- Parameters:
orderBy
- the "ORDER BY" clause to be compared upon for the given object incompare(java.lang.Object, java.lang.Object)
.ascending
- whether to sort as ascending (or descending).
-
FieldComparator
public FieldComparator(java.lang.String orderBy, boolean ascending, boolean nullAsMax)
Compares with the fields per the given "ORDER BY" clause.- Parameters:
orderBy
- the "ORDER BY" clause to be compared upon for the given object incompare(java.lang.Object, java.lang.Object)
.ascending
- whether to sort as ascending (or descending).nullAsMax
- whether to consider null as the maximum value. If false, null is considered as the minimum value.
-
-
Method Detail
-
compare
public int compare(java.lang.Object o1, java.lang.Object o2)
- Specified by:
compare
in interfacejava.util.Comparator
-
getOrderBy
public java.lang.String getOrderBy()
Returns the order-by clause. Notice that is the parsed result, such asname=category ASC
. For the original format, please usegetRawOrderBy()
.
-
getRawOrderBy
public java.lang.String getRawOrderBy()
Returns the original order-by clause passed to the constructor. It is usually the field's name, such ascategory
, or a concatenation of field names, such ascategory.name
.Notice that, with the field's name, you could retrieve the value by use of
Fields.getByCompound(java.lang.Object, java.lang.String)
.- Since:
- 5.0.6
-
isAscending
public boolean isAscending()
Returns whether the sorting is ascending.- Since:
- 5.0.6
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Comparator
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-