| Package | system.data.maps |
| Class | public class SortedArrayMap |
| Inheritance | SortedArrayMap ArrayMap Object |
| Implements | Sortable |
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 ) ;
| Property | Defined 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 | ||
| Method | Defined By | ||
|---|---|---|---|
SortedArrayMap(... arguments)
Creates a new SortedArrayMap instance. | SortedArrayMap | ||
![]() | clear():void
Removes all mappings from this map. | ArrayMap | |
![]() | clone():*
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned. | ArrayMap | |
![]() | containsKey(key:*):Boolean
Returns true if this map contains a mapping for the specified key. | ArrayMap | |
![]() | containsValue(value:*):Boolean
Returns true if this map maps one or more keys to the specified value. | ArrayMap | |
![]() | get(key:*):*
Returns the value to which this map maps the specified key. | ArrayMap | |
![]() | getKeyAt(index:uint):*
Returns the key registered at the specified index in the array map. | ArrayMap | |
![]() | getKeys():Array
Returns an array representation of all keys in the map. | ArrayMap | |
![]() | getValueAt(index:uint):*
Returns the value registered at the specified index in the array map. | ArrayMap | |
![]() | getValues():Array
Returns an array representation of all values in the map. | ArrayMap | |
![]() | indexOfKey(key:*):int
Returns the index position in the ArrayMap of the specified key. | ArrayMap | |
![]() | indexOfValue(value:*):int
Returns the index position in the ArrayMap of the specified value. | ArrayMap | |
![]() | isEmpty():Boolean
Returns true if this map contains no key-value mappings. | ArrayMap | |
![]() |
Returns the values iterator of this map. | ArrayMap | |
![]() |
Returns the keys iterator of this map. | ArrayMap | |
![]() | put(key:*, value:*):*
Associates the specified value with the specified key in this map. | ArrayMap | |
![]() |
Copies all of the mappings from the specified map to this one. | ArrayMap | |
![]() | remove(o:*):*
Removes the mapping for this key from this map if present. | ArrayMap | |
![]() | setKeyAt(index:uint, key:*):*
Sets the value of the "key" in the ArrayMap with the specified index. | ArrayMap | |
![]() | setValueAt(index:uint, value:*):*
Sets the value of the "value" in the ArrayMap with the specified index. | ArrayMap | |
![]() | 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 | ||
![]() | toSource(indent:int = 0):String
Returns the source representation of this map. | ArrayMap | |
![]() | toString():String
Returns the String representation of this map. | ArrayMap | |
| Constant | Defined 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 | ||
| comparator | property |
comparator:ComparatorDeterminates the Comparator object used in the map to sort the entries.
public function get comparator():Comparator public function set comparator(value:Comparator):void| options | property |
options:uintIndicates the options to sort the elements in the Map.
public function get options():uint public function set options(value:uint):void| sortBy | property |
sortBy:StringIndicates if the map entries are sorted by value or key.
public function get sortBy():String public function set sortBy(value:String):void| SortedArrayMap | () | Constructor |
public function SortedArrayMap(... arguments)Creates a new SortedArrayMap instance.
Parameters... arguments — An optional Array of all keys to fill in this Map.
|
| sort | () | method |
public function sort():voidSorts 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):voidSorts 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
| CASEINSENSITIVE | Constant |
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.
| DESCENDING | Constant |
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.
| KEY | Constant |
public static const KEY:String = keyDefines the constant value of the sortPolicy property if the ArrayMap is sorted by "key".
| NONE | Constant |
public static const NONE:uint = 0Specifies the default numeric sorting value for the Array class sorting methods.
The value of this constant is 0.
| NUMERIC | Constant |
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.
| RETURNINDEXEDARRAY | Constant |
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.
| UNIQUESORT | Constant |
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.
| VALUE | Constant |
public static const VALUE:String = valueDefines the constant value of the sortPolicy property if the ArrayMap is sorted by "value".