T - The type of the Objects to compare.@Status(stage=PRODUCTION, unitTests=COMPLETE) @Review(by="Kees Schotanus", at="2009-09-28") @ThreadSafety(level=NOT_THREAD_SAFE, doc="MultiFieldComparators are mutable!") public final class MultiFieldComparator<T> extends Object implements Comparator<T>
CompareField objects (as opposed to Method objects to construct this MultiFieldComparator it
is possible to compare fields that are present in an object that has a one to one relationship with type <T>.| Constructor and Description |
|---|
MultiFieldComparator(CompareField... allowedCompareFields)
Constructs this MultiFieldComparator from the supplied compareFields.
|
MultiFieldComparator(Method... methods)
Creates this MultiFieldComparator from the supplied methods by converting them to
CompareField objects. |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(T left,
T right)
Utility method to compare two objects of type <T>.
|
CompareField |
getCompareField(int ordinal)
Gets an CompareField by its ordinal number.
|
CompareField |
getCompareField(String methodName)
Gets a CompareField by the name of its corresponding method.
|
void |
setCompareFields(CompareField... compareFields)
Sets the fields to compare upon.
|
void |
sort(List<T> items,
String... sortColumns)
Sort the supplied items on the supplied sortColumns.
|
String |
toString()
Creates a String representation of this MultiFieldComparator.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic MultiFieldComparator(CompareField... allowedCompareFields)
allowedCompareFields - All the compare fields that can possibly be compared upon.NullPointerException - When the supplied allowedCompareFields is null.IllegalArgumentException - When the supplied allowedCompareFields is empty.public MultiFieldComparator(Method... methods)
CompareField objects.methods - The methods used for ordering.NullPointerException - When the supplied methods is null.IllegalArgumentException - When the supplied methods is empty.public void setCompareFields(CompareField... compareFields)
compareFields - The fields to compare upon.NullPointerException - When the supplied compareFields is null.IllegalArgumentException - When the supplied compareFields is empty or contains a CompareField that is not one of
the allowed CompareFields supplied at construction time.public CompareField getCompareField(String methodName)
methodName - The name of the method.
IllegalArgumentException - When the supplied methodName is empty or when no CompareField with the supplied
methodName exists.NullPointerException - When the supplied methodName is null.public CompareField getCompareField(int ordinal)
ordinal - The ordinal of the compare field (0 based).IllegalArgumentException - When no CompareField with the supplied ordinal exists.public int compare(T left, T right)
Comparable comparing is
trivial, when the actual fields to compare are not Comparable, they are both converted to a String before being
compared.compare in interface Comparator<T>left - The Object on the left.right - The Object on the right.NullPointerException - When either the supplied left or right object is null.IllegalStateException - When a reflection exception occurs or when no columns to sort upon have been set.public void sort(List<T> items, String... sortColumns)
items - The items to sort.sortColumns - The names of the columns to sort on.
IllegalArgumentException - When the supplied sortColumns is empty.NullPointerException - When the supplied sortColumns is null.public String toString()
CompareField.toString() method.Copyright © 2008–2017. All rights reserved.