Class CompareUtil


  • public class CompareUtil
    extends java.lang.Object
    Util class for comparisons.
    Author:
    Filip Hrisafov
    • Constructor Summary

      Constructors 
      Constructor Description
      CompareUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.lang.Comparable<T>>
      boolean
      areNotInAscendingOrder​(java.util.List<T> values)
      Checks if any of the values are not in an ascending order.
      static <T extends java.lang.Comparable<T>>
      boolean
      areNotInAscendingOrder​(T... values)
      Checks if any of the values are not in an ascending order.
      static <T> boolean elementIsContainedInArray​(T element, T... values)
      Checks if the element is contained within the list of values.
      static <T> boolean elementIsContainedInList​(T element, java.util.Collection<T> values)
      Checks if the element is contained within the list of values.
      static <T> boolean elementIsNotContainedInArray​(T element, T... values)
      Checks if the element is contained within the list of values.
      static <T> boolean elementIsNotContainedInList​(T element, java.util.Collection<T> values)
      Checks if the element is not contained within the list of values.
      static <T extends java.lang.Comparable<T>>
      T
      max​(T obj1, T obj2)
      Returns any element if obj1.compareTo(obj2) == 0
      static <T extends java.lang.Comparable<T>>
      T
      min​(T obj1, T obj2)
      Returns any element if obj1.compareTo(obj2) == 0
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CompareUtil

        public CompareUtil()
    • Method Detail

      • areNotInAscendingOrder

        public static <T extends java.lang.Comparable<T>> boolean areNotInAscendingOrder​(T... values)
        Checks if any of the values are not in an ascending order. The check is done based on the Comparable.compareTo(Object) method. E.g. if we have minPriority = 10, priority = 13 and maxPriority = 5 and Integer[] values = {minPriority, priority, maxPriority}. Then a call to areNotInAscendingOrder(Comparable[] values) will return true
        Type Parameters:
        T - the type of the comparable
        Parameters:
        values - to validate
        Returns:
        false if the not null values are in an ascending order or all the values are null, true otherwise
      • areNotInAscendingOrder

        public static <T extends java.lang.Comparable<T>> boolean areNotInAscendingOrder​(java.util.List<T> values)
        Checks if any of the values are not in an ascending order. The check is done based on the Comparable.compareTo(Object) method. E.g. if we have minPriority = 10, priority = 13 and maxPriority = 5 and List<Integer> values = {minPriority, priority, maxPriority}. Then a call to areNotInAscendingOrder(List values) will return true
        Type Parameters:
        T - the type of the comparable
        Parameters:
        values - to validate
        Returns:
        false if the not null values are in an ascending order or all the values are null, true otherwise
      • elementIsNotContainedInList

        public static <T> boolean elementIsNotContainedInList​(T element,
                                                              java.util.Collection<T> values)
        Checks if the element is not contained within the list of values. If the element, or the list are null then true is returned.
        Type Parameters:
        T - the type of the element
        Parameters:
        element - to check
        values - to check in
        Returns:
        true if the element and values are not null and the values does not contain the element, false otherwise
      • elementIsNotContainedInArray

        public static <T> boolean elementIsNotContainedInArray​(T element,
                                                               T... values)
        Checks if the element is contained within the list of values. If the element, or the list are null then true is returned.
        Type Parameters:
        T - the type of the element
        Parameters:
        element - to check
        values - to check in
        Returns:
        true if the element and values are not null and the values does not contain the element, false otherwise
      • elementIsContainedInList

        public static <T> boolean elementIsContainedInList​(T element,
                                                           java.util.Collection<T> values)
        Checks if the element is contained within the list of values.
        Type Parameters:
        T - the type of the element
        Parameters:
        element - to check
        values - to check in
        Returns:
        true if the element and values are not null and the values contain the element, false otherwise
      • elementIsContainedInArray

        public static <T> boolean elementIsContainedInArray​(T element,
                                                            T... values)
        Checks if the element is contained within the list of values.
        Type Parameters:
        T - the type of the element
        Parameters:
        element - to check
        values - to check in
        Returns:
        true if the element and values are not null and the values contain the element, false otherwise
      • min

        public static <T extends java.lang.Comparable<T>> T min​(T obj1,
                                                                T obj2)
        Returns any element if obj1.compareTo(obj2) == 0
      • max

        public static <T extends java.lang.Comparable<T>> T max​(T obj1,
                                                                T obj2)
        Returns any element if obj1.compareTo(obj2) == 0