Package no.digipost
Class DiggCompare
java.lang.Object
no.digipost.DiggCompare
Utilities for comparing values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
Tmax(T t1, T t2) Choose the greater of twoComparableobjects.static <T> TmaxBy(Comparator<? super T> comparator, T t1, T t2) Choose the greater of two objects by using aComparator.static <T,U extends Comparable<? super U>>
TChoose the greater of two objects by comparing aComparablevalue resolved from each object.static <T extends Comparable<T>>
Tmin(T t1, T t2) Choose the lesser of twoComparableobjects.static <T> TminBy(Comparator<? super T> propertyComparator, T t1, T t2) Choose the lesser of two objects by using a givenComparator.static <T,U extends Comparable<? super U>>
TChoose the lesser of two objects by comparing aComparablevalue resolved from each object.static <T> Comparator<T>prioritize(List<T> elementsOrderedByPriority) Create a comparator which will use a given list of already prioritized elements to determine the order of given elements.static <T> Comparator<T>prioritize(T... elementsOrderedByPriority) Create a comparator which will use a given list of already prioritized elements to determine the order of given elements.static <T> Comparator<T>prioritizeIf(Predicate<? super T>... predicatesOrderedByPriority) Create a comparator which will use the given predicates in prioritized order to determine the order of any given elements.static <T> Comparator<T>prioritizeIf(List<? extends Predicate<? super T>> predicatesOrderedByPriority) Create a comparator which will use a given list of predicates in prioritized order to determine the order of given elements.
-
Method Details
-
min
Choose the lesser of twoComparableobjects. In the case where the objects are considered equal byComparable.compareTo(Object), the first argument is returned.- Returns:
- the least of the two given objects.
-
max
Choose the greater of twoComparableobjects. In the case where the objects are considered equal byComparable.compareTo(Object), the first argument is returned.- Returns:
- the greatest of the two given objects.
-
minBy
Choose the lesser of two objects by using a givenComparator. In the case where the objects are considered equal byComparable.compareTo(Object), the first argument is returned.This is the static method equivalent of applying the resulting function from
BinaryOperator.minBy(Comparator)with the given comparator as argument.- Returns:
- the least of the two given objects.
-
minBy
public static <T,U extends Comparable<? super U>> T minBy(Function<? super T, U> propertyExtractor, T t1, T t2) Choose the lesser of two objects by comparing aComparablevalue resolved from each object. In the case where the objects are considered equal byComparable.compareTo(Object), the first argument is returned.This is the static method equivalent of applying the resulting function from
BinaryOperator.minBy(Comparator)withcomparing(propertyExtractor)as argument.- Returns:
- the least of the two given objects.
-
maxBy
Choose the greater of two objects by using aComparator. In the case where the objects are considered equal byComparable.compareTo(Object), the first argument is returned.This is the static method equivalent of applying the resulting function from
BinaryOperator.maxBy(Comparator)with the given comparator as argument.- Returns:
- the least of the two given objects.
-
maxBy
public static <T,U extends Comparable<? super U>> T maxBy(Function<? super T, U> propertyExtractor, T t1, T t2) Choose the greater of two objects by comparing aComparablevalue resolved from each object. In the case where the objects are considered equal byComparable.compareTo(Object), the first argument is returned.This is the static method equivalent of applying the resulting function from
BinaryOperator.maxBy(Comparator)withcomparing(propertyExtractor)as argument.- Returns:
- the least of the two given objects.
-
prioritize
Create a comparator which will use a given list of already prioritized elements to determine the order of given elements. Two elements present in the prioritized list are compared according to their position in the list. An element not present in the elements is always considered as less prioritized than a present element. Two elements not present are considered equal.- Parameters:
elementsOrderedByPriority- The elements which order is used to determine the order of elements given to the comparator.- Returns:
- the comparator
- See Also:
-
prioritize
Create a comparator which will use a given list of already prioritized elements to determine the order of given elements. Two elements present in the prioritized list are compared according to their position in the list. An element not present in the elements is always considered as less prioritized than a present element. Two elements not present are considered equal.- Parameters:
elementsOrderedByPriority- The elements which order is used to determine the order of elements given to the comparator.- Returns:
- the comparator
-
prioritizeIf
public static <T> Comparator<T> prioritizeIf(List<? extends Predicate<? super T>> predicatesOrderedByPriority) Create a comparator which will use a given list of predicates in prioritized order to determine the order of given elements. The indexes of the first predicates which pass two compared elements will determine the comparison result. An element not passing any of the predicates is always considered as less prioritized than a passing element. Two elements not passing any predicate are considered equal.- Parameters:
predicatesOrderedByPriority- The predicates which order is used to determine the order of elements given to the comparator.- Returns:
- the comparator
-
prioritizeIf
@SafeVarargs public static <T> Comparator<T> prioritizeIf(Predicate<? super T>... predicatesOrderedByPriority) Create a comparator which will use the given predicates in prioritized order to determine the order of any given elements. The indexes of the first predicates which pass two compared elements will determine the comparison result. An element not passing any of the predicates is always considered as less prioritized than a passing element. Two elements not passing any predicate are considered equal.- Parameters:
predicatesOrderedByPriority- The predicates which order is used to determine the order of elements given to the comparator.- Returns:
- the comparator
-