Packagesystem.comparators
Classpublic class NullComparator
InheritanceNullComparator Inheritance Object
Implements Comparator

This comparator compare Null objects. When comparing two non-null objects, the ComparableComparator is used if the nonNullComparator isnt' define.

Example :

     import system.comparators.NullComparator;
     
     var comp1:NullComparator = new NullComparator(null, true) ;
     var comp2:NullComparator = new NullComparator(null, false) ;
     
     var n = null ;
     var o = {} ;
     
     trace( comp1.compare(n, n) ) ; // 0
     trace( comp1.compare(n, o) ) ; // 1
     trace( comp1.compare(o, n) ) ; // -1
     
     trace("----") ;
     
     trace( comp2.compare(n, n) ) ; // 0
     trace( comp2.compare(n, o) ) ; // -1
     trace( comp2.compare(o, n) ) ; // 1
     



Public Properties
 PropertyDefined By
  nonNullComparator : Comparator = null
Defines the comparator to use when comparing two non-null objects.
NullComparator
  nullsAreHigh : Boolean = false
Defines that null should be compared as higher than a non-null object.
NullComparator
Public Methods
 MethodDefined By
  
NullComparator(nonNullComparator:Comparator = null, nullsAreHigh:Boolean = false)
Creates a new NullComparator instance.
NullComparator
  
compare(o1:*, o2:*, options:* = null):int
Performs a comparison between two objects.
NullComparator
Property Detail
nonNullComparatorproperty
public var nonNullComparator:Comparator = null

Defines the comparator to use when comparing two non-null objects.

nullsAreHighproperty 
public var nullsAreHigh:Boolean = false

Defines that null should be compared as higher than a non-null object.

Constructor Detail
NullComparator()Constructor
public function NullComparator(nonNullComparator:Comparator = null, nullsAreHigh:Boolean = false)

Creates a new NullComparator instance.

Parameters
nonNullComparator:Comparator (default = null) — the comparator to use when comparing two non-null objects.
 
nullsAreHigh:Boolean (default = false) — a true value indicates that null should be compared as higher than a non-null object. A false value indicates that null should be compared as lower than a non-null object.
Method Detail
compare()method
public function compare(o1:*, o2:*, options:* = null):int

Performs a comparison between two objects. If both objects are null, a 0 value is returned. If one object is null and the other is not, the result is determined on whether the Comparator was constructed to have nulls as higher or lower than other objects. If neither object is null, an underlying comparator specified in the constructor (or the default) is used to compare the non-null objects. The default Comparator used to compare two non-null objects is the ComparableComparator.

Parameters

o1:* — the first 'null' object to compare.
 
o2:* — the second 'null' 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.
  • See also