Package no.digipost

Class DiggCompare


  • public final class DiggCompare
    extends Object
    Utilities for comparing values.
    • Method Detail

      • min

        public static <T extends Comparable<T>> T min​(T t1,
                                                      T t2)
        Choose the lesser of two Comparable objects. In the case where the objects are considered equal by Comparable.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 two Comparable objects. In the case where the objects are considered equal by Comparable.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 given Comparator. In the case where the objects are considered equal by Comparable.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.
      • maxBy

        public static <T> T maxBy​(Comparator<? super T> comparator,
                                  T t1,
                                  T t2)
        Choose the greater of two objects by using a Comparator. In the case where the objects are considered equal by Comparable.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.
      • 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