Package org.apache.sis.internal.filter
Class SortByComparator<R>
java.lang.Object
org.apache.sis.internal.filter.SortByComparator<R>
- Type Parameters:
R- the type of resources (typicallyFeature) to sort.
- All Implemented Interfaces:
Serializable,Comparator<R>,SortBy<R>
Comparator sorting features using an array of
SortProperty elements applied in order.- Since:
- 1.0
- Version:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SortProperty<R>[]The sort order specified to the constructor.private static final longFor cross-version compatibility. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSortByComparator(Map<?, SortProperty<R>> merged) Creates a new comparator with the values of given map.privateCreates a new comparator for the given sort expression. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <R> voidaddAll(List<SortProperty<R>> properties, Map<ValueReference<? super R, ?>, SortProperty<R>> merged) Adds all elements of thepropertieslist into themergedmap.intCompares two resources for order.static <R> SortBy<? super R>concatenate(SortBy<? super R> sort, Comparator<? super R> comparator) Creates a new comparator as the concatenation of the two given comparators.static <R> SortBy<R>concatenate(SortBy<R> s1, SortBy<R> s2) Creates a new comparator as the concatenation of the two given comparators.static <R> SortByComparator<R>create(SortProperty<R>[] properties) Creates a new comparator for the given sort expressions.Returns the properties whose values are used for sorting.thenComparing(Comparator<? super R> other) Returns a comparator as the concatenation of this comparator with the given one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
properties
The sort order specified to the constructor.- See Also:
-
-
Constructor Details
-
SortByComparator
Creates a new comparator for the given sort expression. This is shortcut for the common case where there is a single expression.- Parameters:
p- the property to wrap in aSortBycomparator.
-
SortByComparator
Creates a new comparator with the values of given map. The map is used for removing duplicated expressions.
-
-
Method Details
-
create
Creates a new comparator for the given sort expressions.- Type Parameters:
R- the type of resources (typicallyFeature) to sort.- Parameters:
properties- the sort order.- Returns:
- the comparator, or
nullif the given array is empty.
-
concatenate
public static <R> SortBy<? super R> concatenate(SortBy<? super R> sort, Comparator<? super R> comparator) Creates a new comparator as the concatenation of the two given comparators. The first comparator is used first, and if two resources are equal then the second comparator is used.- Type Parameters:
R- the type of resources (typicallyFeature) to sort.- Parameters:
sort- the first "sort by" to use, ornullif none.comparator- the second "sort by" to use.- Returns:
- concatenation of the two comparators.
-
concatenate
Creates a new comparator as the concatenation of the two given comparators. The first comparator is used first, and if two resources are equal then the second comparator is used.- Type Parameters:
R- the type of resources (typicallyFeature) to sort.- Parameters:
s1- the first "sort by" to use.s2- the second "sort by" to use.- Returns:
- concatenation of the two comparators.
-
addAll
private static <R> void addAll(List<SortProperty<R>> properties, Map<ValueReference<? super R, ?>, SortProperty<R>> merged) Adds all elements of thepropertieslist into themergedmap. If twoSortPropertyinstances use the sameValueReference, then only the first occurrence is retained. -
getSortProperties
Returns the properties whose values are used for sorting. The list shall have a minimum of one element.- Specified by:
getSortPropertiesin interfaceSortBy<R>
-
compare
Compares two resources for order. Returns a negative number ifr1should be sorted beforer2, a positive number ifr2should be afterr1, or 0 if both resources are equal. The ordering of null resources or null property values is unspecified.- Specified by:
comparein interfaceComparator<R>
-
thenComparing
Returns a comparator as the concatenation of this comparator with the given one. This comparator is used first, and if two resources are equal then the other comparator is used.- Specified by:
thenComparingin interfaceComparator<R>- Parameters:
other- the other comparator to be used when this comparator considers two resources as equal.- Returns:
- concatenation of this comparator with the given one.
-