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 long
For cross-version compatibility. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
SortByComparator
(Map<?, SortProperty<R>> merged) Creates a new comparator with the values of given map.private
Creates a new comparator for the given sort expression. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <R> void
addAll
(List<SortProperty<R>> properties, Map<ValueReference<? super R, ?>, SortProperty<R>> merged) Adds all elements of theproperties
list into themerged
map.int
Compares 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, wait
Methods 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 aSortBy
comparator.
-
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
null
if 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, ornull
if 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 theproperties
list into themerged
map. If twoSortProperty
instances 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:
getSortProperties
in interfaceSortBy<R>
-
compare
Compares two resources for order. Returns a negative number ifr1
should be sorted beforer2
, a positive number ifr2
should be afterr1
, or 0 if both resources are equal. The ordering of null resources or null property values is unspecified.- Specified by:
compare
in 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:
thenComparing
in 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.
-