java.util.Comparator<T>public class OrderByComparator<T>
extends java.lang.Object
implements java.util.Comparator<T>
An OrderByComparator is a Comparator that is
capable of comparing two objects based on a dynamic list of properties of
the objects of type T. It can sort any of its properties
ascending or descending, and for any of its properties, it can place nulls
first or last. Like SQL, this will default to ascending. Nulls default to
last if ascending, and first if descending.
This is based on jAgg's PropertiesComparator, which as of
the time of creation of this class always does ascending, nulls last.
| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
ASC |
Sort ascending (default).
|
static java.lang.String |
DESC |
Sort descending.
|
static java.lang.String |
FIRST |
Sort nulls first (default if descending order).
|
static java.lang.String |
LAST |
Sort nulls last (default if ascending order).
|
static java.lang.String |
NULLS |
Use this to indicate which sequence nulls should be ordered.
|
static int |
NULLS_FIRST |
Constant to order nulls first.
|
static int |
NULLS_LAST |
Constant to order nulls last.
|
static int |
ORDER_ASC |
Constant to order ascending.
|
static int |
ORDER_DESC |
Constant to order descending.
|
| Constructor | Description |
|---|---|
OrderByComparator(java.util.List<java.lang.String> expressions) |
Constructs an
OrderByComparator based on a List
of expressions, of the format "property [ASC|DESC] [NULLS FIRST|LAST]". |
| Modifier and Type | Method | Description |
|---|---|---|
int |
compare(T o1,
T o2) |
Compares the given objects to determine order.
|
boolean |
equals(java.lang.Object obj) |
Indicates whether the given
OrderByComparator is equal to
this OrderByComparator. |
java.util.List<java.lang.Integer> |
getNullOrderings() |
Returns a
List of null orderings. |
java.util.List<java.lang.Integer> |
getOrderings() |
Returns a
List of orderings. |
java.util.List<java.lang.String> |
getProperties() |
Returns a
List of all properties. |
public static final java.lang.String ASC
public static final java.lang.String DESC
public static final java.lang.String NULLS
public static final java.lang.String FIRST
public static final java.lang.String LAST
public static final int ORDER_ASC
public static final int ORDER_DESC
public static final int NULLS_LAST
public static final int NULLS_FIRST
public OrderByComparator(java.util.List<java.lang.String> expressions)
OrderByComparator based on a List
of expressions, of the format "property [ASC|DESC] [NULLS FIRST|LAST]".expressions - A List of expressions.ParseException - If there is a problem parsing the expressions.public int compare(T o1, T o2) throws java.lang.UnsupportedOperationException
Compares the given objects to determine order. Fulfills the
Comparator contract by returning a negative integer, 0, or a
positive integer if o1 is less than, equal to, or greater
than o2.
This compare method respects all properties, their order sequences, and their null order sequences.
compare in interface java.util.Comparator<T>o1 - The left-hand-side object to compare.o2 - The right-hand-side object to compare.o1
is less than, equal to, or greater than o2.java.lang.UnsupportedOperationException - If any property specified in the
constructor doesn't correspond to a no-argument "get<Property>"
getter method in T, or if the property's type is not
Comparable.public boolean equals(java.lang.Object obj)
OrderByComparator is equal to
this OrderByComparator. All property names must match in
order, and all of the order sequences and null order sequences must
match.equals in interface java.util.Comparator<T>equals in class java.lang.Objectobj - The other OrderByComparator.public java.util.List<java.lang.String> getProperties()
List of all properties.List of all properties.public java.util.List<java.lang.Integer> getOrderings()
List of orderings.List of orderings.ORDER_ASC,
ORDER_DESCpublic java.util.List<java.lang.Integer> getNullOrderings()
List of null orderings.List of null orderings.NULLS_FIRST,
NULLS_LASTCopyright © 2012–2018 Jett Team. All rights reserved.