Packagesystem.comparators
Classpublic class AlphaComparator
InheritanceAlphaComparator Inheritance Object
Implements Comparator

This comparator compare String objects with an alphabetic order.

Example :

     import system.comparators.AlphaComparator ;
     
     var comp1:AlphaComparator = new AlphaComparator() ;
     var comp2:AlphaComparator = new AlphaComparator( true ) ; // ignore case
     
     var s0:String = "HELLO" ;
     var s1:String = "hello" ;
     var s2:String = "welcome" ;
     var s3:String = "world" ;
     
     trace( comp1.compare(s1, s2) ) ; // -1
     trace( comp1.compare(s2, s1) ) ; //  1
     trace( comp1.compare(s1, s3) ) ; // -1
     trace( comp1.compare(s1, s1) ) ; //  0
     
     trace( comp1.compare(s1, s0) ) ; // -1
     trace( comp2.compare(s1, s0) ) ; //  0
     



Public Properties
 PropertyDefined By
  ignoreCase : Boolean
Allow to take into account the case for comparison.
AlphaComparator
  nullsAreHigh : Boolean
Defines that null should be compared as higher than a non-null object (default false).
AlphaComparator
Public Methods
 MethodDefined By
  
AlphaComparator(ignoreCase:Boolean = false)
Creates a new AlphaComparator instance.
AlphaComparator
  
compare(o1:*, o2:*, options:* = null):int
Returns an integer value to compare two String objects with an alphabetic order.
AlphaComparator
Property Detail
ignoreCaseproperty
public var ignoreCase:Boolean

Allow to take into account the case for comparison.

nullsAreHighproperty 
nullsAreHigh:Boolean

Defines that null should be compared as higher than a non-null object (default false).


Implementation
    public function get nullsAreHigh():Boolean
    public function set nullsAreHigh(value:Boolean):void
Constructor Detail
AlphaComparator()Constructor
public function AlphaComparator(ignoreCase:Boolean = false)

Creates a new AlphaComparator instance.

Parameters
ignoreCase:Boolean (default = false) — a boolean to define if the comparator ignore case or not.
Method Detail
compare()method
public function compare(o1:*, o2:*, options:* = null):int

Returns an integer value to compare two String objects with an alphabetic order.

Parameters

o1:* — the first String object to compare.
 
o2:* — the second String object to compare.
 
options:* (default = null) — A boolean who indicates if the Comparator ignore the case or not. If this parameter is null the internal ignoreCase property is used.

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 two objects isn't Strings.