PrimitiveTypeMap
- Author: Simon Wacker
- Classpath: org.as2lib.data.holder.map.PrimitiveTypeMap
- File last modified: Tuesday, 10 May 2005, 16:57:30
PrimitiveTypeMap can be used to map any primitive type key to any type
of value. Primitive data types are strings, numbers and booleans. When you use this map you normally use it in conjunction with string keys, because you can use arrays for numbers and for booleans you normally do not need a data holder at all.
Note that if you only want to map values to keys you can also do this using a dynamic or untyped object. But if you also want to be able to iterate over your keys and values in the correct order or if you want this iteration to be fast - the for..in loop is quite slow - you should use this map.
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 map:Map = new PrimitiveTypeMap(); 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
Summary
- containsKey
- containsValue
- getKeys
- getValues
- get
- put
- putAll
- remove
- clear
- iterator
- valueIterator
- keyIterator
- size
- isEmpty
- toString
Constructor
PrimitiveTypeMap
PrimitiveTypeMap 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.
Instance methods
clear
containsKey
key exists.That means whether a value has been mapped to it.
true if the key exists else falsecontainsValue
value is mapped to a key.true if the value is mapped to a key else falseget
key.keygetKeys
getValues
isEmpty
true if this map contains no mappings else falseiterator
keyIterator
put
key to the value.null and undefined values are allowed.
valuekeykey or undefinedputAll
map to this map.remove
key to the value.keysize
toString
The string representation is obtained using the stringifier returned by the static AbstractMap.getStringifier method.