Packagecom.elad.framework.utils.collections
Classpublic class HashMapCollection
ImplementsIMap

Hash table based implementation of the IMap interface. HashMapCollection class makes no guarantees to the order of the map or that the order will remain the same. The class let you pass a pair of keys and values and provides constant-time performance for the basic operations of addItem, removeItemAt and getItemValue since they require no iteration over the collection.

Example shows how to use the HashMapCollection


Example
     
   private function map():void {
    
    var map:IMap = new HashMapCollection();
    map.addEventListener(CollectionEvent.COLLECTION_CHANGE, handler);
    
    map.addItem("John", "212-452-8086");
    map.addItem("James", "718-345-3455");
    map.addItem("Micheal", "917-782-8822");
    map.addItem("Ron", "212-426-8855");
    map.addItem("Mike", "212-255-2436");
    map.addItem("Jenny", "718-344-2433");
    map.addItem("Jack", "917-222-4352");
    map.addItem("Riki", "981-222-1122");
    trace("\nAll items: "+map.toString()+"\n");
    
    trace("containsKey Jack? "+map.containsKey("Jack"));
    trace("containsValue 718-344-2433? "+map.containsValue("718-344-2433"));
    trace("getItemKey 718-344-2433: "+map.getItemKey("718-344-2433"));
    trace("getItemValue Jenny: "+map.getItemValue("Jenny"));
    
    map.removeItemAt("Riki");
    trace("Remove Riki.");
    trace("getItemValue Riki: "+map.getItemValue("Riki"));    
    trace("Comapre: "+map.compare("Ron", "212-426-8855"));
    
    map.removeAll();
    trace("\nAll items: "+map.toString()+"\n");
    
   }
   
   private function handler(event:CollectionEvent):void 
   {
    trace("Event: "+event.kind);
   }
   
     

See also

mx.events.CollectionEvent
com.elad.framework.utils.collections
flash.events.IEventDispatcher
flash.utils.Dictionary


Public Properties
 PropertyDefined by
  addAll : HashMapCollection
[write-only] Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
HashMapCollection
  isEmpty : Boolean
[read-only] Check if the collection has pairs of values and keys or empty
HashMapCollection
  keySet : Array
[read-only] Returns an array collection of the keys contained in this map.
HashMapCollection
  length : int
[read-only] Will result in the length of the map collection.
HashMapCollection
Public Methods
 MethodDefined by
  
HashMapCollection(useWeakReferences:Boolean = true)
Defualt constractor create the Dictionary and set the event dispatcher.
HashMapCollection
  
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
HashMapCollection
  
addItem(key:*, value:*):void
Add a pair consists of key and value.
HashMapCollection
  
clone():Object
Clone the map, the keys and values themselves are not cloned.
HashMapCollection
  
compare(key:*, value:*):Boolean
Compare specified key with the map value for equality.
HashMapCollection
  
containsKey(key:*):Boolean
Method to check if a key exists in the map collection.
HashMapCollection
  
containsValue(value:*):Boolean
Method to check if a value exist in the map colletcion.
HashMapCollection
  
dispatchEvent(event:Event):Boolean
HashMapCollection
  
getItemKey(value:*):String
Retrieve an item key based on a value.
HashMapCollection
  
Method to retrieve all the items values in the collection.
HashMapCollection
  
getItemValue(key:*):*
Retrieve item value based on the item key.
HashMapCollection
  
getKeys():Array
Method to retrieve the list of keys avaliable in the map.
HashMapCollection
  
hasEventListener(type:String):Boolean
HashMapCollection
  
removeAll():void
Remove the entire pairs in the collection.
HashMapCollection
  
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
HashMapCollection
  
removeItemAt(key:*):void
Remove the value based on the key without the need to iteration.
HashMapCollection
  
reset():void
Method to clear the values of the collection.
HashMapCollection
  
toString():String
Method to convert the map into a string representation consists of a list of key-value.
HashMapCollection
  
willTrigger(type:String):Boolean
HashMapCollection
Events
 EventSummaryDefined by
   Dispatched when the HashMapCollection has been updated in some way.HashMapCollection
Property detail
addAllproperty
addAll:HashMapCollection  [write-only]

Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.

Implementation
    public function set addAll(value:HashMapCollection):void
isEmptyproperty 
isEmpty:Boolean  [read-only]

Check if the collection has pairs of values and keys or empty

Implementation
    public function get isEmpty():Boolean
keySetproperty 
keySet:Array  [read-only]

Returns an array collection of the keys contained in this map.

Implementation
    public function get keySet():Array
lengthproperty 
length:int  [read-only]

Will result in the length of the map collection.

Implementation
    public function get length():int
Constructor detail
HashMapCollection()constructor
public function HashMapCollection(useWeakReferences:Boolean = true)

Defualt constractor create the Dictionary and set the event dispatcher.

Parameters
useWeakReferences:Boolean (default = true) — Instructs the Dictionary object to use "weak" references on object keys.

See also

flash.utils.Dictionary
Method detail
addEventListener()method
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):voidParameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
 
priority:int (default = 0)
 
useWeakReference:Boolean (default = false)
addItem()method 
public function addItem(key:*, value:*):void

Add a pair consists of key and value.

Parameters
key:*
 
value:*
clone()method 
public function clone():Object

Clone the map, the keys and values themselves are not cloned.

Returns
Object — Returns a shallow copy of this HashMap instance
compare()method 
public function compare(key:*, value:*):Boolean

Compare specified key with the map value for equality.

Parameters
key:*
 
value:*

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

Method to check if a key exists in the map collection.

Parameters
key:*

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

Method to check if a value exist in the map colletcion.

Parameters
value:*

Returns
Boolean
dispatchEvent()method 
public function dispatchEvent(event:Event):BooleanParameters
event:Event

Returns
Boolean
getItemKey()method 
public function getItemKey(value:*):String

Retrieve an item key based on a value.

Parameters
value:*

Returns
String
getItemsValues()method 
public function getItemsValues():Array

Method to retrieve all the items values in the collection.

Returns
Array — An array collection with all the values.
getItemValue()method 
public function getItemValue(key:*):*

Retrieve item value based on the item key.

Parameters
key:*

Returns
*
getKeys()method 
public function getKeys():Array

Method to retrieve the list of keys avaliable in the map.

Returns
Array — An array collection with the keys.
hasEventListener()method 
public function hasEventListener(type:String):BooleanParameters
type:String

Returns
Boolean
removeAll()method 
public function removeAll():void

Remove the entire pairs in the collection.

removeEventListener()method 
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):voidParameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
removeItemAt()method 
public function removeItemAt(key:*):void

Remove the value based on the key without the need to iteration. The method also call an event dispatcher.

Parameters
key:*
reset()method 
public function reset():void

Method to clear the values of the collection. Keys will stays but values will be removed.

toString()method 
public function toString():String

Method to convert the map into a string representation consists of a list of key-value.

Returns
String — Returns a string representation of this map. The string representation consists of a list of key-value.
willTrigger()method 
public function willTrigger(type:String):BooleanParameters
type:String

Returns
Boolean
Event detail
collectionChangeevent 
Event object type: mx.events.CollectionEvent

Dispatched when the HashMapCollection has been updated in some way.