Packageorg.as3coreaddendum.system.comparators
Classpublic class PropertyComparator
InheritancePropertyComparator Inheritance Object
Implements IComparator

This comparator uses the received comparator object to compare the values recovered from the property of each of the two objects.

View the examples



Public Properties
 PropertyDefined By
  comparator : IComparator
Defines the comparator object used in the comparison.
PropertyComparator
  property : String
Defines the name of the property to be recovered and compared between the objects.
PropertyComparator
Public Methods
 MethodDefined By
  
PropertyComparator(property:String, comparator:IComparator)
Constructor, creates a new PropertyComparator object.
PropertyComparator
  
compare(o1:*, o2:*):int
Performs the comparison between the values recovered from the properties of each of the two objects.
PropertyComparator
  
toString():String
Returns the string representation of this object.
PropertyComparator
Property Detail
comparatorproperty
comparator:IComparator

Defines the comparator object used in the comparison.


Implementation
    public function get comparator():IComparator
    public function set comparator(value:IComparator):void

Throws
ArgumentError — if is assigned a null value.
propertyproperty 
property:String

Defines the name of the property to be recovered and compared between the objects.


Implementation
    public function get property():String
    public function set property(value:String):void

Throws
ArgumentError — if is assigned a null value or an empty String.
Constructor Detail
PropertyComparator()Constructor
public function PropertyComparator(property:String, comparator:IComparator)

Constructor, creates a new PropertyComparator object.

Parameters
property:String — The name of the property to be recovered and compared between the objects.
 
comparator:IComparator — The comparator object used in the comparison.

Throws
ArgumentError — if the property argument is null or an empty String.
 
ArgumentError — if the comparator argument is null.
Method Detail
compare()method
public function compare(o1:*, o2:*):int

Performs the comparison between the values recovered from the properties of each of the two objects.

Parameters

o1:* — The first object which has the property recovered to be compared. Can be an instance of any custom class.
 
o2:* — The second object which has the property recovered to be compared. Can be an instance of any custom class.

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

Throws
ArgumentError — if any argument is null.
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.AlphabeticComparator;
     import org.as3coreaddendum.system.comparators.NumberComparator;
     import org.as3coreaddendum.system.comparators.PropertyComparator;
     
     var a:Object = { id: 1, name: "TestA" };
     var b:Object = { id: 0, name: "TestB" };
     var c:Object = { id: 2, name: "TestC" };
      
     var p1:PropertyComparator = new PropertyComparator("id", new NumberComparator());
     
     p1.compare(a, a)    // 0
     p1.compare(a, b)    // 1
     p1.compare(b, a)    // -1
     p1.compare(b, c)    // -1
     p1.compare(c, a)    // 1
     
     var p2:PropertyComparator = new PropertyComparator("name", new AlphabeticComparator());
      
     p2.compare(a, a)    // 0
     p2.compare(a, b)    // -1
     p2.compare(b, a)    // 1
     p2.compare(b, c)    // -1
     p2.compare(c, a)    // 1