Class org.as2lib.data.holder.map.HashMap

org.as2lib.core.BasicClass
   +--org.as2lib.data.holder.map.AbstractMap
      +--org.as2lib.data.holder.map.HashMap

Implemented Interfaces

Map

Description

HashMap can be used to map any type of key to any type of value.

This class offers ordered mapping functionality. That means that the methods getKeys and getValues return the keys and values in the order they were put to the map and that the iterators returned by the methods valueIterator and keyIterator also iterate over the keys and values in the correct order.

This 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 this map you can use the getKeys, getValues and get methods. If you want to iterate over the values of this 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 this 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.

To change the string representation returned by the toString method you can set your own stringifier using the static AbstractMap.setStringifier method.

Example: // constructs the map var key1:Object = new Object(); var key2:Object = new Object(); var key3:Object = new Object(); var map:Map = new HashMap(); map.put(key1, "value1"); map.put(key2, "value2"); map.put(key3, "value3"); // uses the map trace(map.get(key1)); trace(map.get(key2)); trace(map.get(key3));

Output:

   value1
   value2
   value3
 

Method Index

new HashMap()

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

Inherited from AbstractMap

getStringifier(), setStringifier()

Constructor Detail

HashMap

public function HashMap(source)

Constructs a new HashMap instance.

This map iterates over the passed-in source with the for..in loop and uses the variables' names as key and their values as value. Variables that are hidden from for..in loops will not be added to this map.

Parameters

source(optional) an object that contains key-value pairs to populate this map with

Method Detail

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 passed-in key

Specified By

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

put

public function put(key, value)

Maps the given key to the value.

Both key and value are allowed to be null and undefined.

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 or undefined

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.

Parameters

mapthe mappings to add to this map

Specified By

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

clear

public function clear(Void):Void

Clears all mappings.

Specified By

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

remove

public function remove(key)

Removes the mapping from the given 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

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

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

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

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 this map.

The string representation is obtained using the stringifier returned by the static AbstractMap.getStringifier method.

Return

the string representation of this map

Specified By

toString() in org.as2lib.core.BasicInterface

Overrides

toString() in org.as2lib.core.BasicClass