| Package | system.comparators |
| Class | public class GenericComparator |
| Inheritance | GenericComparator Object |
| Implements | Comparator, Sortable |
Example :
import system.comparators.GenericComparator ;
import system.comparators.StringComparator ;
var write:Function = function( ar:Array ):void
{
var result:Array = [] ;
var size:uint = ar.length ;
for (var i:uint = 0 ; i<size ; i++)
{
result[i] = ar[i].label ;
}
trace( result.join('|') ) ;
}
var ar:Array =
[
{ id : 0 , label : "Paris" } ,
{ id : 1 , label : "Marseille" } ,
{ id : 2 , label : "Lyon" } ,
{ id : 3 , label : "Bordeaux" }
] ;
var c:GenericComparator = new GenericComparator( "label", StringComparator.getStringComparator() ) ;
ar.sort( c.compare , Array.CASEINSENSITIVE ) ;
write(ar) ; // Lyon|Paris|Bordeaux|Marseille
ar.sort( c.compare , Array.CASEINSENSITIVE | Array.DESCENDING ) ;
write(ar) ; // Paris|Marseille|Lyon|Bordeaux
| Property | Defined By | ||
|---|---|---|---|
| comparator : Comparator
Determinates the Comparator strategy used to sort the instance. | GenericComparator | ||
| sortBy : String
Determinates a String who represents a property name to compare the two objects. | GenericComparator | ||
| Method | Defined By | ||
|---|---|---|---|
GenericComparator(sortBy:String, comparator:Comparator)
Creates a new GenericComparator instance. | GenericComparator | ||
compare(o1:*, o2:*, options:* = null):int
Returns an integer value to compare two objects. | GenericComparator | ||
| comparator | property |
comparator:ComparatorDeterminates the Comparator strategy used to sort the instance.
The internal Comparator used by this Comparator to compare two objects with the specified field.
public function get comparator():Comparator public function set comparator(value:Comparator):voidReferenceError — If the 'comparator' property is 'null'.
|
| sortBy | property |
sortBy:StringDeterminates a String who represents a property name to compare the two objects.
public function get sortBy():String public function set sortBy(value:String):voidArgumentError — If the 'sortBy' property is 'null'.
|
| GenericComparator | () | Constructor |
public function GenericComparator(sortBy:String, comparator:Comparator)Creates a new GenericComparator instance.
ParameterssortBy:String — A String who represents a property name to compare the two objects.
| |
comparator:Comparator — An Comparator use to compare the two objects with the specified property names.
|
ArgumentError — If the 'sortBy' argument is 'null'.
| |
ArgumentError — If the 'comparator' argument is 'null'.
|
| compare | () | method |
public function compare(o1:*, o2:*, options:* = null):intReturns an integer value to compare two objects.
Parameters
o1:* — the first Number object to compare.
| |
o2:* — the second Number object to compare.
| |
options:* (default = null) |
int —
|
ArgumentError — if the two arguments are null.
|