public abstract class Map<K,V>
extends java.lang.Object
Map
is a data structure consisting of a set of keys and values in which each key is mapped to a single
value. The class of the objects used as keys is declared when the Map
is declared, as is the class of the
corresponding values.
A Map
provides helper methods to iterate through all of the keys contained in it, as well as various methods
to access and update the key/value pairs.
Changes from the java.util version:
Does not implement Serializable nor clone()
This class is an abstract implementation of the Map
interface. This default implementation does not support
adding. A subclass must implement the abstract method entrySet().Modifier | Constructor and Description |
---|---|
protected |
Map()
Constructs a new instance of this
AbstractMap . |
Modifier and Type | Method and Description |
---|---|
abstract void |
clear()
Removes all elements from this
Map , leaving it empty. |
abstract boolean |
containsKey(K key)
Returns whether this
Map contains the specified key. |
abstract boolean |
containsValue(V value)
Returns whether this
Map contains the specified value. |
abstract Set<MapEntry<K,V>> |
entrySet()
Returns a
Set containing all of the mappings in this Map . |
boolean |
equals(java.lang.Object object)
By default, equals isn't supported for maps or other collections, though subclasses can choose to override this
behavior if they want.
|
abstract V |
get(K key)
Returns the value of the mapping with the specified key
|
int |
hashCode()
Returns the hash code for this object.
|
abstract boolean |
isEmpty()
Returns whether this map is empty.
|
abstract Set<K> |
keySet()
Returns a set of the keys contained in this
Map . |
abstract V |
put(K key,
V value)
Maps the specified key to the specified value.
|
abstract void |
putAll(Map<? extends K,? extends V> map)
Copies every mapping in the specified
Map to this Map . |
abstract V |
remove(K key)
Removes a mapping with the specified key from this
Map . |
abstract int |
size()
Returns the number of mappings in this
Map . |
java.lang.String |
toString()
Returns the string representation of this map.
|
abstract Collection<V> |
values()
Returns a
Collection of the values contained in this Map . |
public abstract Set<MapEntry<K,V>> entrySet()
Set
containing all of the mappings in this Map
. Each mapping is an instance of MapEntry
. As the Set
is backed by this Map
, changes in one will be reflected in the other.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- the object to compare to this object.true
if the specified object is equal to this list, false
otherwise; though by default
this method throws an exception and developers generally shouldn't use itpublic int hashCode()
hashCode
in class java.lang.Object
equals(Object)
public java.lang.String toString()
toString
in class java.lang.Object
public abstract void clear()
Map
, leaving it empty.public abstract boolean containsKey(K key)
Map
contains the specified key.key
- the key to search for.true
if this map contains the specified key, false
otherwise.public abstract boolean containsValue(V value)
Map
contains the specified value.value
- the value to search for.true
if this map contains the specified value, false
otherwise.public abstract V get(K key)
key
- the key.null
/ default value for non-nullable value
type if no mapping for the specified key is found.public abstract boolean isEmpty()
true
if this map has no elements, false
otherwise.size()
public abstract Set<K> keySet()
Map
. The Set
is backed by this Map
so changes
to one are reflected by the other. The Set
does not support adding.public abstract V put(K key, V value)
key
- the key.value
- the value.null
/ default value for non-nullable
value type if there was no mapping.java.lang.UnsupportedOperationException
- if adding to this Map
is not supported.java.lang.ClassCastException
- if the class of the key or value is inappropriate for this Map
.java.lang.IllegalArgumentException
- if the key or value cannot be added to this Map
.java.lang.NullPointerException
- if the key or value is null
and this Map
does not support
null
keys or values.public abstract void putAll(Map<? extends K,? extends V> map)
Map
to this Map
.map
- the Map
to copy mappings from.java.lang.UnsupportedOperationException
- if adding to this Map
is not supported.java.lang.ClassCastException
- if the class of a key or a value of the specified Map
is
inappropriate for this Map
.java.lang.IllegalArgumentException
- if a key or value cannot be added to this Map
.java.lang.NullPointerException
- if a key or value is null
and this Map
does not support
null
keys or values.public abstract V remove(K key)
Map
.key
- the key of the mapping to remove.null
/ default value for non-nullable value type if no
mapping for the specified key was foundjava.lang.UnsupportedOperationException
- if removing from this Map
is not supported.public abstract int size()
Map
.Map
.public abstract Collection<V> values()
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 Collection.remove(E)
, Collection.removeAll(jsimple.util.Collection<E>)
, Collection.retainAll(jsimple.util.Collection<E>)
, and Collection.clear()
operations, and it does not support Collection.add(E)
or Collection.addAll(jsimple.util.Collection<? extends E>)
operations.
This method returns a Collection
which is the subclass of Collection
. The Collection.iterator()
method of this subclass returns a "wrapper object" over the iterator of this Map
's
entrySet()
. The Collection.size()
method wraps this Map
's size()
method and the
Collection.contains(E)
method wraps this Map
's containsValue(V)
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.