Package | com.bmap.core.hashmap |
Class | public class HashMap |
Inheritance | HashMap ![]() |
Implements | IHashMap |
See also
Property | Defined By | ||
---|---|---|---|
map : Dictionary
Defines the underlying object which contains the key / value
mappings of an IMap implementation. | HashMap |
Method | Defined By | ||
---|---|---|---|
HashMap(useWeakReferences:Boolean = true)
Creates a new HashMap instance. | HashMap | ||
clear():void
Resets all key / values in the HashMap instance to null
| HashMap | ||
clearAllExcept(keyId:*):void
Clears all key / values defined in the HashMap instance
with the exception of the specified key
| HashMap | ||
containsKey(key:*):Boolean
Determines if a key exists in the HashMap instance
| HashMap | ||
containsValue(value:*):Boolean
Determines if a value exists in the HashMap instance
If multiple keys exists in the map with the same value,
the first key located which is mapped to the specified
key will be returned. | HashMap | ||
getEntries():Array
Returns an Array of IHashMapEntry
objects based on the underlying internal map. | HashMap | ||
getKey(value:*):*
Returns the value of the specified key from the HashMap
instance. | HashMap | ||
getKeys():Array
Returns each key added to the HashMap instance
| HashMap | ||
getValue(key:*):*
Retrieves the value of the specified key from the HashMap instance
| HashMap | ||
getValues():Array
Retrieves each value assigned to each key in the HashMap instance
| HashMap | ||
isEmpty():Boolean
Determines if the current HashMap instance is empty
| HashMap | ||
put(key:*, value:*):void
Adds a key and value to the HashMap instance
| HashMap | ||
putAll(table:Dictionary):void
Places all name / value pairs into the current
IMap instance. | HashMap | ||
putEntry(entry:IHashMapEntry):void
putEntry is intended as a pseudo-overloaded
put implementation whereby clients may call
putEntry to pass an IHashMapEntry
implementation. | HashMap | ||
remove(key:*):void
Removes a key and value from the HashMap instance
| HashMap | ||
reset():void
Resets all key value assignments in the HashMap instance to null
| HashMap | ||
resetAllExcept(keyId:*):void
Resets all key / values defined in the HashMap instance to null
with the exception of the specified key
| HashMap | ||
size():int
Determines the size of the HashMap instance
| HashMap |
map | property |
protected var map:Dictionary
Defines the underlying object which contains the key / value
mappings of an IMap
implementation.
See also
HashMap | () | Constructor |
public function HashMap(useWeakReferences:Boolean = true)
Creates a new HashMap instance. By default, weak key references are used in order to ensure that objects are eligible for Garbage Collection iimmediatly after they are no longer being referenced, if the only reference to an object is in the specified HashMap object, the key is eligible for garbage collection and is removed from the table when the object is collected
ParametersuseWeakReferences:Boolean (default = true ) — if weak key references should be used
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap( false );
clear | () | method |
public function clear():void
Resets all key / values in the HashMap instance to null
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); Trace.log( map.size() ); //2 map.clear(); Trace.log( map.size() ); //0
clearAllExcept | () | method |
public function clearAllExcept(keyId:*):void
Clears all key / values defined in the HashMap instance with the exception of the specified key
Parameters
keyId:* — key which is not to be cleared from the map
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); Trace.log( map.size() ); //2 map.clearAllExcept( "editor", editorVO ); Trace.log( map.getValues() ); //[object, editorVO] Trace.log( map.size() ); //1
containsKey | () | method |
public function containsKey(key:*):Boolean
Determines if a key exists in the HashMap instance
Parameters
key:* — key in which to determine existance in the map
|
Boolean — true if the key exisits, false if not
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); Trace.log( map.containsKey( "admin" ) ); //true
containsValue | () | method |
public function containsValue(value:*):Boolean
Determines if a value exists in the HashMap instance
If multiple keys exists in the map with the same value, the first key located which is mapped to the specified key will be returned.
Parameters
value:* — value in which to determine existance in the map
|
Boolean — true if the value exisits, false if not
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); Trace.log( map.containsValue( adminVO ) ); //true
getEntries | () | method |
public function getEntries():Array
Returns an Array
of IHashMapEntry
objects based on the underlying internal map.
Array |
getKey | () | method |
public function getKey(value:*):*
Returns the value of the specified key from the HashMap instance.
If multiple keys exists in the map with the same value, the first key located which is mapped to the specified value will be returned.
Parameters
value:* — key in which to retrieve the value of
|
* — the value of the specified key
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); Trace.log( map.getKey( adminVO ) ); //admin
getKeys | () | method |
public function getKeys():Array
Returns each key added to the HashMap instance
ReturnsArray — Array of key identifiers
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); Trace.log( map.getKeys() ); //admin, editor
getValue | () | method |
public function getValue(key:*):*
Retrieves the value of the specified key from the HashMap instance
Parameters
key:* — key in which to retrieve the value of
|
* — the value of the specified key, otherwise returns undefined
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); Trace.log( map.getValue( "editor" ) ); //[object, editorVO]
getValues | () | method |
public function getValues():Array
Retrieves each value assigned to each key in the HashMap instance
ReturnsArray — Array of values assigned for all keys in the map
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); Trace.log( map.getValues() ); //[object, adminVO],[object, editorVO]
isEmpty | () | method |
public function isEmpty():Boolean
Determines if the current HashMap instance is empty
ReturnsBoolean — true if the current map is empty, false if not
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); Trace.log( map.isEmpty() ); //true map.put( "admin", adminVO ); Trace.log( map.isEmpty() ); //false
put | () | method |
public function put(key:*, value:*):void
Adds a key and value to the HashMap instance
Parameters
key:* — key to add to the map
| |
value:* — value of the specified key
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "user", userVO );
putAll | () | method |
public function putAll(table:Dictionary):void
Places all name / value pairs into the current
IMap
instance.
Parameters
table:Dictionary — Object of name / value pairs
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var table:Object = {a: "foo", b: "bar"}; var map:IMap = new HashMap(); map.putAll( table ); Trace.log( map.getValues() ); // foo, bar
putEntry | () | method |
public function putEntry(entry:IHashMapEntry):void
putEntry
is intended as a pseudo-overloaded
put
implementation whereby clients may call
putEntry
to pass an IHashMapEntry
implementation.
Parameters
entry:IHashMapEntry — IHashMapEntry implementation
|
remove | () | method |
public function remove(key:*):void
Removes a key and value from the HashMap instance
Parameters
key:* — key to remove from the map
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.remove( "admin" );
reset | () | method |
public function reset():void
Resets all key value assignments in the HashMap instance to null
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); map.reset(); Trace.log( map.getValues() ); //null, null
resetAllExcept | () | method |
public function resetAllExcept(keyId:*):void
Resets all key / values defined in the HashMap instance to null with the exception of the specified key
Parameters
keyId:* — key which is not to be cleared from the map
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); Trace.log( map.getValues() ); //[object, adminVO],[object, editorVO] map.resetAllExcept( "editor", editorVO ); Trace.log( map.getValues() ); //null,[object, editorVO]
size | () | method |
public function size():int
Determines the size of the HashMap instance
Returnsint — the current size of the map instance
|
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; var map:IMap = new HashMap(); map.put( "admin", adminVO ); map.put( "editor", editorVO ); Trace.log( map.size() ); //2
Hashmap
instance has keys
and values added and retrieved.
import com.ericfeminella.collections.HashMap; import com.ericfeminella.collections.IMap; private function init() : void { var map:IMap = new HashMap(); map.put("a", "value A"); map.put("b", "value B"); map.put("c", "value C"); map.put("x", "value X"); map.put("y", "value Y"); map.put("z", "value Z"); Trace.log( map.getKeys() ); Trace.log( map.getValues() ); Trace.log( map.size() ); // outputs the following: // b,x,z,a,c,y // value B,value X,value Z,value A,value C,value Y // 6 }