Packageorg.aswing.util
Classpublic class HashMap
SubclassesUIDefaults

To successfully store and retrieve (key->value) mapping from a HashMap. HashMap accept any type of object to be the key: number, string, Object etc... But it is only get fast accessing with string type keys. Others are slow.

---------------------------------------------------------- This example creates a HashMap of friends. It uses the number of the friends as keys:

     function person(name,age,sex){
         this.name=name;
         this.age=age;
         this.sex=sex;
     }
     var friends = new HashMap();
     friends.put("one", new person("iiley",21,"M"));
     friends.put("two", new person("gothic man",22,"M"));
     friends.put("three", new person("rock girl",19,"F"));
 

To retrieve a friends, use the following code:

     var thisperson = friends.get("two");
     if (thisperson != null) {
         trace("two name is "+thisperson.name);
         trace("two age is "+thisperson.age);
         trace("two sex is "+thisperson.sex);
     }else{
         trace("two is not in friends!");
     }
 
/p>



Public Methods
 MethodDefined by
  
HashMap
  
clear():void
Clears this HashMap so that it contains no keys no values.
HashMap
  
Return a same copy of HashMap object
HashMap
  
containsKey(key:*):Boolean
Tests if the specified object is a key in this HashMap.
HashMap
  
containsValue(value:*):Boolean
Tests if some key maps into the specified value in this HashMap.
HashMap
  
eachKey(func:Function):void
Call func(key) for each key.
HashMap
  
eachValue(func:Function):void
Call func(value) for each value.
HashMap
  
get(key:*):*
Returns the value to which the specified key is mapped in this HashMap.
HashMap
  
getValue(key:*):*
Same functionity method with different name to get.
HashMap
  
isEmpty():Boolean
Returns if this HashMap maps no keys to values.
HashMap
  
keys():Array
Returns an Array of the keys in this HashMap.
HashMap
  
put(key:*, value:*):*
Associates the specified value with the specified key in this map.
HashMap
  
remove(key:*):*
Removes the mapping for this key from this map if present.
HashMap
  
size():int
Returns the number of keys in this HashMap.
HashMap
  
toString():String
HashMap
  
values():Array
Returns an Array of the values in this HashMap.
HashMap
Constructor detail
HashMap()constructor
public function HashMap()
Method detail
clear()method
public function clear():void

Clears this HashMap so that it contains no keys no values.

clone()method 
public function clone():HashMap

Return a same copy of HashMap object

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

Tests if the specified object is a key in this HashMap. This operation is very fast if it is a string.

Parameters
key:* — key The key whose presence in this map is to be tested

Returns
Booleantrue if this map contains a mapping for the specified
containsValue()method 
public function containsValue(value:*):Boolean

Tests if some key maps into the specified value in this HashMap. This operation is more expensive than the containsKey method.

Parameters
value:*

Returns
Boolean
eachKey()method 
public function eachKey(func:Function):void

Call func(key) for each key.

Parameters
func:Function — the function to call
eachValue()method 
public function eachValue(func:Function):void

Call func(value) for each value.

Parameters
func:Function — the function to call
get()method 
public function get(key:*):*

Returns the value to which the specified key is mapped in this HashMap. Return null if the key is not mapped to any value in this HashMap. This operation is very fast if the key is a string.

Parameters
key:* — key the key whose associated value is to be returned.

Returns
* — the value to which this map maps the specified key, or null if the map contains no mapping for this key or it is null value originally.
getValue()method 
public function getValue(key:*):*

Same functionity method with different name to get.

Parameters
key:* — key the key whose associated value is to be returned.

Returns
* — the value to which this map maps the specified key, or null if the map contains no mapping for this key or it is null value originally.
isEmpty()method 
public function isEmpty():Boolean

Returns if this HashMap maps no keys to values.

Returns
Boolean
keys()method 
public function keys():Array

Returns an Array of the keys in this HashMap.

Returns
Array
put()method 
public function put(key:*, value:*):*

Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced. If value is null, means remove the key from the map.

Parameters
key:* — key with which the specified value is to be associated.
 
value:* — value to be associated with the specified key. null to remove the key.

Returns
* — previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the HashMap previously associated null with the specified key.
remove()method 
public function remove(key:*):*

Removes the mapping for this key from this map if present.

Parameters
key:* — key key whose mapping is to be removed from the map.

Returns
* — previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.
size()method 
public function size():int

Returns the number of keys in this HashMap.

Returns
int
toString()method 
public function toString():String

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

Returns an Array of the values in this HashMap.

Returns
Array