Class BooleanComparator

java.lang.Object
org.apache.commons.collections.comparators.BooleanComparator
All Implemented Interfaces:
Serializable, Comparator

@Deprecated(since="2021-04-30") public final class BooleanComparator extends Object implements Comparator, Serializable
Deprecated.
Apache Commons Collections version 3.x is being deprecated from AEMaaCS. The upgraded version 4.4 of Commons Collections is already included as replacement. Customers are advised to upgrade to this version of the library. Please note: the package name was changed to org.apache.commons.collections4. Further note that there are AEM APIs currently exposing the old collections classes; these will be updated in upcoming releases.
A Comparator for Boolean objects that can sort either true or false first.

Since:
Commons Collections 3.0
See Also:
  • Constructor Details

    • BooleanComparator

      public BooleanComparator()
      Deprecated.
      Creates a BooleanComparator that sorts false values before true values.

      Equivalent to BooleanComparator(false).

      Please use the static factory instead whenever possible.

    • BooleanComparator

      public BooleanComparator(boolean trueFirst)
      Deprecated.
      Creates a BooleanComparator that sorts trueFirst values before !trueFirst values.

      Please use the static factories instead whenever possible.

      Parameters:
      trueFirst - when true, sort true boolean values before false
  • Method Details

    • getTrueFirstComparator

      public static BooleanComparator getTrueFirstComparator()
      Deprecated.
      Returns a BooleanComparator instance that sorts true values before false values.

      Clients are encouraged to use the value returned from this method instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same virtual machine.

      Returns:
      the true first singleton BooleanComparator
    • getFalseFirstComparator

      public static BooleanComparator getFalseFirstComparator()
      Deprecated.
      Returns a BooleanComparator instance that sorts false values before true values.

      Clients are encouraged to use the value returned from this method instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same virtual machine.

      Returns:
      the false first singleton BooleanComparator
    • getBooleanComparator

      public static BooleanComparator getBooleanComparator(boolean trueFirst)
      Deprecated.
      Returns a BooleanComparator instance that sorts trueFirst values before !trueFirst values.

      Clients are encouraged to use the value returned from this method instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same virtual machine.

      Parameters:
      trueFirst - when true, sort true Booleans before false
      Returns:
      a singleton BooleanComparator instance
    • compare

      public int compare(Object obj1, Object obj2)
      Deprecated.
      Compares two arbitrary Objects. When both arguments are Boolean, this method is equivalent to compare((Boolean)obj1,(Boolean)obj2). When either argument is not a Boolean, this methods throws a ClassCastException.
      Specified by:
      compare in interface Comparator
      Parameters:
      obj1 - the first object to compare
      obj2 - the second object to compare
      Returns:
      negative if obj1 is less, positive if greater, zero if equal
      Throws:
      ClassCastException - when either argument is not Boolean
    • compare

      public int compare(Boolean b1, Boolean b2)
      Deprecated.
      Compares two non-null Boolean objects according to the value of sortsTrueFirst().
      Parameters:
      b1 - the first boolean to compare
      b2 - the second boolean to compare
      Returns:
      negative if obj1 is less, positive if greater, zero if equal
      Throws:
      NullPointerException - when either argument null
    • hashCode

      public int hashCode()
      Deprecated.
      Implement a hash code for this comparator that is consistent with equals.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code for this comparator.
    • equals

      public boolean equals(Object object)
      Deprecated.
      Returns true iff that Object is is a Comparator whose ordering is known to be equivalent to mine.

      This implementation returns true iff that is a BooleanComparator whose value of sortsTrueFirst() is equal to mine.

      Specified by:
      equals in interface Comparator
      Overrides:
      equals in class Object
      Parameters:
      object - the object to compare to
      Returns:
      true if equal
    • sortsTrueFirst

      public boolean sortsTrueFirst()
      Deprecated.
      Returns true iff I sort true values before false values. In other words, returns true iff compare(Boolean.FALSE,Boolean.TRUE) returns a positive value.
      Returns:
      the trueFirst flag