Packageorg.as3collections.maps
Classpublic class ArrayListMap
InheritanceArrayListMap Inheritance AbstractListMap Inheritance Object
Subclasses SortedArrayListMap

Array based implementation of the IMap interface. This implementation provides all of the optional map operations, and permits null values and the null key.

This class makes guarantees as to the order of the map. The order in which elements are stored is the order in which they were inserted.

This class has great similarity to ArrayList class. In a way this class can be thought of as an ArrayList of mappings.

It's possible to create typed list maps. You just sends the ArrayListMap object to the wrapper TypedListMap or uses the MapUtil.getTypedListMap.

View the examples

See also

AbstractListMap
TypedListMap
SortedArrayListMap
MapUtil.getTypedListMap()


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
 InheritedmodCount : int
[read-only] The number of times this map has been structurally modified.
AbstractListMap
Protected Properties
 PropertyDefined By
 Inheritedkeys : IList
AbstractListMap
 Inheritedvalues : IList
AbstractListMap
Public Methods
 MethodDefined By
  
ArrayListMap(source:IMap = null)
Constructor, creates a new ArrayListMap object.
ArrayListMap
  
clear():void
[override] Removes all of the mappings from this map.
ArrayListMap
  
clone():*
[override] Creates and return a new ArrayListMap object containing all mappings in this map (in the same order).
ArrayListMap
 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
 Inherited
equals(other:*):Boolean
This method uses MapUtil.equalConsideringOrder method to perform equality, sending this map and other argument.
AbstractListMap
 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
  
[override] Returns an iterator over a set of mappings.
ArrayListMap
  
[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.
ArrayListMap
 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.
ArrayListMap
 Inherited
Associates the specified entry.value with the specified entry.key in this map (optional operation).
AbstractListMap
  
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
  
removeAt(index:int):IMapEntry
[override] Removes the mapping at the specified position in this map (optional operation).
ArrayListMap
  
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).
ArrayListMap
  
setValueAt(index:int, value:*):*
[override] Replaces the value at the specified position in this map with the specified value (optional operation).
ArrayListMap
 Inherited
size():int
Returns the number of key-value mappings in this map.
AbstractListMap
  
subMap(fromIndex:int, toIndex:int):IListMap
[override] Returns a new map that is a view of the portion of this map between the specified fromIndex, inclusive, and toIndex, exclusive.
ArrayListMap
 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
Constructor Detail
ArrayListMap()Constructor
public function ArrayListMap(source:IMap = null)

Constructor, creates a new ArrayListMap object.

Parameters
source:IMap (default = null) — a map with wich fill this map.
Method Detail
clear()method
override public function clear():void

Removes all of the mappings from this map. The map will be empty after this call returns.

clone()method 
override public function clone():*

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

Returns
* — a new ArrayListMap object containing all mappings in this map.
iterator()method 
override public function iterator():IIterator

Returns an iterator over a set of mappings.

This implementation returns a MapIterator object.

Returns
IIterator — an iterator over a set of values.

See also

listMapIterator()method 
override public function listMapIterator(index:int = 0):IListMapIterator

Returns a IListMapIterator object to iterate over the mappings in this map (in proper sequence), starting at the specified position in this map.

This implementation returns a ListMapIterator object.

Parameters

index:int (default = 0) — index of first value to be returned from the iterator (by a call to the next method)

Returns
IListMapIterator — a ListMapIterator object to iterate over the mappings in this map (in proper sequence), starting at the specified position in this map.
put()method 
override public function put(key:*, value:*):*

Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced by the specified value, and the order of the key is not affected. (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, because this 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. 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.


Throws
ArgumentError — if this map already contains the specified key.
 
IndexOutOfBoundsError — if the index is out of range (index < 0 || index > size()).
remove()method 
override public function remove(key:*):*

Removes the mapping for a key from this map if it is present.

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key. A return value of null does not necessarily indicate that the map contained no mapping for the key. It's possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters

key:* — the key whose mapping is to be removed from the map.

Returns
* — the previous value associated with key, or null if there was no mapping for key.
removeAt()method 
override public function removeAt(index:int):IMapEntry

Removes the mapping at the specified position in this map (optional operation). Shifts any subsequent mappings to the left (subtracts one from their indices). Returns an IMapEntry object containing the mapping (key/value) that was removed from the map.

This implementation always throws an UnsupportedOperationError.

Parameters

index:int — the index of the mapping to be removed.

Returns
IMapEntry — an IMapEntry object containing the mapping (key/value) that was removed from the map.

Throws
org.as3coreaddendum.errors:UnsupportedOperationError — if the removeAt operation is not supported by this map.
 
IndexOutOfBoundsError — if the index is out of range (index < 0 || index >= size()).
removeRange()method 
override public function removeRange(fromIndex:int, toIndex:int):IListMap

Removes all of the mappings whose index is between fromIndex, inclusive, and toIndex, exclusive (optional operation). Shifts any subsequent mappings to the left (subtracts their indices).

If toIndex == fromIndex, this operation has no effect.

Parameters

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

Returns
IListMap — a new map containing all the removed mappings.

Throws
org.as3coreaddendum.errors:UnsupportedOperationError — if the removeRange operation is not supported by this map.
 
IndexOutOfBoundsError — if fromIndex or toIndex is out of range (index < 0 || index > size()).
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.

Throws
org.as3coreaddendum.errors:UnsupportedOperationError — if the setKeyAt operation is not supported by this map.
 
org.as3coreaddendum.errors:ClassCastError — if the class of the specified key prevents it from being added to this map.
 
ArgumentError — if the specified key is null and this map does not permit null keys.
 
ArgumentError — if this map already contains the specified key.
 
IndexOutOfBoundsError — if the index is out of range (index < 0 || index >= size()).
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).

This implementation always throws an UnsupportedOperationError.

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.

Throws
org.as3coreaddendum.errors:UnsupportedOperationError — if the setValueAt operation is not supported by this map.
 
org.as3coreaddendum.errors:ClassCastError — if the class of the specified value prevents it from being added to this map.
 
ArgumentError — if the specified value is null and this map does not permit null values.
 
IndexOutOfBoundsError — if the index is out of range (index < 0 || index >= size()).
subMap()method 
override public function subMap(fromIndex:int, toIndex:int):IListMap

Returns a new map that is a view of the portion of this map between the specified fromIndex, inclusive, and toIndex, exclusive.

The returned map supports all of the optional map operations supported by this map.

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.IMap;
     import org.as3collections.IList;
     import org.as3collections.maps.ArrayListMap;
     import org.as3collections.maps.MapEntry;
     
     var map1:IMap = new ArrayListMap();
     var tf1:TextField = new TextField();
     var tf2:TextField = new TextField();
     
     map1                            // {}
     map1.containsKey("a")           // false
     map1.containsKey(tf2)           // false
     map1.containsValue(2)           // false
     map1.containsValue(tf1)         // false
     map1.isEmpty()                  // true
     map1.size()                     // 0
     
     map1.put("a", 1)                // null
     map1                            // {a=1}
     map1.isEmpty()                  // false
     map1.size()                     // 1
     map1.containsKey("a")           // true
     map1.containsKey(tf2)           // false
     map1.containsValue(2)           // false
     map1.containsValue(tf1)         // false
     
     map1.put("b", 2)                // null
     map1                            // {a=1,b=2}
     map1.isEmpty()                  // false
     map1.size()                     // 2
     map1.containsKey("a")           // true
     map1.containsKey("b")           // true
     map1.containsKey(tf2)           // false
     map1.containsValue(2)           // true
     
     map1.put("c", 3)                // null
     map1                            // {a=1,b=2,c=3}
     map1.size()                     // 3
     
     map1.put("tf1", tf1)            // null
     map1                            // {a=1,b=2,c=3,tf1=[object TextField]}
     map1.size()                     // 4
     map1.containsValue(tf1)         // true
     
     map1.put(tf2, "tf2")            // null
     map1                            // {a=1,b=2,c=3,tf1=[object TextField],[object TextField]=tf2}
     map1.size()                     // 5
     map1.containsKey(tf2)           // true
     
     map1.put("a", 1.1)              // 1
     map1                            // {a=1.1,b=2,c=3,tf1=[object TextField],[object TextField]=tf2}
     map1.size()                     // 5
     
     map1.put("tf1", String)         // [object TextField]
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[object TextField]=tf2}
     map1.size()                     // 5
     
     map1.put(tf2, "tf2.1")          // tf2
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[object TextField]=tf2.1}
     map1.size()                     // 5
     
     map1.put(Number, 999)           // null
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[object TextField]=tf2.1,[class Number]=999}
     map1.size()                     // 6
     
     map1.getValue("b")              // 2
     
     map1.getValue(tf2)              // tf2.1
     
     map1.putAllByObject({fa:"fb",ga:"gb",ha:"hb"});
     
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[object TextField]=tf2.1,[class Number]=999,ha=hb,ga=gb,fa=fb}
     
     map1.size()                     // 9
     
     map1.getValue("fa")             // fb
     
     map1.remove("ga")               // gb
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[object TextField]=tf2.1,[class Number]=999,ha=hb,fa=fb}
     map1.size()                     // 8
     
     map1.remove("fa")               // fb
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[object TextField]=tf2.1,[class Number]=999,ha=hb}
     map1.size()                     // 7
     
     map1.remove(tf2)                // tf2.1
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[class Number]=999,ha=hb}
     map1.size()                     // 6
     
     map1.getValue("fa")             // null
     map1.getValue(tf2)              // null
     
     var map2:IMap = map1.clone();
     
     map2                            // {a=1.1,b=2,c=3,tf1=[class String],[class Number]=999,ha=hb}
     map2.size()                     // 6
     map2.isEmpty()                  // false
     
     map1.equals(map2)               // true
     map2.equals(map1)               // true
     map2.equals(map2)               // true
     
     map2.remove("b")                // 2
     map2                            // {a=1.1,c=3,tf1=[class String],[class Number]=999,ha=hb}
     map2.equals(map2)               // true
     map2.size()                     // 5
     
     map1.equals(map2)               // false
     map2.equals(map1)               // false
     
     map2.getValues()                // [1.1,3,[class String],999,hb]
     
     var keysMap2:IList = map2.getKeys();
     
     keysMap2                        // [a,c,tf1,[class Number],ha]
     
     keysMap2.remove("c")            // true
     keysMap2                        // [a,tf1,[class Number],ha]
     map2                            // {a=1.1,c=3,tf1=[class String],[class Number]=999,ha=hb}
     map2.size()                     // 5
     
     map2.removeAll(keysMap2)        // true
     map2                            // {c=3}
     map2.size()                     // 1
     map2.isEmpty()                  // false
     
     map2.clear();
     
     map2                            // {}
     map2.size()                     // 0
     map2.isEmpty()                  // true
     
     var entry:IMapEntry = new MapEntry("c", 3);
     
     entry                           // c=3
     map2.putEntry(entry)            // null
     map2                            // {c=3}
     map2.size()                     // 1
     
     map1                            // {a=1.1,b=2,c=3,tf1=[class String],[class Number]=999,ha=hb}
     map1.retainAll(map2)            // true
     map1                            // {c=3}
     map1.size()                     // 1
     map1.isEmpty()                  // false
     
     map1.put("d", 4)                // null
     map1.put("e", 5)                // null
     map1.put("f", 6)                // null
     map1                            // {c=3,d=4,e=5,f=6}
     map1.size()                     // 4
     
     var it:IIterator = map1.iterator();
     
     var e:*;
     
     while (it.hasNext())
     {
     
         e = it.next();
         trace(it.pointer() + "=" + e)    // c=3
     
         e = it.next();
         trace(it.pointer() + "=" + e)    // d=4
     
         if (e == 4)
         {
             it.remove();
         }
     
         e = it.next();
         trace(it.pointer() + "=" + e)    // e=5
     
         e = it.next();
         trace(it.pointer() + "=" + e)    // f=6
     }
     
     map1                            // {c=3,e=5,f=6}
     map1.size()                     // 3