Class EqualsComparator<T>

  • All Implemented Interfaces:
    Comparator<T>

    public class EqualsComparator<T>
    extends Object
    implements Comparator<T>
    Implementation of IComparator that uses java.lang.Object.equals(Object) to determine equality or not. This is used as a default comparison method for DefaultEditComparator, but can also be used as an adapter for customising the equals comparison, e.g.:
     // case-insensitive comparison
     new EqualsComparator<String>()
     {
       public int compare(String o1, String o2)
       {
          return o1.toLowerCase().compareTo(o2.toLowerCase());
       }
      }
     

    NB This comparator cannot be used for ordering elements, as it only returns 0 (for "equal") or 1 (for "not equal").

    Author:
    Robert Fromont robert@fromont.net.nz
    • Constructor Detail

      • EqualsComparator

        public EqualsComparator()
        Default constructor.
    • Method Detail

      • compare

        public int compare​(T o1,
                           T o2)
        Compares two objects for equality only.

        NB This cannot be used for ordering elements, as it only returns 0 or 1.

        Specified by:
        compare in interface Comparator<T>
        Returns:
        0 if o1.equals(o2), 1 otherwise,