Packagesystem.data.maps
Classpublic class SortedArrayMap
InheritanceSortedArrayMap Inheritance ArrayMap Inheritance Object
Implements Sortable

This ArrayMap can be sorted with a Comparator object.

Example :

     import system.data.maps.SortedArrayMap ;
     
     import system.comparators.NumberComparator ;
     import system.comparators.StringComparator ;
     
     var map:SortedArrayMap = new SortedArrayMap( [0] , ["item0"] ) ;
     
     map.put( 1 , "item8" ) ;
     map.put( 3 , "item7" ) ;
     map.put( 2 , "item6" ) ;
     map.put( 5 , "item5" ) ;
     map.put( 4 , "item4" ) ;
     map.put( 7 , "item3" ) ;
     map.put( 6 , "item2" ) ;
     map.put( 8 , "item1" ) ;
     
     trace("----- original Map") ;
     
     trace( map ) ;
     
     trace("----- sort by key with sort() method") ;
     
     map.comparator = new NumberComparator() ;
     
     map.options = SortedArrayMap.NUMERIC | SortedArrayMap.DESCENDING ;
     map.sort() ;
     trace( map ) ;
     
     map.options = SortedArrayMap.NUMERIC ;
     map.sort() ;
     trace( map ) ;
     
     trace("----- sort by value with sort() method") ;
     
     map.comparator = new StringComparator() ;
     map.sortBy = SortedArrayMap.VALUE ;
     
     map.options = SortedArrayMap.DESCENDING ;
     map.sort() ;
     trace( map ) ;
     
     map.options = SortedArrayMap.NONE ;
     map.sort() ;
     trace( map ) ;
     



Public Properties
 PropertyDefined By
  comparator : Comparator
Determinates the Comparator object used in the map to sort the entries.
SortedArrayMap
  options : uint
Indicates the options to sort the elements in the Map.
SortedArrayMap
  sortBy : String
Indicates if the map entries are sorted by value or key.
SortedArrayMap
Public Methods
 MethodDefined By
  
SortedArrayMap(... arguments)
Creates a new SortedArrayMap instance.
SortedArrayMap
 Inherited
clear():void
Removes all mappings from this map.
ArrayMap
 Inherited
clone():*
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.
ArrayMap
 Inherited
containsKey(key:*):Boolean
Returns true if this map contains a mapping for the specified key.
ArrayMap
 Inherited
containsValue(value:*):Boolean
Returns true if this map maps one or more keys to the specified value.
ArrayMap
 Inherited
get(key:*):*
Returns the value to which this map maps the specified key.
ArrayMap
 Inherited
getKeyAt(index:uint):*
Returns the key registered at the specified index in the array map.
ArrayMap
 Inherited
getKeys():Array
Returns an array representation of all keys in the map.
ArrayMap
 Inherited
getValueAt(index:uint):*
Returns the value registered at the specified index in the array map.
ArrayMap
 Inherited
getValues():Array
Returns an array representation of all values in the map.
ArrayMap
 Inherited
indexOfKey(key:*):int
Returns the index position in the ArrayMap of the specified key.
ArrayMap
 Inherited
indexOfValue(value:*):int
Returns the index position in the ArrayMap of the specified value.
ArrayMap
 Inherited
isEmpty():Boolean
Returns true if this map contains no key-value mappings.
ArrayMap
 Inherited
Returns the values iterator of this map.
ArrayMap
 Inherited
Returns the keys iterator of this map.
ArrayMap
 Inherited
put(key:*, value:*):*
Associates the specified value with the specified key in this map.
ArrayMap
 Inherited
putAll(m:Map):void
Copies all of the mappings from the specified map to this one.
ArrayMap
 Inherited
remove(o:*):*
Removes the mapping for this key from this map if present.
ArrayMap
 Inherited
setKeyAt(index:uint, key:*):*
Sets the value of the "key" in the ArrayMap with the specified index.
ArrayMap
 Inherited
setValueAt(index:uint, value:*):*
Sets the value of the "value" in the ArrayMap with the specified index.
ArrayMap
 Inherited
size():uint
Returns the number of key-value mappings in this map.
ArrayMap
  
sort():void
Sorts the elements in Map by key or value with the current Comparator reference.
SortedArrayMap
  
sortOn(fieldName:*, opts:Number):void
Sorts the elements in the list according to one or more fields in the array.
SortedArrayMap
 Inherited
toSource(indent:int = 0):String
Returns the source representation of this map.
ArrayMap
 Inherited
toString():String
Returns the String representation of this map.
ArrayMap
Public Constants
 ConstantDefined By
  CASEINSENSITIVE : uint = 1
[static] Specifies case-insensitive sorting for the Array class sorting methods.
SortedArrayMap
  DESCENDING : uint = 2
[static] Specifies descending sorting for the Array class sorting methods.
SortedArrayMap
  KEY : String = key
[static] Defines the constant value of the sortPolicy property if the ArrayMap is sorted by "key".
SortedArrayMap
  NONE : uint = 0
[static] Specifies the default numeric sorting value for the Array class sorting methods.
SortedArrayMap
  NUMERIC : uint = 16
[static] Specifies numeric (instead of character-string) sorting for the Array class sorting methods.
SortedArrayMap
  RETURNINDEXEDARRAY : uint = 8
[static] Specifies that a sort returns an array that consists of array indices as a result of calling the sort() or sortOn() method.
SortedArrayMap
  UNIQUESORT : uint = 4
[static] Specifies the unique sorting requirement for the Array class sorting methods.
SortedArrayMap
  VALUE : String = value
[static] Defines the constant value of the sortPolicy property if the ArrayMap is sorted by "value".
SortedArrayMap
Property Detail
comparatorproperty
comparator:Comparator

Determinates the Comparator object used in the map to sort the entries.


Implementation
    public function get comparator():Comparator
    public function set comparator(value:Comparator):void
optionsproperty 
options:uint

Indicates the options to sort the elements in the Map.


Implementation
    public function get options():uint
    public function set options(value:uint):void
sortByproperty 
sortBy:String

Indicates if the map entries are sorted by value or key.


Implementation
    public function get sortBy():String
    public function set sortBy(value:String):void
Constructor Detail
SortedArrayMap()Constructor
public function SortedArrayMap(... arguments)

Creates a new SortedArrayMap instance.

Parameters
... arguments — An optional Array of all keys to fill in this Map.
Method Detail
sort()method
public function sort():void

Sorts the elements in Map by key or value with the current Comparator reference.

Example :

import system.data.maps.SortedArrayMap ; import system.comparators.NumberComparator ; var map:SortedArrayMap = new SortedArrayMap() ; map.comparator = new NumberComparator() ; map.put( 1 , 4 ) ; map.put( 3 , 2 ) ; map.put( 4 , 3 ) ; map.put( 2 , 1 ) ; trace(map) ; // {1:4,3:2,4:3,2:1} map.options = SortedArrayMap.DESCENDING ; map.sort() ; trace(map) ; // {4:3,3:2,2:1,1:4} map.options = SortedArrayMap.NONE ; map.sort() ; trace(map) ; // {1:4,2:1,3:2,4:3} map.sortBy = SortedArrayMap.VALUE ; map.options = SortedArrayMap.DESCENDING ; map.sort() ; trace(map) ; // {1:4,4:3,3:2,2:1} map.options = SortedArrayMap.NONE ; map.sort() ; trace(map) ; // {2:1,3:2,4:3,1:4}

See also

sortOn()method 
public function sortOn(fieldName:*, opts:Number):void

Sorts the elements in the list according to one or more fields in the array.

Example :

import system.data.Iterator ; import system.data.Map ; import system.data.maps.SortedArrayMap ; var map:SortedArrayMap = new SortedArrayMap() ; map.put( { id:5 } , { name:'name4' } ) ; map.put( { id:1 } , { name:'name1' } ) ; map.put( { id:3 } , { name:'name5' } ) ; map.put( { id:2 } , { name:'name2' } ) ; map.put( { id:4 } , { name:'name3' } ) ; var debug:Function = function( map:Map ):void { var vit:Iterator = map.iterator() ; var kit:Iterator = map.keyIterator() ; var str:String = "{" ; var key:; var value:; while( vit.hasNext() ) { value = vit.next() ; key = kit.next() ; str += key.id + ":" + value.name ; if (vit.hasNext()) { str += "," ; } } str += "}" ; trace(str) ; } trace("----- original Map") ; debug( map ) ; // {5:name4,1:name1,3:name5,2:name2,4:name3} trace("----- sort by key with sort() method") ; map.sortBy = SortedArrayMap.KEY ; // default map.options = SortedArrayMap.NUMERIC | SortedArrayMap.DESCENDING ; map.sortOn("id") ; debug( map ) ; // {5:name4,4:name3,3:name5,2:name2,1:name1} map.options = SortedArrayMap.NUMERIC | SortedArrayMap.DESCENDING ; map.sortOn("id") ; debug( map ) ; // {5:name4,4:name3,3:name5,2:name2,1:name1} trace("----- sort by value with sort() method") ; map.sortBy = SortedArrayMap.VALUE ; map.options = SortedArrayMap.DESCENDING ; map.sortOn("name") ; debug( map ) ; // {3:name5,5:name4,4:name3,2:name2,1:name1} map.options = SortedArrayMap.NONE ; map.sortOn("name") ; debug( map ) ; // {1:name1,2:name2,4:name3,5:name4,3:name5}

Parameters

fieldName:* — A string that identifies a field to be used as the sort value.
 
opts:Number (default = NaN) — (optional) The option number value to use to sort this map.

See also

Constant Detail
CASEINSENSITIVEConstant
public static const CASEINSENSITIVE:uint = 1

Specifies case-insensitive sorting for the Array class sorting methods. You can use this constant for the options parameter in the sort() or sortOn() method.

The value of this constant is 1.

DESCENDINGConstant 
public static const DESCENDING:uint = 2

Specifies descending sorting for the Array class sorting methods. You can use this constant for the options parameter in the sort() or sortOn() method.

The value of this constant is 2.

KEYConstant 
public static const KEY:String = key

Defines the constant value of the sortPolicy property if the ArrayMap is sorted by "key".

NONEConstant 
public static const NONE:uint = 0

Specifies the default numeric sorting value for the Array class sorting methods.

The value of this constant is 0.

NUMERICConstant 
public static const NUMERIC:uint = 16

Specifies numeric (instead of character-string) sorting for the Array class sorting methods. Including this constant in the options parameter causes the sort() and sortOn() methods to sort numbers as numeric values, not as strings of numeric characters. Without the NUMERIC constant, sorting treats each array element as a character string and produces the results in Unicode order.

For example, given the array of values [2005, 7, 35], if the NUMERIC constant is not included in the options parameter, the sorted array is [2005, 35, 7], but if the NUMERIC constant is included, the sorted array is [7, 35, 2005].

This constant applies only to numbers in the array; it does not apply to strings that contain numeric data such as ["23", "5"].

The value of this constant is 16.

RETURNINDEXEDARRAYConstant 
public static const RETURNINDEXEDARRAY:uint = 8

Specifies that a sort returns an array that consists of array indices as a result of calling the sort() or sortOn() method. You can use this constant for the options parameter in the sort() or sortOn() method, so you have access to multiple views on the array elements while the original array is unmodified.

The value of this constant is 8.

UNIQUESORTConstant 
public static const UNIQUESORT:uint = 4

Specifies the unique sorting requirement for the Array class sorting methods. You can use this constant for the options parameter in the sort() or sortOn() method. The unique sorting option terminates the sort if any two elements or fields being sorted have identical values.

The value of this constant is 4.

VALUEConstant 
public static const VALUE:String = value

Defines the constant value of the sortPolicy property if the ArrayMap is sorted by "value".