Packagevegas.util.comparators
Classpublic class NullComparator
InheritanceNullComparator Inheritance CoreObject
ImplementsICloneable, IComparator, ICopyable

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

Example :

  import vegas.util.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 : IComparator = 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:IComparator = null, nullsAreHigh:Boolean = false)
Creates a new NullComparator instance.
NullComparator
  
clone():*
Creates and returns a shallow copy of the object.
NullComparator
  
compare(o1:*, o2:*):int
Perform a comparison between two objects.
NullComparator
  
copy():*
Creates and returns a deep copy of the object.
NullComparator
  
[static] Returns the singleton instance of a ReverseComparator.
NullComparator
 Inherited
Returns the internal ILogger reference of this ILogable object.
CoreObject
 Inherited
hashCode():uint
Returns a hashcode value for the object.
CoreObject
 Inherited
setLogger(log:ILogger = null):void
Sets the internal ILogger reference of this ILogable object.
CoreObject
 Inherited
toSource(indent:int = 0):String
Returns the string representation the source code of the object.
CoreObject
 Inherited
toString():String
Returns the string representation of this instance.
CoreObject
Property detail
nonNullComparatorproperty
public var nonNullComparator:IComparator = 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:IComparator = null, nullsAreHigh:Boolean = false)

Creates a new NullComparator instance.

Parameters
nonNullComparator:IComparator (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
clone()method
public function clone():*

Creates and returns a shallow copy of the object.

Returns
* — A new object that is a shallow copy of this instance.
compare()method 
public function compare(o1:*, o2:*):int

Perform 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 IComparator 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.

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

    copy()method 
    public function copy():*

    Creates and returns a deep copy of the object.

    Returns
    * — A new object that is a deep copy of this instance.
    getInstance()method 
    public static function getInstance():NullComparator

    Returns the singleton instance of a ReverseComparator. Developers are encouraged to use the comparator returned from this method instead of constructing a new instance to reduce allocation and GC overhead when multiple comparable comparators may be used in the same application.

    Returns
    NullComparator — the singleton instance of a ReverseComparator.