|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.neoworks.util.HashMapMultiMap
HashMapMultiMap is a Multimap backed by a HashMap
of
Set
objects. This means it differs from a standard MultiMap in
a few important ways.
Nested Class Summary |
Nested classes inherited from class com.neoworks.util.MultiMap |
MultiMap.Entry |
Constructor Summary | |
HashMapMultiMap()
Public constructor |
Method Summary | |
void |
clear()
Removes all mappings from this multimap (optional operation). |
boolean |
containsKey(java.lang.Object key)
Returns true if this multimap contains a mapping for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this multimap maps one or more keys to the specified value. |
java.util.Set |
entrySet()
Get the EntrySet. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this multimap for equality. |
java.util.Set |
get(java.lang.Object key)
Returns the set of values to which this multimap maps the specified key. |
int |
hashCode()
Returns the hash code value for this multimap. |
boolean |
isEmpty()
Returns true if this multimap contains no key-value mappings. |
java.util.Collection |
keys()
Returns a collection view of the keys contained in this multimap. |
java.util.Set |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key in this multimap (optional operation). |
void |
putAll(MultiMap multimap)
Copies all of the mappings from the specified multimap to this multimap (optional operation). |
java.util.Set |
remove(java.lang.Object key)
Removes all the mappings for this key from this multimap if present (optional operation). |
java.lang.Object |
remove(java.lang.Object key,
java.lang.Object value)
Removes the (key, value) mapping from this multimap if present (optional operation). |
int |
size()
Returns the number of key-values mappings in this multimap. |
java.util.Collection |
uniqueKeys()
Returns a collection of the unique keys in this multimap. |
java.util.Collection |
values()
Returns a collection view of the values contained in this multimap. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HashMapMultiMap()
Method Detail |
public java.util.Set put(java.lang.Object key, java.lang.Object value) throws java.lang.UnsupportedOperationException, java.lang.ClassCastException, java.lang.IllegalArgumentException, java.lang.NullPointerException
put
in interface MultiMap
key
- Key with which the specified value is to be associated.value
- Value to be associated with the specified key.
Set
of values associated with the specified key (including the new addition).
java.lang.UnsupportedOperationException
- If the put operation is not supported by this multimap.
java.lang.ClassCastException
- If the class of the specified key or value prevents it from being stored in this
multimap.
java.lang.IllegalArgumentException
- If some aspect of this key or value prevents it from being stored in this multimap.
java.lang.NullPointerException
- This multimap does not permit null
keys or values, and the specified key
or value is null
.public java.util.Collection keys()
Iterator.remove
,
Collection.remove
, removeAll
retainAll
, and clear
operations.
It does not support the add
or addAll
operations.
This implementation does not return duplicate keys in the keyset.
keys
in interface MultiMap
public java.util.Set remove(java.lang.Object key) throws java.lang.UnsupportedOperationException
remove
in interface MultiMap
key
- Key whose mappings is to be removed from the multimap.
Set
of values associated with the specified key, or null
if there were no mappings
for key.
java.lang.UnsupportedOperationException
- If the remove operation is not supported by this multimap.public void clear() throws java.lang.UnsupportedOperationException
clear
in interface MultiMap
java.lang.UnsupportedOperationException
- If clear is not supported by this multimap.public java.util.Collection values()
Iterator.remove
,
Collection.remove
, removeAll
, retainAll
and clear
operations.
It does not support the add
or addAll
operations.
values
in interface MultiMap
public java.util.Set entrySet()
entrySet
in interface MultiMap
public int hashCode()
hashCodes
of each entry in the multimap's entrySet
view. This ensures that
t1.equals(t2)
implies that t1.hashCode()==t2.hashCode()
for any two multimaps t1 and t2,
as required by the general contract of Object.hashCode
.
hashCode
in interface MultiMap
hashCode
in class java.lang.Object
public boolean containsKey(java.lang.Object key) throws java.lang.ClassCastException, java.lang.NullPointerException
true
if this multimap contains a mapping for the specified key.
containsKey
in interface MultiMap
key
- Key whose presence in this multimap is to be tested.
true
if this multimap contains a mapping for the specified key.
java.lang.ClassCastException
- If the key is of an inappropriate type for this multimap.
java.lang.NullPointerException
- If the key is null and this multimap does not not permit null keyspublic void putAll(MultiMap multimap) throws java.lang.UnsupportedOperationException, java.lang.ClassCastException, java.lang.IllegalArgumentException, java.lang.NullPointerException
putAll
in interface MultiMap
multimap
- Mappings to be stored in this multimap.
java.lang.UnsupportedOperationException
- If the put operation is not supported by this multimap.
java.lang.ClassCastException
- If the class of the specified key or value prevents it from being stored in this
multimap.
java.lang.IllegalArgumentException
- If some aspect of a key or value in the specified multimap prevents it from being
stored in this multimap.
java.lang.NullPointerException
- This multimap does not permit null
keys or values, and the specified key
or value is null
.public int size()
Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.
size
in interface MultiMap
public java.util.Collection uniqueKeys()
uniqueKeys
in interface MultiMap
public java.lang.Object remove(java.lang.Object key, java.lang.Object value) throws java.lang.UnsupportedOperationException
remove
in interface MultiMap
value
- The value associated with the key to identify the item to removekey
- Key whose mapping to the value is to be removed from the multimap.
null
if the given mapping did not exist.
java.lang.UnsupportedOperationException
- If the remove operation is not supported by this multimap.public boolean containsValue(java.lang.Object value)
(value==null ? v==null : value.equals(v))
. This operation will probably require time linear in the
multimap size for most implementations of the MultiMap
interface.
containsValue
in interface MultiMap
value
- Value whose presence in this multimap is to be tested.
true
if this multimap maps one or more keys to the specified value.public boolean equals(java.lang.Object o)
t1.entrySet().equals(t2.entrySet())
. This ensures that the equals method works properly across different
implementations of the MultiMap
interface.
equals
in interface MultiMap
equals
in class java.lang.Object
o
- Object to be compared for equality with this multimap.
true
if the specified object is equal to this multimap.public java.util.Set get(java.lang.Object key) throws java.lang.ClassCastException, java.lang.NullPointerException
null
does indicate that the multimap contains no mappings for the
key; it's possible that the multimap explicitly maps the key to null, in this case the returned set will contain
null
possibly along with other objects. The containsKey
operation may also be used to
distinguish these two cases.
get
in interface MultiMap
key
- Key whose associated value is to be returned.
Set
of values to which this multimap maps the specified key, or null
if the
multimap contains no mapping for this key.
java.lang.ClassCastException
- If the key is of an inappropriate type for this multimap.
java.lang.NullPointerException
- If the key is null
and this multimap does not not permit null
keyspublic boolean isEmpty()
true
if this multimap contains no key-value mappings.
isEmpty
in interface MultiMap
true
if this multimap contains no key-value mappings.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |