Class Comparators
- java.lang.Object
-
- org.eclipse.collections.impl.block.factory.Comparators
-
public final class Comparators extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static SerializableComparator<Collection<?>>
ascendingCollectionSizeComparator()
static <T> SerializableComparator<T>
byBooleanFunction(BooleanFunction<T> function)
static <T> SerializableComparator<T>
byByteFunction(ByteFunction<T> function)
static <T> SerializableComparator<T>
byCharFunction(CharFunction<T> function)
static <T> SerializableComparator<T>
byDoubleFunction(DoubleFunction<T> function)
static <T> SerializableComparator<Pair<T,?>>
byFirstOfPair(Comparator<? super T> comparator)
Creates a comparator for pairs by using an existing comparator that only compares the first element of the pairstatic <T> SerializableComparator<T>
byFloatFunction(FloatFunction<T> function)
static <T,V extends Comparable<? super V>>
SerializableComparator<T>byFunction(Function<? super T,? extends V> function)
static <T,V>
SerializableComparator<T>byFunction(Function<? super T,? extends V> function, Comparator<V> comparator)
Original signature accepted a Comparator which may not be Serializable.static <T,V extends Comparable<? super V>>
SerializableComparator<T>byFunctionNullsFirst(Function<? super T,? extends V> function)
static <T,V extends Comparable<? super V>>
SerializableComparator<T>byFunctionNullsLast(Function<? super T,? extends V> function)
static <T> SerializableComparator<T>
byIntFunction(IntFunction<T> function)
static <T> SerializableComparator<T>
byLongFunction(LongFunction<T> function)
static <T> SerializableComparator<Pair<?,T>>
bySecondOfPair(Comparator<? super T> comparator)
Creates a comparator for pairs by using an existing comparator that only compares the second element of the pairstatic <T> SerializableComparator<T>
byShortFunction(ShortFunction<T> function)
static <T> SerializableComparator<T>
chain(Comparator<T>... comparators)
static <T> SerializableComparator<T>
comparableComparator()
static <T> Comparator<? super T>
comparableComparatorIfNull(Comparator<? super T> comparator)
static SerializableComparator<Collection<?>>
descendingCollectionSizeComparator()
static <T,V extends Comparable<? super V>>
SerializableComparator<T>fromFunctions(Function<? super T,? extends V> one)
static <T,V1 extends Comparable<? super V1>,V2 extends Comparable<? super V2>>
SerializableComparator<T>fromFunctions(Function<? super T,? extends V1> one, Function<? super T,? extends V2> two)
static <T,V1 extends Comparable<? super V1>,V2 extends Comparable<? super V2>,V3 extends Comparable<? super V3>>
SerializableComparator<T>fromFunctions(Function<? super T,? extends V1> one, Function<? super T,? extends V2> two, Function<? super T,? extends V3> three)
static <T> SerializableComparator<T>
fromPredicate(BiPredicate<? super T,? super T> isBeforePredicate)
static <T> SerializableComparator<T>
naturalOrder()
Uses the natural compareTo methods of the objects which will throw if there are any nulls.static <T extends Comparable<T>>
intnullSafeCompare(T value1, T value2)
static boolean
nullSafeEquals(Object value1, Object value2)
static <T,V extends Comparable<? super V>>
SerializableComparator<T>originalByFunction(Function<? super T,? extends V> function)
Deprecated.static <T,V>
SerializableComparator<T>originalByFunction(Function<? super T,? extends V> function, Comparator<V> comparator)
Deprecated.static <T> SerializableComparator<T>
originalNaturalOrder()
Deprecated.static <T> SerializableComparator<T>
originalReverseNaturalOrder()
Deprecated.static <T> SerializableComparator<SortedSetIterable<T>>
powerSet()
static <T> SerializableComparator<T>
reverse(Comparator<T> comparator)
static <T> SerializableComparator<T>
reverseNaturalOrder()
Uses the natural compareTo methods of the objects which will throw if there are any nulls.static <T> SerializableComparator<T>
safeNullsHigh(Comparator<T> notNullSafeComparator)
static <T> SerializableComparator<T>
safeNullsLow(Comparator<T> notNullSafeComparator)
-
-
-
Method Detail
-
comparableComparator
public static <T> SerializableComparator<T> comparableComparator()
- Since:
- 10.0
-
comparableComparatorIfNull
public static <T> Comparator<? super T> comparableComparatorIfNull(Comparator<? super T> comparator)
- Since:
- 10.0
-
naturalOrder
public static <T> SerializableComparator<T> naturalOrder()
Uses the natural compareTo methods of the objects which will throw if there are any nulls.
-
originalNaturalOrder
@Deprecated public static <T> SerializableComparator<T> originalNaturalOrder()
Deprecated.This method exists in order to guarantee serialization compatibility in tests.- Since:
- 11.1
-
reverseNaturalOrder
public static <T> SerializableComparator<T> reverseNaturalOrder()
Uses the natural compareTo methods of the objects which will throw if there are any nulls.
-
originalReverseNaturalOrder
@Deprecated public static <T> SerializableComparator<T> originalReverseNaturalOrder()
Deprecated.This method exists in order to guarantee serialization compatibility in tests.- Since:
- 11.1
-
reverse
public static <T> SerializableComparator<T> reverse(Comparator<T> comparator)
- Parameters:
comparator
- original comparator whose order will be reversed- Returns:
- A comparator that reverses the order of any other Serializable Comparator.
-
safeNullsLow
public static <T> SerializableComparator<T> safeNullsLow(Comparator<T> notNullSafeComparator)
-
safeNullsHigh
public static <T> SerializableComparator<T> safeNullsHigh(Comparator<T> notNullSafeComparator)
-
chain
@SafeVarargs public static <T> SerializableComparator<T> chain(Comparator<T>... comparators)
-
fromFunctions
public static <T,V extends Comparable<? super V>> SerializableComparator<T> fromFunctions(Function<? super T,? extends V> one)
-
fromFunctions
public static <T,V1 extends Comparable<? super V1>,V2 extends Comparable<? super V2>> SerializableComparator<T> fromFunctions(Function<? super T,? extends V1> one, Function<? super T,? extends V2> two)
-
fromFunctions
public static <T,V1 extends Comparable<? super V1>,V2 extends Comparable<? super V2>,V3 extends Comparable<? super V3>> SerializableComparator<T> fromFunctions(Function<? super T,? extends V1> one, Function<? super T,? extends V2> two, Function<? super T,? extends V3> three)
-
powerSet
public static <T> SerializableComparator<SortedSetIterable<T>> powerSet()
-
ascendingCollectionSizeComparator
public static SerializableComparator<Collection<?>> ascendingCollectionSizeComparator()
-
descendingCollectionSizeComparator
public static SerializableComparator<Collection<?>> descendingCollectionSizeComparator()
-
byFirstOfPair
public static <T> SerializableComparator<Pair<T,?>> byFirstOfPair(Comparator<? super T> comparator)
Creates a comparator for pairs by using an existing comparator that only compares the first element of the pair- Parameters:
comparator
- original comparator that compares the first element of the pair- Returns:
- A comparator that compares pairs only by their first element
-
bySecondOfPair
public static <T> SerializableComparator<Pair<?,T>> bySecondOfPair(Comparator<? super T> comparator)
Creates a comparator for pairs by using an existing comparator that only compares the second element of the pair- Parameters:
comparator
- original comparator that compares the second element of the pair- Returns:
- A comparator that compares pairs only by their second element
-
fromPredicate
public static <T> SerializableComparator<T> fromPredicate(BiPredicate<? super T,? super T> isBeforePredicate)
- Parameters:
isBeforePredicate
- a predicate that returns true if the first argument is less than, or should appear before, the second argument- Since:
- 12.0.0
-
byFunction
public static <T,V extends Comparable<? super V>> SerializableComparator<T> byFunction(Function<? super T,? extends V> function)
-
originalByFunction
@Deprecated public static <T,V extends Comparable<? super V>> SerializableComparator<T> originalByFunction(Function<? super T,? extends V> function)
Deprecated.This signature is kept for serialization backwards compatibility.- Since:
- 11.1
-
byFunctionNullsLast
public static <T,V extends Comparable<? super V>> SerializableComparator<T> byFunctionNullsLast(Function<? super T,? extends V> function)
-
byFunctionNullsFirst
public static <T,V extends Comparable<? super V>> SerializableComparator<T> byFunctionNullsFirst(Function<? super T,? extends V> function)
-
byBooleanFunction
public static <T> SerializableComparator<T> byBooleanFunction(BooleanFunction<T> function)
-
byByteFunction
public static <T> SerializableComparator<T> byByteFunction(ByteFunction<T> function)
-
byCharFunction
public static <T> SerializableComparator<T> byCharFunction(CharFunction<T> function)
-
byDoubleFunction
public static <T> SerializableComparator<T> byDoubleFunction(DoubleFunction<T> function)
-
byFloatFunction
public static <T> SerializableComparator<T> byFloatFunction(FloatFunction<T> function)
-
byIntFunction
public static <T> SerializableComparator<T> byIntFunction(IntFunction<T> function)
-
byLongFunction
public static <T> SerializableComparator<T> byLongFunction(LongFunction<T> function)
-
byShortFunction
public static <T> SerializableComparator<T> byShortFunction(ShortFunction<T> function)
-
byFunction
public static <T,V> SerializableComparator<T> byFunction(Function<? super T,? extends V> function, Comparator<V> comparator)
Original signature accepted a Comparator which may not be Serializable. This signature is kept for backwards compatibility.
-
originalByFunction
@Deprecated public static <T,V> SerializableComparator<T> originalByFunction(Function<? super T,? extends V> function, Comparator<V> comparator)
Deprecated.Original signature accepted a Comparator which may not be Serializable. This signature is kept for backwards compatibility.
-
nullSafeCompare
public static <T extends Comparable<T>> int nullSafeCompare(T value1, T value2)
-
-