Package no.digipost
Class DiggCompare
- java.lang.Object
-
- no.digipost.DiggCompare
-
public final class DiggCompare extends Object
Utilities for comparing values.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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>>
TmaxBy(Function<? super T,U> propertyExtractor, T t1, T t2)Choose 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>>
TminBy(Function<? super T,U> propertyExtractor, T t1, T t2)Choose 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.
-
-
-
Method Detail
-
min
public static <T extends Comparable<T>> T min(T t1, T t2)
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
public static <T extends Comparable<T>> T max(T t1, T t2)
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
public static <T> T minBy(Comparator<? super T> propertyComparator, T t1, T t2)
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
public static <T> T maxBy(Comparator<? super T> comparator, T t1, T t2)
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
@SafeVarargs public 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. 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 lesser 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(List)
-
prioritize
public 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. 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 lesser 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
-
-