Class ObjectComparisons

java.lang.Object
io.deephaven.util.compare.ObjectComparisons

public class ObjectComparisons extends Object
  • Constructor Details

    • ObjectComparisons

      public ObjectComparisons()
  • Method Details

    • compare

      public static int compare(Object lhs, Object rhs)
      Compares two Objects according to the following rules:
      Parameters:
      lhs - the first value
      rhs - the second value
      Returns:
      the value 0 if lhs is equal to rhs; a value less than 0 if lhs is less than rhs; and a value greater than 0 if lhs is greater than rhs
    • eq

      public static boolean eq(Object lhs, Object rhs)
      Compare two Objects for equality using Objects.equals(Object, Object); this is consistent with hashCode(Object), that is eq(x, y) => hashCode(x) == hashCode(y).

      For types whose compareTo is not consistent with equals (e.g., BigDecimal 1.0 and 1.00), eq may be false for values where compare(lhs, rhs) == 0. Use compareEquals(Object, Object) for equality that is consistent with compare(Object, Object).

      Parameters:
      lhs - the first value
      rhs - the second value
      Returns:
      true if the values are equal, false otherwise
    • compareEquals

      public static boolean compareEquals(Object lhs, Object rhs)
      Compare two Objects for equality consistent with compare(Object, Object); logically equivalent to compare(lhs, rhs) == 0.

      This equality is suitable for any ordering in which distinct objects that are not equals may share an equivalence class (e.g., BigDecimal 1.0 and 1.00). Unlike eq(Object, Object), it is not consistent with hashCode(Object), so it must not be used for hashing.

      Parameters:
      lhs - the first value
      rhs - the second value
      Returns:
      true if compare(lhs, rhs) == 0, false otherwise
    • hashCode

      public static int hashCode(Object x)
      Returns a hash code for an Object value consistent with eq(Object, Object); that is, eq(x, y) ⇒ hashCode(x) == hashCode(y).
      Parameters:
      x - the value to hash
      Returns:
      a hash code value for an Object value
    • gt

      public static boolean gt(Object lhs, Object rhs)
      Logically equivalent to compare(lhs, rhs) > 0.
      Parameters:
      lhs - the first value
      rhs - the second value
      Returns:
      true iff lhs is greater than rhs
    • lt

      public static boolean lt(Object lhs, Object rhs)
      Logically equivalent to compare(lhs, rhs) < 0.
      Parameters:
      lhs - the first value
      rhs - the second value
      Returns:
      true iff lhs is less than rhs
    • geq

      public static boolean geq(Object lhs, Object rhs)
      Logically equivalent to compare(lhs, rhs) >= 0.
      Parameters:
      lhs - the first value
      rhs - the second value
      Returns:
      true iff lhs is greater than or equal to rhs
    • leq

      public static boolean leq(Object lhs, Object rhs)
      Logically equivalent to compare(lhs, rhs) <= 0.
      Parameters:
      lhs - the first value
      rhs - the second value
      Returns:
      true iff lhs is less than or equal to rhs