Package no.digipost

Class 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>>
      T
      max​(T t1, T t2)
      Choose the greater of two Comparable objects.
      static <T> T maxBy​(Comparator<? super T> comparator, T t1, T t2)
      Choose the greater of two objects by using a Comparator.
      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 a Comparable value resolved from each object.
      static <T extends Comparable<T>>
      T
      min​(T t1, T t2)
      Choose the lesser of two Comparable objects.
      static <T> T minBy​(Comparator<? super T> propertyComparator, T t1, T t2)
      Choose the lesser of two objects by using a given Comparator.
      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 a Comparable value 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 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 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(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 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