Packagesystem.comparators
Classpublic class BooleanComparator
InheritanceBooleanComparator Inheritance Object
Implements Comparator

An Comparator for Boolean objects that can sort either true or false first.

Example :

     import system.Comparator ;
     import system.comparators.BooleanComparator ;
     
     var c:Comparator = new BooleanComparator() ;
     trace(c.compare(true, true)) ; // 0
     trace(c.compare(true, false)) ; // 1
     trace(c.compare(false, true)) ; // -1
     trace(c.compare(false, false)) ; // 0
     



Public Properties
 PropertyDefined By
  trueFirst : Boolean
When true sort true boolean values before false.
BooleanComparator
Public Methods
 MethodDefined By
  
BooleanComparator(trueFirst:Boolean = true)
Creates a BooleanComparator that sorts trueFirst values before !trueFirst values.
BooleanComparator
  
compare(o1:*, o2:*, options:* = null):int
Returns an integer value to compare two Boolean objects.
BooleanComparator
Public Constants
 ConstantDefined By
  falseFirst : BooleanComparator
[static] This BooleanComparator singleton that sorts false values before true values.
BooleanComparator
  trueFirst : BooleanComparator
[static] This BooleanComparator singleton that sorts true values before false values.
BooleanComparator
Property Detail
trueFirstproperty
public var trueFirst:Boolean

When true sort true boolean values before false.

Constructor Detail
BooleanComparator()Constructor
public function BooleanComparator(trueFirst:Boolean = true)

Creates a BooleanComparator that sorts trueFirst values before !trueFirst values. Please use the static factories instead whenever possible.

Parameters
trueFirst:Boolean (default = true) — when true, sort true boolean values before false
Method Detail
compare()method
public function compare(o1:*, o2:*, options:* = null):int

Returns an integer value to compare two Boolean objects.

Parameters

o1:* — the first Number object to compare.
 
o2:* — the second Number object to compare.
 
options:* (default = null)

Returns
int

  • -1 if o1 is "lower" than (less than, before, etc.) o2 ;
  • 1 if o1 is "higher" than (greater than, after, etc.) o2 ;
  • 0 if o1 and o2 are equal.

  • Throws
    ArgumentError — if the first argument is null and not a Boolean object.
     
    ArgumentError — when either argument is not Boolean
    Constant Detail
    falseFirstConstant
    public static const falseFirst:BooleanComparator

    This BooleanComparator singleton that sorts false values before true values. Clients are encouraged to use the value returned from this constant instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same application.

    Example :

             import system.comparators.BooleanComparator ;
             import system.Comparator ;
             
             var c:Comparator = BooleanComparator.falseFirst ;
             
             trace( c.compare( true  , true  ) ) ; //  0
             trace( c.compare( true  , false ) ) ; // -1
             trace( c.compare( false , true  ) ) ; //  1
             trace( c.compare( false , false ) ) ; //  0
             

    trueFirstConstant 
    public static const trueFirst:BooleanComparator

    This BooleanComparator singleton that sorts true values before false values. Clients are encouraged to use the value returned from this constant instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple BooleanComparators may be used in the same application.

             import system.comparators.BooleanComparator ;
             import system.Comparator ;
             
             var c:Comparator = BooleanComparator.trueFirst ;
             
             trace( c.compare( true  , true  ) ) ; //  0
             trace( c.compare( true  , false ) ) ; //  1
             trace( c.compare( false , true  ) ) ; // -1
             trace( c.compare( false , false ) ) ; //  0