Class Map


  extended by Object
      extended by Map

public class Map
extends Object

This class implements a hashtable, which maps keys to values. Any non-null object can be used as a key or as a value.


Constructor Summary
Map()
          Constructs a new Map instance.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 boolean containsKey(Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(Object value)
          Returns true if this map maps one or more keys to the specified value.
 List keys()
          Returns a list containing all the keys on this map.
 Object operator_get(Object key)
          Operator to return the value to which this map maps the specified key.
 Object operator_set(Object key, Object value)
          Associates the specified value with the specified key in this map.
 Map put(Object key, Object value)
          Associates the specified value with the specified key in this map.
 Object remove(Object key)
          Removes the mapping for this key from this map if it is present.
 int size()
          Returns the number of key-value mappings in this map.
 List values()
          Returns a list containing all the values on this map.
 
Methods inherited from class Object
toString, equals, hashCode
 
Methods inherited from
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Map

public Map()
Constructs a new Map instance.

Method Detail

size

public int size()
Returns the number of key-value mappings in this map.

Returns:
the number of key-value mappings in this map.

clear

public void clear()
Removes all mappings from this map.


put

public Map put(Object key,
               Object 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 by the specified value.

Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
this Map instance.

remove

public Object remove(Object key)
Removes the mapping for this key from this map if it is present.

Returns the value to which the map previously associated the key, or null if the map contained no mapping for this key. The map will not contain a mapping for the specified key once the call returns.

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

containsKey

public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key.

Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.

containsValue

public boolean containsValue(Object value)
Returns true if this map maps one or more keys to the specified value.

Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.

keys

public List keys()
Returns a list containing all the keys on this map. Order of keys on list is unspecified.

Returns:
List containing all the keys on this Map

values

public List values()
Returns a list containing all the values on this map. Order of values on list is unspecified.

Returns:
List containing all the values on this Map

operator_get

public Object operator_get(Object key)
Operator to return the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.

Map map = ...;
String s = map["name"];

Parameters:
key - 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.
See Also:
get

operator_set

public Object operator_set(Object key,
                           Object 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 by the specified value.

Map map = ...;
map["city"] = "Rome";

Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
the associated value
See Also:
set