Map
TypedMap is a wrapper for Map instances that ensures that only
values of a specific type are added to the wrapped map.
This class simply delegates all method invocations to the wrapped map. If the specific method is responsible for adding values it first checks if the values to add are of the expected type. If they are the method invocation is forwarded, otherwise an IllegalArgumentException is thrown.
new TypedMap()public function TypedMap(type:Function, map:Map)
Constructs a new TypedMap instance.
If the passed-in map does already contain values, these values do not
get type-checked.
type | the type of the values this map is allowed to contain |
map | the map to type-check |
| IllegalArgumentException | if the passed-in type is null
or undefined
|
| IllegalArgumentException | if map is null or
undefined
|
public function getType(Void):FunctionReturns the type that all values in the wrapped map have.
This is the type passed-in on construction.
the type that all values in the wrapped map have
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):ArrayReturns an array that contains all keys that have a value mapped to it.
an array that contains all keys
public function getValues(Void):ArrayReturns 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 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
| IllegalArgumentException | if the type of the passed-in value is
invalid
|
public function putAll(map:Map):Void
Copies all mappings from the passed-in map to this map.
If one value in the given map is invalid, no key-value pair will be
added.
map | the mappings to add to this map |
| IllegalArgumentException | if the type of any value to put is invalid |
public function remove(key)
Removes the mapping from the specified 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):IteratorReturns an iterator to iterate over the values of this map.
an iterator to iterate over the values of this map
iterator() in org.as2lib.data.holder.Map
public function valueIterator(Void):IteratorReturns an iterator to iterate over the values of this map.
an iterator to iterate over the values of this map
valueIterator() in org.as2lib.data.holder.Map
public function keyIterator(Void):IteratorReturns an iterator to iterate over the keys of this map.
an iterator to iterate over the keys of this map
keyIterator() in org.as2lib.data.holder.Map
public function size(Void):NumberReturns the amount of mappings.
the amount of mappings
public function isEmpty(Void):BooleanReturns whether this map contains any mappings.
true if this map contains no mappings else false
public function toString():StringReturns the string representation of the wrapped map.
the string representation of the wrapped map
toString() in org.as2lib.core.BasicInterface