Packageorg.as3coreaddendum.system.comparators
Classpublic class NumberComparator
InheritanceNumberComparator Inheritance Object
Implements IComparator

A comparator for Number objects.

View the examples

See also

IComparator


Public Properties
 PropertyDefined By
  decimalPlaces : int
Defines the number of decimal places to be considered in the comparison.
NumberComparator
  useDecimalPlaces : Boolean
Defines if both numbers should be rounded by the decimalPlaces property.
NumberComparator
Public Methods
 MethodDefined By
  
NumberComparator(useDecimalPlaces:Boolean = false, decimalPlaces:int = 0)
Constructor, creates a new NumberComparator object.
NumberComparator
  
compare(o1:*, o2:*):int
Performs the comparison between the two arguments.
NumberComparator
  
toString():String
Returns the string representation of this object.
NumberComparator
Property Detail
decimalPlacesproperty
decimalPlaces:int

Defines the number of decimal places to be considered in the comparison. Must be an integer between 0 and 20.


Implementation
    public function get decimalPlaces():int
    public function set decimalPlaces(value:int):void

Throws
RangeError — if is assigned a value out of the 0-20 range.
useDecimalPlacesproperty 
useDecimalPlaces:Boolean

Defines if both numbers should be rounded by the decimalPlaces property.


Implementation
    public function get useDecimalPlaces():Boolean
    public function set useDecimalPlaces(value:Boolean):void
Constructor Detail
NumberComparator()Constructor
public function NumberComparator(useDecimalPlaces:Boolean = false, decimalPlaces:int = 0)

Constructor, creates a new NumberComparator object.

Parameters
useDecimalPlaces:Boolean (default = false) — Indicates if both numbers should be rounded by the decimalPlaces property.
 
decimalPlaces:int (default = 0) — The number of decimal places to be considered in the comparison. Must be an integer between 0 and 20.

Throws
ArgumentError — if useDecimalPlaces argument is sent false but some value is sent to decimalPlaces argument.
 
RangeError — if the decimalPlaces argument is out of the 0-20 range.
Method Detail
compare()method
public function compare(o1:*, o2:*):int

Performs the comparison between the two arguments.

Parameters

o1:* — The first Number object to be compared.
 
o2:* — The second Number object to be compared.

Returns
int — A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Throws
ArgumentError — if any of the arguments is not of type Number.
toString()method 
public function toString():String

Returns the string representation of this object.

Returns
String — the string representation of the this object.
Examples
     import org.as3coreaddendum.system.comparators.NumberComparator;
     
     var c:NumberComparator = new NumberComparator();
     
     c.compare(0, 0);              // 0
     c.compare(1, 1);              // 0
     c.compare(0, 1);              // -1
     c.compare(94, 56);            // 1
     c.compare(-38, -27);          // -1
     c.compare(2.5, 2.5);          // 0
     c.compare(2.54, 2.54);        // 0
     c.compare(2.54, 2.56);        // -1
     c.compare(2.567, 2.567);      // 0
     c.compare(2.5678, 2.5677);    // 1
     c.compare(2.5678, 2.5674);    // 1
     c.compare(2.5674, 2.5678);    // -1
     
     import org.as3coreaddendum.system.comparators.NumberComparator;
     
     var c1:NumberComparator = new NumberComparator(true, 1);
     
     c1.compare(2.5, 2.5);          // 0
     c1.compare(2.54, 2.54);        // 0
     c1.compare(2.54, 2.56);        // -1
     c1.compare(2.567, 2.567);      // 0
     c1.compare(2.5678, 2.5677);    // 0
     c1.compare(2.5678, 2.5674);    // 0
     c1.compare(2.5674, 2.5678);    // 0
     
     import org.as3coreaddendum.system.comparators.NumberComparator;
     
     var c2:NumberComparator = new NumberComparator(true, 2);
     
     c2.compare(2.5, 2.5);          // 0
     c2.compare(2.54, 2.54);        // 0
     c2.compare(2.54, 2.56);        // -1
     c2.compare(2.567, 2.567);      // 0
     c2.compare(2.5678, 2.5677);    // 0
     c2.compare(2.5678, 2.5674);    // 0
     c2.compare(2.5674, 2.5678);    // 0
     
     import org.as3coreaddendum.system.comparators.NumberComparator;
     
     var c3:NumberComparator = new NumberComparator(true, 3);
     
     c3.compare(2.5, 2.5);          // 0
     c3.compare(2.54, 2.54);        // 0
     c3.compare(2.54, 2.56);        // -1
     c3.compare(2.567, 2.567);      // 0
     c3.compare(2.5678, 2.5677);    // 0
     c3.compare(2.5678, 2.5674);    // 1
     c3.compare(2.5674, 2.5678);    // -1
     
     import org.as3coreaddendum.system.comparators.NumberComparator;
     
     var c4:NumberComparator = new NumberComparator(true, 4);
     
     c4.compare(2.5, 2.5);          // 0
     c4.compare(2.54, 2.54);        // 0
     c4.compare(2.54, 2.56);        // -1
     c4.compare(2.567, 2.567);      // 0
     c4.compare(2.5678, 2.5677);    // 1
     c4.compare(2.5678, 2.5674);    // 1
     c4.compare(2.5674, 2.5678);    // -1