Packagecom.ericfeminella.collections
Classpublic final class HashMap
ImplementsIMap

IMap implementation which dynamically creates a HashMap of key / value pairs and provides a standard API for working with the map


Example
The following example demonstrates a typical use-case in a Hashmap instance has keys and values added and retrieved.
 import com.ericfeminella.collections.HashMap;
 import com.ericfeminella.collections.IMap;

 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( map.getKeys() );
 trace( map.getValues() );
 trace( map.size() );
 // outputs the following:
 // b,x,z,a,c,y
 // value B,value X,value Z,value A,value C,value Y
 // 6
          

See also

flash.utils.Dictionary
com.ericfeminella.collections.IMap


Public Methods
 MethodDefined 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
HashMap
  
getEntries():IList
Returns an IList of IHashMapEntry objects based on the underlying internal map.
HashMap
  
getKey(value:*):*
Returns a key value 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
[new] putAll places all name / value pairs defined in an Object or Dictionary instance into the IMap instance.
HashMap
  
putEntry(entry:IHashMapEntry):void
[new] 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
Constructor detail
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

Parameters
useWeakReferences:Boolean (default = true) — if weak key references should be used

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap( false );
                  

Method detail
clear()method
public function clear():void

Resets all key / values in the HashMap instance to null


Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.size() ); //2

map.clear();
trace( 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

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.size() ); //2

map.clearAllExcept( "editor", editorVO );
trace( map.getValues() ); //[object, editorVO]
trace( map.size() ); //1
                  

containsKey()method 
public function containsKey(key:*):Boolean

Determines if a key exists in the HashMap instance

Parameters
key:* — the key in which to determine existance in the map

Returns
Boolean — true if the key exisits, false if not

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
trace( map.containsKey( "admin" ) ); //true
                  

containsValue()method 
public function containsValue(value:*):Boolean

Determines if a value exists in the HashMap instance

Parameters
value:* — the value in which to determine existance in the map

Returns
Boolean — true if the value exisits, false if not

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;
var map:IMap = new HashMap();
map.put( "admin", adminVO );
trace( map.containsValue( adminVO ) ); //true
                  

getEntries()method 
public function getEntries():IList

Returns an IList of IHashMapEntry objects based on the underlying internal map.

Returns
IList
getKey()method 
public function getKey(value:*):*

Returns a key value from the HashMap instance

Parameters
value:* — the key in which to retrieve the value of

Returns
String — the value of the specified key

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
trace( map.getKey( adminVO ) ); //admin
                  

getKeys()method 
public function getKeys():Array

Returns each key added to the HashMap instance

Returns
Array — Array of key identifiers

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getKeys() ); //admin, editor
	  

getValue()method 
public function getValue(key:*):*

Retrieves the value of the specified key from the HashMap instance

Parameters
key:* — the key in which to retrieve the value of

Returns
* — the value of the specified key, otherwise returns undefined

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getValue( "editor" ) ); //[object, editorVO]
                  

getValues()method 
public function getValues():Array

Retrieves each value assigned to each key in the HashMap instance

Returns
Array — Array of values assigned for all keys in the map

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getValues() ); //[object, adminVO],[object, editorVO]
                  

isEmpty()method 
public function isEmpty():Boolean

Determines if the current HashMap instance is empty

Returns
Boolean — true if the current map is empty, false if not

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
trace( map.isEmpty() ); //true
map.put( "admin", adminVO );
trace( 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

Example
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:DictionaryObject of name / value pairs

Example
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( 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:IHashMapEntryIHashMapEntry 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

Example
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


Example
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( 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

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getValues() ); //[object, adminVO],[object, editorVO]

map.resetAllExcept( "editor", editorVO );
trace( map.getValues() ); //null,[object, editorVO]
                  

size()method 
public function size():int

Determines the size of the HashMap instance

Returns
int — the current size of the map instance

Example
import com.ericfeminella.collections.HashMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new HashMap();
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.size() ); //2