Package | org.as3collections.maps |
Class | public class HashMap |
Inheritance | HashMap AbstractHashMap Object |
IMap
interface.
This implementation provides all of the optional map operations, and permits null
values and the null
key.
This class makes no guarantees as to the order of the map. In particular, it does not guarantee that the order will remain constant over time.
It's possible to create typed maps.
You just sends the HashMap
object to the wrapper TypedMap
or uses the MapUtil.getTypedMap
.
See also
Method | Defined By | ||
---|---|---|---|
Constructor, creates a new HashMap object. | HashMap | ||
clear():void [override]
Removes all of the mappings from this map. | HashMap | ||
clone():* [override]
Creates and return a new HashMap object containing all mappings in this map. | HashMap | ||
containsKey(key:*):Boolean
Returns true if this map contains a mapping for the specified key. | AbstractHashMap | ||
containsValue(value:*):Boolean
Returns true if this map maps one or more keys to the specified value. | AbstractHashMap | ||
Returns an ArrayList object that is a view of the mappings contained in this map. | AbstractHashMap | ||
equals(other:*):Boolean
This method uses MapUtil.equalNotConsideringOrder method to perform equality, sending this map and other argument. | AbstractHashMap | ||
Returns an ArrayList object that is a view of the keys contained in this map. | AbstractHashMap | ||
getValue(key:*):*
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. | AbstractHashMap | ||
Returns an ArrayList object that is a view of the values contained in this map. | AbstractHashMap | ||
isEmpty():Boolean
Returns true if this map contains no key-value mappings. | AbstractHashMap | ||
[override]
Returns an iterator over a set of mappings. | HashMap | ||
put(key:*, value:*):* [override]
Associates the specified value with the specified key in this map. | HashMap | ||
Copies all of the mappings from the specified map to this map (optional operation). | AbstractHashMap | ||
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). | AbstractHashMap | ||
Associates the specified entry.value with the specified entry.key in this map (optional operation). | AbstractHashMap | ||
remove(key:*):* [override]
Removes the mapping for a key from this map if it is present. | HashMap | ||
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). | AbstractHashMap | ||
retainAll(keys:ICollection):Boolean
Retains only the mappings in this map that the keys are contained (as elements) in the specified collection (optional operation). | AbstractHashMap | ||
size():int
Returns the number of key-value mappings in this map. | AbstractHashMap | ||
toString():String
Returns the string representation of this instance. | AbstractHashMap |
HashMap | () | Constructor |
public function HashMap(source:IMap = null, weakKeys:Boolean = false)
Constructor, creates a new HashMap
object.
source:IMap (default = null ) — a map with wich fill this map.
| |
weakKeys:Boolean (default = false ) — instructs the backed Dictionary object to use "weak" references on object keys. If the only reference to an object is in the specified Dictionary object, the key is eligible for garbage collection and is removed from the table when the object is collected.
|
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 HashMap
object containing all mappings in this map.
* — a new HashMap 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.
IIterator — an iterator over a set of values.
|
See also
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. (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.
|
* — 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.)
|
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.
|
* — the previous value associated with key, or null if there was no mapping for key .
|
import org.as3collections.IMap; import org.as3collections.IList; import org.as3collections.maps.HashMap; import org.as3collections.maps.MapEntry; var map1:IMap = new HashMap(); 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 // {b=2,a=1} 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 // {b=2,a=1,c=3} map1.size() // 3 map1.put("tf1", tf1) // null map1 // {b=2,a=1,c=3,tf1=[object TextField]} map1.size() // 4 map1.containsValue(tf1) // true map1.put(tf2, "tf2") // null map1 // {b=2,[object TextField]=tf2,a=1,c=3,tf1=[object TextField]} map1.size() // 5 map1.containsKey(tf2) // true map1.put("a", 1.1) // 1 map1 // {b=2,[object TextField]=tf2,a=1.1,c=3,tf1=[object TextField]} map1.size() // 5 map1.put("tf1", String) // [object TextField] map1 // {b=2,[object TextField]=tf2,a=1.1,c=3,tf1=[class String]} map1.size() // 5 map1.put(tf2, "tf2.1") // tf2 map1 // {b=2,[object TextField]=tf2.1,a=1.1,c=3,tf1=[class String]} map1.size() // 5 map1.put(Number, 999) // null map1 // {b=2,[object TextField]=tf2.1,[class Number]=999,a=1.1,c=3,tf1=[class String]} map1.size(): 6 map1.getValue("b") // 2 map1.getValue(tf2) // tf2.1 map1.putAllByObject({fa:"fb",ga:"gb",ha:"hb"}); map1 // {b=2,[object TextField]=tf2.1,fa=fb,[class Number]=999,c=3,ha=hb,a=1.1,tf1=[class String],ga=gb} map1.size() // 9 map1.getValue("fa") // fb map1.remove("ga") // gb map1 // {b=2,[object TextField]=tf2.1,fa=fb,[class Number]=999,c=3,ha=hb,a=1.1,tf1=[class String]} map1.size() // 8 map1.remove("fa") // fb map1 // {b=2,[object TextField]=tf2.1,[class Number]=999,c=3,ha=hb,a=1.1,tf1=[class String]} map1.size() // 7 map1.remove(tf2) // tf2.1 map1 // {b=2,[class Number]=999,c=3,ha=hb,a=1.1,tf1=[class String]} map1.size() // 6 map1.getValue("fa") // null map1.getValue(tf2) // null var map2:IMap = map1.clone(); map2 // {b=2,a=1.1,[class Number]=999,c=3,tf1=[class String],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,[class Number]=999,c=3,tf1=[class String],ha=hb} map2.equals(map2) // true map2.size() // 5 map1.equals(map2) // false map2.equals(map1) // false map2.getValues() // [1.1,999,3,[class String],hb] var keysMap2:IList = map2.getKeys(); keysMap2 // [a,[class Number],c,tf1,ha] keysMap2.remove("c") // true keysMap2 // [a,[class Number],tf1,ha] map2 // {a=1.1,[class Number]=999,c=3,tf1=[class String],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 // {b=2,[class Number]=999,c=3,ha=hb,a=1.1,tf1=[class String]} 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,f=6,e=5} 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) // f=6 e = it.next(); trace(it.pointer() + "=" + e) // e=5 } map1 // {c=3,f=6,e=5} map1.size() // 3