org.as2lib.core.BasicInterface +--org.as2lib.data.holder.Map
Map
is the base interface for data holders that map keys to values.
A map offers two methods that help you find out whether it contains a specific key or value. These two methods are containsKey and containsValue.
To get the data stored in the map you can use the methods getKeys, getValues and get. If you want to iterate over the values of the map you can use the iterators returned by the methods iterator or valueIterator. If you want to iterate over the keys you can use the iterator returned by the keyIterator method.
To add key value pairs to the map you can use the methods put and
putAll. The putAll
method lets you add all key-value pairs
contained in the passed-in map
to this map.
To remove key-value pairs you can use the methods remove and
clear. The remove
method deletes only the key-value pair
corresponding to the passed-in key
, while the clear method removes all
key-value pairs.
There are two more methods you may need. The isEmpty and the size method. These methods give you information about whether this map contains any mappings and how many mappings it contains.
Example:
// the map gets set up somewhere
var map:Map = new MyMap();
map.put("myKey", "myValue");
// at some different place in your code
if (map.containsKey("myKey")) {
trace(map.get("myKey"));
}
public function containsKey(key):Boolean
Checks if the passed-in key
exists.
That means whether a value has been mapped to it.
key | the key to be checked for availability |
true
if the key
exists else false
public function containsValue(value):Boolean
Checks if the passed-in value
is mapped to a key.
value | the value to be checked for availability |
true
if the value
is mapped to a key else false
public function getKeys(Void):Array
Returns an array that contains all keys that have a value mapped to it.
an array that contains all keys
public function getValues(Void):Array
Returns an array that contains all values that are mapped to a key.
an array that contains all mapped values
public function get(key)
Returns the value that is mapped to the passed-in key
.
key | the key to return the corresponding value for |
the value corresponding to the passed-in key
public function put(key, value)
Maps the given key
to the value
.
key | the key used as identifier for the value
|
value | the value to map to the key
|
the value that was originally mapped to the key
public function putAll(map:Map):Void
Copies all mappings from the passed-in map
to this map.
map | the mappings to add to this map |
public function remove(key)
Removes the mapping from the given key
to the value.
key | the key identifying the mapping to remove |
the value that was originally mapped to the key
public function iterator(Void):Iterator
Returns an iterator to iterate over the values of this map.
an iterator to iterate over the values of this map
public function valueIterator(Void):Iterator
Returns an iterator to iterate over the values of this map.
an iterator to iterate over the values of this map
public function keyIterator(Void):Iterator
Returns an iterator to iterate over the keys of this map.
an iterator to iterate over the keys of this map