Class Comparables


  • public class Comparables
    extends java.lang.Object
    Utility methods linked to comparing comparable values.
    • Constructor Summary

      Constructors 
      Constructor Description
      Comparables()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.lang.Comparable<? super T>>
      T
      max​(T a, T b)
      Returns the maximum of 2 comparable values.
      static <C,​T extends C>
      T
      max​(T a, T b, java.util.Comparator<C> comparator)
      Returns the maximum of 2 values given a comparator of those values.
      static <T extends java.lang.Comparable<? super T>>
      T
      min​(T a, T b)
      Returns the minimum of 2 comparable values.
      static <C,​T extends C>
      T
      min​(T a, T b, java.util.Comparator<C> comparator)
      Returns the minimum of 2 values given a comparator of those values.
      • Methods inherited from class java.lang.Object

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

      • Comparables

        public Comparables()
    • Method Detail

      • max

        public static <T extends java.lang.Comparable<? super T>> T max​(T a,
                                                                        T b)
        Returns the maximum of 2 comparable values. On ties, returns the first argument.
      • max

        public static <C,​T extends C> T max​(T a,
                                                  T b,
                                                  java.util.Comparator<C> comparator)
        Returns the maximum of 2 values given a comparator of those values. On ties, returns the first argument.
      • min

        public static <T extends java.lang.Comparable<? super T>> T min​(T a,
                                                                        T b)
        Returns the minimum of 2 comparable values. On ties, returns the first argument.
      • min

        public static <C,​T extends C> T min​(T a,
                                                  T b,
                                                  java.util.Comparator<C> comparator)
        Returns the minimum of 2 values given a comparator of those values. On ties, returns the first argument.