Class org.as2lib.data.holder.map.TypedMap

Implemented Interfaces

Map

Description

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.

Method Index

new TypedMap()
clear(), containsKey(), containsValue(), get(), getKeys(), getType(), getValues(), isEmpty(), iterator(), keyIterator(), put(), putAll(), remove(), size(), toString(), valueIterator()

Constructor Detail

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.

Parameters

typethe type of the values this map is allowed to contain
mapthe map to type-check

Throws

IllegalArgumentExceptionif the passed-in type is null or undefined
IllegalArgumentExceptionif map is null or undefined

Method Detail

getType

public function getType(Void):Function

Returns the type that all values in the wrapped map have.

This is the type passed-in on construction.

Return

the type that all values in the wrapped map have

containsKey

public function containsKey(key):Boolean

Checks if the passed-in key exists.

That means whether a value has been mapped to it.

Parameters

keythe key to be checked for availability

Return

true if the key exists else false

Specified By

containsKey() in org.as2lib.data.holder.Map

containsValue

public function containsValue(value):Boolean

Checks if the passed-in value is mapped to a key.

Parameters

valuethe value to be checked for availability

Return

true if the value is mapped to a key else false

Specified By

containsValue() in org.as2lib.data.holder.Map

getKeys

public function getKeys(Void):Array

Returns an array that contains all keys that have a value mapped to it.

Return

an array that contains all keys

Specified By

getKeys() in org.as2lib.data.holder.Map

getValues

public function getValues(Void):Array

Returns an array that contains all values that are mapped to a key.

Return

an array that contains all mapped values

Specified By

getValues() in org.as2lib.data.holder.Map

get

public function get(key)

Returns the value that is mapped to the passed-in key.

Parameters

keythe key to return the corresponding value for

Return

the value corresponding to the key

Specified By

get() in org.as2lib.data.holder.Map

put

public function put(key, value)

Maps the given key to the value.

Parameters

keythe key used as identifier for the value
valuethe value to map to the key

Return

the value that was originally mapped to the key

Throws

IllegalArgumentExceptionif the type of the passed-in value is invalid

Specified By

put() in org.as2lib.data.holder.Map

putAll

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.

Parameters

mapthe mappings to add to this map

Throws

IllegalArgumentExceptionif the type of any value to put is invalid

Specified By

putAll() in org.as2lib.data.holder.Map

remove

public function remove(key)

Removes the mapping from the specified key to the value.

Parameters

keythe key identifying the mapping to remove

Return

the value that was originally mapped to the key

Specified By

remove() in org.as2lib.data.holder.Map

clear

public function clear(Void):Void

Clears all mappings.

Specified By

clear() in org.as2lib.data.holder.Map

iterator

public function iterator(Void):Iterator

Returns an iterator to iterate over the values of this map.

Return

an iterator to iterate over the values of this map

Specified By

iterator() in org.as2lib.data.holder.Map

See Also

valueIterator

public function valueIterator(Void):Iterator

Returns an iterator to iterate over the values of this map.

Return

an iterator to iterate over the values of this map

Specified By

valueIterator() in org.as2lib.data.holder.Map

See Also

keyIterator

public function keyIterator(Void):Iterator

Returns an iterator to iterate over the keys of this map.

Return

an iterator to iterate over the keys of this map

Specified By

keyIterator() in org.as2lib.data.holder.Map

See Also

size

public function size(Void):Number

Returns the amount of mappings.

Return

the amount of mappings

Specified By

size() in org.as2lib.data.holder.Map

isEmpty

public function isEmpty(Void):Boolean

Returns whether this map contains any mappings.

Return

true if this map contains no mappings else false

Specified By

isEmpty() in org.as2lib.data.holder.Map

toString

public function toString():String

Returns the string representation of the wrapped map.

Return

the string representation of the wrapped map

Specified By

toString() in org.as2lib.core.BasicInterface

Overrides

toString() in org.as2lib.core.BasicClass