Class org.aswing.utils.HashMap

Description

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!");
     }
 

Method Index

new HashMap()
clear(), clone(), containsKey(), containsValue(), get(), isEmpty(), keys(), put(), putArray(), remove(), size(), toString(), values()

Constructor Detail

HashMap

public function HashMap()

Method Detail

size

public function size():Number

Returns the number of keys in this HashMap.

isEmpty

public function isEmpty():Boolean

Returns if this HashMap maps no keys to values.

keys

public function keys():Array

Returns an Array of the keys in this HashMap.

values

public function values():Array

Returns an Array of the values in this HashMap.

containsValue

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.

containsKey

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

keyThe key whose presence in this map is to be tested

Return

true if this map contains a mapping for the specified

get

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

keythe key whose associated value is to be returned.

Return

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.

put

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.

Parameters

keykey with which the specified value is to be associated.
valuevalue to be associated with the specified key.

Return

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

public function remove(key)

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

Parameters

keykey whose mapping is to be removed from the map.

Return

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.

putArray

public function putArray(Arr:Array, key:String):Void

put a array's all element into the HashMap, key+index will be the key

clear

public function clear():Void

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

clone

public function clone():HashMap

Return a same copy of HashMap object

toString

public function toString():String