Build 1.0_r1

java.util
Class AbstractMap

java.lang.Object
  extended by java.util.AbstractMap
All Implemented Interfaces:
Map
Direct Known Subclasses:
ConcurrentHashMap, EnumMap, HashMap, IdentityHashMap, TreeMap, WeakHashMap

public abstract class AbstractMap
extends Object
implements Map

AbstractMap is an abstract implementation of the Map interface. This Implementation does not support adding. A subclass must implement the abstract method entrySet().


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry
 
Constructor Summary
protected AbstractMap()
          Constructs a new instance of this AbstractMap.
 
Method Summary
 void clear()
          Removes all elements from this Map, leaving it empty.
protected  Object clone()
          Returns a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
 boolean containsKey(Object key)
          Searches this Map for the specified key.
 boolean containsValue(Object value)
          Searches this Map for the specified value.
abstract  Set entrySet()
          Returns a set view of the mappings contained in this map.
 boolean equals(Object object)
          Compares the specified object to this Map and answer if they are equal.
 Object get(Object key)
          Returns the value of the mapping with the specified key.
 int hashCode()
          Returns an integer hash code for the receiver.
 boolean isEmpty()
          Returns if this Map has no elements, a size of zero.
 Set keySet()
          Returns a Set of the keys contained in this Map.
 Object put(Object key, Object value)
          Maps the specified key to the specified value.
 void putAll(Map map)
          Copies every mapping in the specified Map to this Map.
 Object remove(Object key)
          Removes a mapping with the specified key from this Map.
 int size()
          Returns the number of elements in this Map.
 String toString()
          Returns the string representation of this Map.
 Collection values()
          Returns a collection of the values contained in this map.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMap

protected AbstractMap()
Constructs a new instance of this AbstractMap.

Method Detail

clear

public void clear()
Removes all elements from this Map, leaving it empty.

Specified by:
clear in interface Map
Throws:
UnsupportedOperationException - when removing from this Map is not supported
See Also:
isEmpty(), size()

containsKey

public boolean containsKey(Object key)
Searches this Map for the specified key.

Specified by:
containsKey in interface Map
Parameters:
key - the object to search for
Returns:
true if key is a key of this Map, false otherwise

containsValue

public boolean containsValue(Object value)
Searches this Map for the specified value.

Specified by:
containsValue in interface Map
Parameters:
value - the object to search for
Returns:
true if value is a value of this Map, false otherwise

entrySet

public abstract Set entrySet()
Returns a set view of the mappings contained in this map. Each element in this set is a Map.Entry. The set is backed by the map so changes to one are reflected by the other. (If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined.) The set supports remove, removeAll, retainAll and clear operations, and it does not support add or addAll operations.

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

equals

public boolean equals(Object object)
Compares the specified object to this Map and answer if they are equal. The object must be an instance of Map and contain the same key/value pairs.

Specified by:
equals in interface Map
Overrides:
equals in class Object
Parameters:
object - the object to compare with this object
Returns:
true if the specified object is equal to this Map, false otherwise
See Also:
hashCode()

get

public Object get(Object key)
Returns the value of the mapping with the specified key.

Specified by:
get in interface Map
Parameters:
key - the key
Returns:
the value of the mapping with the specified key

hashCode

public int hashCode()
Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Specified by:
hashCode in interface Map
Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(Object)

isEmpty

public boolean isEmpty()
Returns if this Map has no elements, a size of zero.

Specified by:
isEmpty in interface Map
Returns:
true if this Map has no elements, false otherwise
See Also:
size()

keySet

public Set keySet()
Returns a Set of the keys contained in this Map. The set is backed by this Map so changes to one are reflected by the other. The set does not support adding.

Specified by:
keySet in interface Map
Returns:
a Set of the keys

put

public Object put(Object key,
                  Object value)
Maps the specified key to the specified value.

Specified by:
put in interface Map
Parameters:
key - the key
value - the value
Returns:
the value of any previous mapping with the specified key or null if there was no mapping
Throws:
UnsupportedOperationException - when adding to this Map is not supported
ClassCastException - when the class of the key or value is inappropriate for this Map
IllegalArgumentException - when the key or value cannot be added to this Map
NullPointerException - when the key or value is null and this Map does not support null keys or values

putAll

public void putAll(Map map)
Copies every mapping in the specified Map to this Map.

Specified by:
putAll in interface Map
Parameters:
map - the Map to copy mappings from
Throws:
UnsupportedOperationException - when adding to this Map is not supported
ClassCastException - when the class of a key or value is inappropriate for this Map
IllegalArgumentException - when a key or value cannot be added to this Map
NullPointerException - when a key or value is null and this Map does not support null keys or values

remove

public Object remove(Object key)
Removes a mapping with the specified key from this Map.

Specified by:
remove in interface Map
Parameters:
key - the key of the mapping to remove
Returns:
the value of the removed mapping or null if key is not a key in this Map
Throws:
UnsupportedOperationException - when removing from this Map is not supported

size

public int size()
Returns the number of elements in this Map.

Specified by:
size in interface Map
Returns:
the number of elements in this Map

toString

public String toString()
Returns the string representation of this Map.

Overrides:
toString in class Object
Returns:
the string representation of this Map

values

public Collection values()
Returns a collection of the values contained in this map. The collection is backed by this map so changes to one are reflected by the other. The collection supports remove, removeAll, retainAll and clear operations, and it does not support add or addAll operations. This method returns a collection which is the subclass of AbstractCollection. The iterator method of this subclass returns a "wrapper object" over the iterator of map's entrySet(). The size method wraps the map's size method and the contains method wraps the map's containsValue method. The collection is created when this method is called at first time and returned in response to all subsequent calls. This method may return different Collection when multiple calls to this method, since it has no synchronization performed.

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

clone

protected Object clone()
                throws CloneNotSupportedException
Returns a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.

Overrides:
clone in class Object
Returns:
Object a shallow copy of this object.
Throws:
CloneNotSupportedException - if the receiver's class does not implement the interface Cloneable.

Build 1.0_r1

Please submit a feedback, bug or feature