Package adams.core

Class CompareUtils


  • public class CompareUtils
    extends Object
    Utility class for comparisons.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • CompareUtils

        public CompareUtils()
    • Method Detail

      • compare

        public static int compare​(Comparable o1,
                                  Comparable o2)
        Compares two comparable objects. Takes care of null objects. Returns -1, 0 or +1, if o1 less than, equal to or greater than o2. Returns 0 if both objects null, -1 if o1 null but not o2 and +1 if o1 not null but o2.
        Parameters:
        o1 - the first object
        o2 - the second object
        Returns:
        the comparison result
      • compare

        public static int compare​(int[] a1,
                                  int[] a2)
        Compares two integer arrays.
        Parameters:
        a1 - the first array
        a2 - the second array
        Returns:
        -1, 0, +1 if a1 is smaller than, equal to, or larger than a2
      • compare

        public static int compare​(Map m1,
                                  Map m2)
        Compares two maps. Both, keys and values must be Comparable.
        Parameters:
        m1 - the first map
        m2 - the second map
        Returns:
        the comparison result