Packageorg.as3collections.maps
Classpublic class SortedArrayListMap
InheritanceSortedArrayListMap Inheritance ArrayListMap Inheritance AbstractListMap Inheritance Object
Implements ISortedMap

A map that provides a total ordering on its mappings. The map is ordered according to the natural ordering of its keys or values, by a IComparator typically provided at sorted map creation time, or by the arguments provided to the sort or sortOn methods.

For each change that occurs the map is automatically ordered using the comparator and options. If none was provided the default behavior of the sort method is used.

The sortBy property defines whether the sorting will be made by key or value.

The user of this map may change their order at any time by calling the sort or sortOn method and imposing others arguments to change the sort behaviour.

It's possible to create typed sorted maps. You just sends the SortedArrayListMap object to the wrapper TypedSortedMap or uses the MapUtil.getTypedSortedMap.

View the examples

See also

MapUtil.getTypedSortedMap()


Public Properties
 PropertyDefined By
 InheritedallKeysEquatable : Boolean
[read-only] Indicates whether all keys in this map implements org.as3coreaddendum.system.IEquatable interface.
AbstractListMap
 InheritedallValuesEquatable : Boolean
[read-only] Indicates whether all values in this map implements org.as3coreaddendum.system.IEquatable interface.
AbstractListMap
  comparator : IComparator
Defines the comparator object to be used automatically to sort.
SortedArrayListMap
 InheritedmodCount : int
[read-only] The number of times this map has been structurally modified.
AbstractListMap
  options : uint
Defines the options to be used automatically to sort.
SortedArrayListMap
  sortBy : SortMapBy
Defines whether the map should be sorted by its keys or values.
SortedArrayListMap
Protected Properties
 PropertyDefined By
 Inheritedkeys : IList
AbstractListMap
 Inheritedvalues : IList
AbstractListMap
Public Methods
 MethodDefined By
  
SortedArrayListMap(source:IMap = null, comparator:IComparator = null, options:uint = 0)
Constructor, creates a new SortedArrayListMap object.
SortedArrayListMap
 Inherited
clear():void
[override] Removes all of the mappings from this map.
ArrayListMap
  
clone():*
[override] Creates and return a new SortedArrayListMap object containing all elements in this map (in the same order).
SortedArrayListMap
 Inherited
containsKey(key:*):Boolean
Returns true if this map contains a mapping for the specified key.
AbstractListMap
 Inherited
containsValue(value:*):Boolean
Returns true if this map maps one or more keys to the specified value.
AbstractListMap
 Inherited
Returns an ArrayList object that is a view of the mappings contained in this map (in the same order).
AbstractListMap
  
equals(other:*):Boolean
[override] Performs an arbitrary, specific evaluation of equality between this object and the other object.
SortedArrayListMap
 Inherited
getKeyAt(index:int):*
Returns the key at the specified position in this map.
AbstractListMap
 Inherited
Returns an ArrayList object that is a view of the keys contained in this map.
AbstractListMap
 Inherited
getValue(key:*):*
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
AbstractListMap
 Inherited
getValueAt(index:int):*
Returns the value at the specified position in this map.
AbstractListMap
 Inherited
Returns an ArrayList object that is a view of the values contained in this map.
AbstractListMap
 Inherited
headMap(toKey:*):IListMap
Returns a new IListMap object that is a view of the portion of this map whose keys are strictly less than toKey.
AbstractListMap
 Inherited
indexOfKey(key:*):int
Returns the position of the specified key.
AbstractListMap
 Inherited
indexOfValue(value:*):int
Returns the position of the specified value.
AbstractListMap
 Inherited
isEmpty():Boolean
Returns true if this map contains no key-value mappings.
AbstractListMap
 Inherited
[override] Returns an iterator over a set of mappings.
ArrayListMap
 Inherited
[override] Returns a IListMapIterator object to iterate over the mappings in this map (in proper sequence), starting at the specified position in this map.
ArrayListMap
  
put(key:*, value:*):*
[override] Associates the specified value with the specified key in this map (optional operation).
SortedArrayListMap
 Inherited
putAll(map:IMap):void
Copies all of the mappings from the specified map to this map (optional operation).
AbstractListMap
 Inherited
putAllAt(index:int, map:IMap):void
Copies all of the mappings from the specified map to this map (optional operation).
AbstractListMap
 Inherited
putAllByObject(o:Object):void
This implementation performs a for..in in the specified object, calling put on this map once for each iteration (optional operation).
AbstractListMap
  
putAt(index:int, key:*, value:*):void
[override] Associates the specified value with the specified key at the specified position in this map (optional operation).
SortedArrayListMap
 Inherited
Associates the specified entry.value with the specified entry.key in this map (optional operation).
AbstractListMap
 Inherited
remove(key:*):*
[override] Removes the mapping for a key from this map if it is present.
ArrayListMap
 Inherited
removeAll(keys:ICollection):Boolean
Removes the mapping for a key from this map (if it is present) for each element in the specified collection (optional operation).
AbstractListMap
 Inherited
removeAt(index:int):IMapEntry
[override] Removes the mapping at the specified position in this map (optional operation).
ArrayListMap
 Inherited
removeRange(fromIndex:int, toIndex:int):IListMap
[override] Removes all of the mappings whose index is between fromIndex, inclusive, and toIndex, exclusive (optional operation).
ArrayListMap
 Inherited
retainAll(keys:ICollection):Boolean
Retains only the mappings in this map that the keys are contained (as elements) in the specified collection (optional operation).
AbstractListMap
 Inherited
reverse():void
Reverses the order of the mappings in this map.
AbstractListMap
  
setKeyAt(index:int, key:*):*
[override] Replaces the key at the specified position in this map with the specified key (optional operation).
SortedArrayListMap
  
setValueAt(index:int, value:*):*
[override] Replaces the value at the specified position in this map with the specified value (optional operation).
SortedArrayListMap
 Inherited
size():int
Returns the number of key-value mappings in this map.
AbstractListMap
  
sort(compare:Function = null, options:uint = 0):Array
Sorts the objects within this class.
SortedArrayListMap
  
sortOn(fieldName:*, options:* = null):Array
Sorts the elements in an array according to one or more fields in the array.
SortedArrayListMap
  
subMap(fromIndex:int, toIndex:int):IListMap
[override] inheritDoc
SortedArrayListMap
 Inherited
tailMap(fromKey:*):IListMap
Returns a new IListMap object that is a view of the portion of this map whose keys are greater than or equal to fromKey.
AbstractListMap
 Inherited
toString():String
Returns the string representation of this instance.
AbstractListMap
Property Detail
comparatorproperty
comparator:IComparator

Defines the comparator object to be used automatically to sort.

If this value change the map is automatically reordered with the new value.


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

Defines the options to be used automatically to sort.

If this value change the list is automatically reordered with the new value.


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

Defines whether the map should be sorted by its keys or values. The default is SortMapBy.KEY.

If this value change the map is automatically reordered with the new value.


Implementation
    public function get sortBy():SortMapBy
    public function set sortBy(value:SortMapBy):void

Throws
ArgumentError — if try to set a null value.
Constructor Detail
SortedArrayListMap()Constructor
public function SortedArrayListMap(source:IMap = null, comparator:IComparator = null, options:uint = 0)

Constructor, creates a new SortedArrayListMap object.

Parameters
source:IMap (default = null) — a map with wich fill this map.
 
comparator:IComparator (default = null) — the comparator object to be used internally to sort.
 
options:uint (default = 0) — the options to be used internally to sort.
Method Detail
clone()method
override public function clone():*

Creates and return a new SortedArrayListMap object containing all elements in this map (in the same order).

Returns
* — a new SortedArrayListMap object containing all elements in this map (in the same order).
equals()method 
override public function equals(other:*):Boolean

Performs an arbitrary, specific evaluation of equality between this object and the other object.

This implementation considers two differente objects equal if:

This implementation takes care of the order of the mappings in the map. So, for two maps are equal the order of mappings returned by the iterator must be equal.

Parameters

other:* — the object to be compared for equality.

Returns
Booleantrue if the arbitrary evaluation considers the objects equal.
put()method 
override public function put(key:*, value:*):*

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters

key:* — key with which the specified value is to be associated.
 
value:* — value to be associated with the specified key.

Returns
* — the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)
putAt()method 
override public function putAt(index:int, key:*, value:*):void

Associates the specified value with the specified key at the specified position in this map (optional operation). Shifts the entry currently at that position (if any) and any subsequent entries to the right (adds one to their indices).

Parameters

index:int — index at which the specified entry is to be inserted.
 
key:* — key with which the specified value is to be associated.
 
value:* — value to be associated with the specified key.

setKeyAt()method 
override public function setKeyAt(index:int, key:*):*

Replaces the key at the specified position in this map with the specified key (optional operation).

Parameters

index:int — index of the key to replace.
 
key:* — key to be stored at the specified position.

Returns
* — the key previously at the specified position.
setValueAt()method 
override public function setValueAt(index:int, value:*):*

Replaces the value at the specified position in this map with the specified value (optional operation).

Parameters

index:int — index of the value to replace.
 
value:* — value to be stored at the specified position.

Returns
* — the value previously at the specified position.
sort()method 
public function sort(compare:Function = null, options:uint = 0):Array

Sorts the objects within this class.

For more info see org.as3coreaddendum.system.ISortable.sort() in the link below.

Parameters

compare:Function (default = null)
 
options:uint (default = 0)

Returns
Array
sortOn()method 
public function sortOn(fieldName:*, options:* = null):Array

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

Consult Array.sortOn in the ActionScript 3.0 Language Reference in the link below for more info.

Parameters

fieldName:*
 
options:* (default = null)

Returns
Array

See also

subMap()method 
override public function subMap(fromIndex:int, toIndex:int):IListMap

inheritDoc

Parameters

fromIndex:int — the index to start retrieving mappings (inclusive).
 
toIndex:int — the index to stop retrieving mappings (exclusive).

Returns
IListMap — a new list that is a view of the specified range within this list.

Throws
org.as3coreaddendum.errors:UnsupportedOperationError — if the subMap operation is not supported by this map.
 
IndexOutOfBoundsError — if fromIndex or toIndex is out of range (index < 0 || index > size()).
Examples
     import org.as3collections.ISortedMap;
     import org.as3collections.maps.SortedArrayListMap;
     
     var map1:ISortedMap = new SortedArrayListMap();
     
     map1.put("e", 1)            // null
     map1.put("d", 2)            // null
     map1.put("c", 3)            // null
     map1.put("b", 4)            // null
     map1.put("a", 5)            // null
     
     map1                        // {a=5,b=4,c=3,d=2,e=1}
     
     map1.firstKey()             // a
     map1.lastKey()              // e
     
     map1.sortBy = SortMapBy.VALUE;
     
     map1                        // {e=1,d=2,c=3,b=4,a=5}
     
     map1.firstKey()             // e
     map1.lastKey()              // a
     
     map1.sort(null, Array.NUMERIC);
     
     map1                        // {e=1,d=2,c=3,b=4,a=5}
     
     map1.sort(null, Array.NUMERIC | Array.DESCENDING);
     
     map1                        // {a=5,b=4,c=3,d=2,e=1}
     
     map1.sortBy = SortMapBy.KEY;
     
     map1                        // {a=5,b=4,c=3,d=2,e=1}
     
     map1.headMap("d")           // {a=5,b=4,c=3}
     map1.tailMap("b")           // {b=4,c=3,d=2,e=1}
     map1.subMap("b", "d")       // {b=4,c=3}