Class Compare

java.lang.Object
org.tentackle.common.Compare

public class Compare extends Object
Some handy static null-safe methods to compare two Comparables.
Author:
harald
  • Method Details

    • compare

      public static <T extends Comparable<? super T>> int compare(T o1, T o2)
      Compares two objects.
      null is being treated as smallest value.

      Notice the different semantics compared to Objects.compare(java.lang.Object, java.lang.Object, java.util.Comparator) for null-values.

      Type Parameters:
      T - the class type
      Parameters:
      o1 - the first object
      o2 - the second object
      Returns:
      a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.
    • compareWithNullLargest

      public static <T extends Comparable<? super T>> int compareWithNullLargest(T o1, T o2)
      Compares two objects.
      null is being treated as largest value.
      Type Parameters:
      T - the class type
      Parameters:
      o1 - the first object
      o2 - the second object
      Returns:
      a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.