Class Comparators
- java.lang.Object
-
- org.eclipse.collections.impl.block.factory.Comparators
-
public final class Comparators extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Comparators.AscendingCollectionSizeComparator
private static class
Comparators.ByFirstOfPairComparator<T>
private static class
Comparators.BySecondOfPairComparator<T>
private static class
Comparators.ChainedComparator<T>
private static class
Comparators.ComparableComparator<T>
private static class
Comparators.DescendingCollectionSizeComparator
private static class
Comparators.NaturalOrderComparator<T extends java.lang.Comparable<T>>
private static class
Comparators.PowerSetComparator<T>
private static class
Comparators.ReverseComparator<T>
private static class
Comparators.SafeNullsHighComparator<T>
private static class
Comparators.SafeNullsLowComparator<T>
-
Field Summary
Fields Modifier and Type Field Description private static SerializableComparator<java.util.Collection<?>>
ASCENDING_COLLECTION_SIZE_COMPARATOR
private static SerializableComparator<?>
COMPARABLE_COMPARATOR
private static SerializableComparator<java.util.Collection<?>>
DESCENDING_COLLECTION_SIZE_COMPARATOR
private static SerializableComparator<?>
NATURAL_ORDER_COMPARATOR
private static SerializableComparator<?>
POWER_SET_COMPARATOR
private static SerializableComparator<?>
REVERSE_NATURAL_ORDER_COMPARATOR
-
Constructor Summary
Constructors Modifier Constructor Description private
Comparators()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static SerializableComparator<java.util.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(java.util.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 java.lang.Comparable<? super V>>
SerializableComparator<T>byFunction(Function<? super T,? extends V> function)
static <T,V>
SerializableComparator<T>byFunction(Function<? super T,? extends V> function, java.util.Comparator<V> comparator)
Original signature accepted a Comparator which may not be Serializable.static <T,V extends java.lang.Comparable<? super V>>
SerializableComparator<T>byFunctionNullsFirst(Function<? super T,? extends V> function)
static <T,V extends java.lang.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(java.util.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(java.util.Comparator<T>... comparators)
static <T> SerializableComparator<T>
comparableComparator()
static <T> java.util.Comparator<? super T>
comparableComparatorIfNull(java.util.Comparator<? super T> comparator)
static SerializableComparator<java.util.Collection<?>>
descendingCollectionSizeComparator()
static <T,V extends java.lang.Comparable<? super V>>
SerializableComparator<T>fromFunctions(Function<? super T,? extends V> one)
static <T,V1 extends java.lang.Comparable<? super V1>,V2 extends java.lang.Comparable<? super V2>>
SerializableComparator<T>fromFunctions(Function<? super T,? extends V1> one, Function<? super T,? extends V2> two)
static <T,V1 extends java.lang.Comparable<? super V1>,V2 extends java.lang.Comparable<? super V2>,V3 extends java.lang.Comparable<? super V3>>
SerializableComparator<T>fromFunctions(Function<? super T,? extends V1> one, Function<? super T,? extends V2> two, Function<? super T,? extends V3> three)
private static <T,V extends java.lang.Comparable<? super V>>
SerializableComparator<T>getPrimitiveFunctionComparator(Function<? super T,? extends V> function)
static <T> SerializableComparator<T>
naturalOrder()
Uses the natural compareTo methods of the objects which will throw if there are any nulls.static <T extends java.lang.Comparable<T>>
intnullSafeCompare(T value1, T value2)
static boolean
nullSafeEquals(java.lang.Object value1, java.lang.Object value2)
static <T,V extends java.lang.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, java.util.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(java.util.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(java.util.Comparator<T> notNullSafeComparator)
static <T> SerializableComparator<T>
safeNullsLow(java.util.Comparator<T> notNullSafeComparator)
-
-
-
Field Detail
-
COMPARABLE_COMPARATOR
private static final SerializableComparator<?> COMPARABLE_COMPARATOR
-
NATURAL_ORDER_COMPARATOR
private static final SerializableComparator<?> NATURAL_ORDER_COMPARATOR
-
REVERSE_NATURAL_ORDER_COMPARATOR
private static final SerializableComparator<?> REVERSE_NATURAL_ORDER_COMPARATOR
-
POWER_SET_COMPARATOR
private static final SerializableComparator<?> POWER_SET_COMPARATOR
-
ASCENDING_COLLECTION_SIZE_COMPARATOR
private static final SerializableComparator<java.util.Collection<?>> ASCENDING_COLLECTION_SIZE_COMPARATOR
-
DESCENDING_COLLECTION_SIZE_COMPARATOR
private static final SerializableComparator<java.util.Collection<?>> DESCENDING_COLLECTION_SIZE_COMPARATOR
-
-
Method Detail
-
comparableComparator
public static <T> SerializableComparator<T> comparableComparator()
- Since:
- 10.0
-
comparableComparatorIfNull
public static <T> java.util.Comparator<? super T> comparableComparatorIfNull(java.util.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(java.util.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(java.util.Comparator<T> notNullSafeComparator)
-
safeNullsHigh
public static <T> SerializableComparator<T> safeNullsHigh(java.util.Comparator<T> notNullSafeComparator)
-
chain
@SafeVarargs public static <T> SerializableComparator<T> chain(java.util.Comparator<T>... comparators)
-
fromFunctions
public static <T,V extends java.lang.Comparable<? super V>> SerializableComparator<T> fromFunctions(Function<? super T,? extends V> one)
-
fromFunctions
public static <T,V1 extends java.lang.Comparable<? super V1>,V2 extends java.lang.Comparable<? super V2>> SerializableComparator<T> fromFunctions(Function<? super T,? extends V1> one, Function<? super T,? extends V2> two)
-
fromFunctions
public static <T,V1 extends java.lang.Comparable<? super V1>,V2 extends java.lang.Comparable<? super V2>,V3 extends java.lang.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<java.util.Collection<?>> ascendingCollectionSizeComparator()
-
descendingCollectionSizeComparator
public static SerializableComparator<java.util.Collection<?>> descendingCollectionSizeComparator()
-
byFirstOfPair
public static <T> SerializableComparator<Pair<T,?>> byFirstOfPair(java.util.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(java.util.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
-
byFunction
public static <T,V extends java.lang.Comparable<? super V>> SerializableComparator<T> byFunction(Function<? super T,? extends V> function)
-
originalByFunction
@Deprecated public static <T,V extends java.lang.Comparable<? super V>> SerializableComparator<T> originalByFunction(Function<? super T,? extends V> function)
Deprecated.This signature is kept for serialization backwards compatibility.- Since:
- 11.1
-
getPrimitiveFunctionComparator
private static <T,V extends java.lang.Comparable<? super V>> SerializableComparator<T> getPrimitiveFunctionComparator(Function<? super T,? extends V> function)
-
byFunctionNullsLast
public static <T,V extends java.lang.Comparable<? super V>> SerializableComparator<T> byFunctionNullsLast(Function<? super T,? extends V> function)
-
byFunctionNullsFirst
public static <T,V extends java.lang.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, java.util.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, java.util.Comparator<V> comparator)
Deprecated.Original signature accepted a Comparator which may not be Serializable. This signature is kept for backwards compatibility.
-
nullSafeEquals
public static boolean nullSafeEquals(java.lang.Object value1, java.lang.Object value2)
-
nullSafeCompare
public static <T extends java.lang.Comparable<T>> int nullSafeCompare(T value1, T value2)
-
-