assertTrue(byLengthOrdering.reverse().isOrdered(list));
OrderingIs the "smooth version" of Guava"ComparatorIt is used to build advanced comparator and apply comparator to various collections ).
OrderingThe instance is just a special
Ordering
|
|
Natural () |
Natural sorting(Natural ordering ). |
UsingToString () |
The return values of toString () are ordered alphabetically.
|
However
Ordering<String> byLengthOrdering = Ordering<String>
OrderingTo perform some preprocessing. Some of the most common solutions are as follows:
|
|
Reverse () |
|
NullsFirst () |
OrderingPlace the null element before the non-null element.Ordering is the same.The same is true for nullsLast.
|
Compound (Comparator) |
OrderingUse the specifiedComparatorSort again. |
Lexicographical () |
OrderingThe iterable elements are ordered alphabetically. |
OnResultOf (Function) |
OrderingPass the sorted elements into the function and use the originalOrdering sorting.
|
Processing null values based on sortedBy. The following is a solution for application chain call:
Ordering<Foo> ordering = Ordering.natural().nullsFirst().onResultOf(newFunction<Foo,String>
In Ordering.
The chain call of compound should be viewed from left to right. To avoid confusion, do not CompoundMixed processing of calls and other chained calls .)
Ordering<Foo> ordering = Ordering.natural().nullsFirst().onResultOf(sortKeyFunction);
|
|
|
GreatestOf (Iterable iterable, int k) |
|
LeastOf |
IsOrdered (Iterable) |
IterableWhether or not the ordering sorting rules are ordered (monotonic non-subtraction ). |
IsStrictlyOrdered |
SortedCopy (Iterable) |
|
ImmutableSortedCopy |
Min (E, E) |
|
Max (E, E) |
Min (E, E ...) |
The smallest of the two parameters is returned Based on the ordering sorting rule. If there are multiple equal minimum values, the first value is returned.
|
Max (E, E ...) |
Min (Iterable) |
The minimum Iterable value. IfThisIterableIf it is null, return |
Max (Iterable),Min (Iterator),Max (Iterator) |