org.jaffa.util
Class ListMap

java.lang.Object
  extended byorg.jaffa.util.ListMap
All Implemented Interfaces:
Cloneable, Map, Serializable

public class ListMap
extends Object
implements Map, Cloneable, Serializable

This class combines the utility of the HashMap & the ListSet. Features are: 1) Ensure quick random access to an object using a 'key' 2) Iterate through the Map in the order in which the entries were made

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Constructor Summary
ListMap()
          Creates new ListMap
ListMap(int initialCapacity)
          Creates new ListMap specifying the initial capacity.
ListMap(int initialCapacity, float loadFactor)
          Creates new ListMap specifying the initial capacity and load factor.
ListMap(Map t)
          Creates new ListMap from an existing Map
 
Method Summary
 void clear()
          Removes all mappings from this map .
 Object clone()
          Returns a clone of the 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.
 Set entrySet()
          Returns a set view of the mappings contained in this map.
 boolean equals(Object o)
          Compares the specified object with this map for equality.
 Object get(Object key)
          Returns the value to which this map maps the specified key.
 Object getByIndex(int index)
          Returns the mapping at the specified index.
 int hashCode()
          Returns the hash code value for this map.
 int indexOf(Object key)
          Returns the index in this Map of the specified key.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 Set keySet()
          Returns a set view of the keys contained in this map.
 Object put(int index, Object key, Object value)
          Adds an object to the Map.
 Object put(Object key, Object value)
          Adds an object to the Map.
 void putAll(Map t)
          Copies all of the mappings from the specified map to this map.
 Object remove(int index)
          Removes the mapping for this index from this map if it is present.
 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.
 Collection values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListMap

public ListMap()
Creates new ListMap


ListMap

public ListMap(int initialCapacity)
Creates new ListMap specifying the initial capacity.

Parameters:
initialCapacity - The initial capacity.

ListMap

public ListMap(int initialCapacity,
               float loadFactor)
Creates new ListMap specifying the initial capacity and load factor.

Parameters:
initialCapacity - The initial capacity.
loadFactor - The loadFactor.

ListMap

public ListMap(Map t)
Creates new ListMap from an existing Map

Parameters:
t - An existing Map.
Method Detail

put

public Object put(Object key,
                  Object value)
Adds an object to the Map. If the map previously contained a mapping for this key, the old value is replaced by the specified value.

Specified by:
put in interface Map
Parameters:
key - The key used for adding the object.
value - The object to be added.
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.

remove

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

Specified by:
remove in interface Map
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.

keySet

public Set keySet()
Returns a set view of the keys contained in this map.

Specified by:
keySet in interface Map
Returns:
a set view of the keys contained in this map.

clear

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

Specified by:
clear in interface Map

values

public Collection values()
Returns a collection view of the values contained in this map.

Specified by:
values in interface Map
Returns:
a collection view of the values contained in this map.

hashCode

public int hashCode()
Returns the hash code value for this map.

Specified by:
hashCode in interface Map
Returns:
the hash code value for this map.

containsKey

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

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

size

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

Specified by:
size in interface Map
Returns:
the number of key-value mappings in this map.

entrySet

public Set entrySet()
Returns a set view of the mappings contained in this map.

Specified by:
entrySet in interface Map
Returns:
a set view of the mappings contained in this map.

containsValue

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

Specified by:
containsValue in interface Map
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.

putAll

public void putAll(Map t)
Copies all of the mappings from the specified map to this map.

Specified by:
putAll in interface Map
Parameters:
t - Mappings to be stored in this map.

equals

public boolean equals(Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a ListMap and the two Maps represent the same mappings.

Specified by:
equals in interface Map
Parameters:
o - object to be compared for equality with this map.
Returns:
true if the specified object is equal to this map.

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in interface Map
Returns:
true if this map contains no key-value mappings.

get

public Object get(Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Specified by:
get in interface Map
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.

put

public Object put(int index,
                  Object key,
                  Object value)
Adds an object to the Map. If the map previously contained a mapping for this key, the old value is replaced by the specified value.

Parameters:
index - The position at which the the object will be added.
key - The key used for adding the object.
value - The object to be added.
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.

getByIndex

public Object getByIndex(int index)
Returns the mapping at the specified index.

Parameters:
index - The position at from which the mapping is to be retrieved.
Returns:
the mapping at the specified index.

remove

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

Parameters:
index - The position at from which the mapping is to be removed.
Returns:
previous value associated with position, or null if there was no mapping for position.

indexOf

public int indexOf(Object key)
Returns the index in this Map of the specified key. A '-1' is returned in case no such key exists.

Parameters:
key - The key used for adding the object.
Returns:
the index in this Map of the specified key.

clone

public Object clone()
             throws CloneNotSupportedException
Returns a clone of the Map.

Returns:
a clone of the Map.
Throws:
CloneNotSupportedException - if cloning is not supported. Should never happen.


Copyright © 2002-2004 JAFFA Project.