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.
|
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 .
|
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 .
|
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 .
|
public function toString():String
Returns the string representation of this object.
Returns | String — the string representation of the this object.
|
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