Packagecom.bmap.core.hashmap
Classpublic class HashMap
InheritanceHashMap Inheritance Object
Implements IHashMap

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

View the examples

See also

http://livedocs.adobe.com/flex/3/langref/flash/utils/Dictionary.html
com.ericfeminella.collections.IMap


Protected Properties
 PropertyDefined By
  map : Dictionary
Defines the underlying object which contains the key / value mappings of an IMap implementation.
HashMap
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 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 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
Property Detail
mapproperty
protected var map:Dictionary

Defines the underlying object which contains the key / value mappings of an IMap implementation.

See also

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


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

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

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.log( map.containsValue( adminVO ) ); //true
         
         
getEntries()method 
public function getEntries():Array

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

Returns
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

Returns
* — 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.log( 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.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

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.log( 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.log( 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.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


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.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: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.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


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

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.log( map.size() ); //2
         
         
Examples
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;
     
     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
     }