|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
common.HashMultiMap
public class HashMultiMap
Implementation of the MultiMap interface that uses a HashMap for the map and HashSets for automatically created sets.
Technically, a MultiMap implementation should put a wrapper around
the iterators for the underlying data structure so the values associated
with keys are unmodifiable sets. Also, its Map.Entry objects
should have a setValue
method that removes the key when the
value is set to an empty set. For now, we don't bother with these issues.
Nested Class Summary | |
---|---|
protected class |
HashMultiMap.ValueSet
|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface common.MultiMap |
---|
MultiMap.EmptyMultiMap |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
protected boolean |
maintainOrder
|
protected java.util.HashMap |
map
|
Fields inherited from interface common.MultiMap |
---|
EMPTY_MULTI_MAP |
Constructor Summary | |
---|---|
HashMultiMap()
Creates a new, empty HashMultiMap. |
|
HashMultiMap(boolean maintainOrder)
Creates a new, empty HashMultiMap. |
|
HashMultiMap(MultiMap orig)
Creates a new HashMultiMap that is equal to the given MultiMap. |
Method Summary | |
---|---|
boolean |
add(java.lang.Object key,
java.lang.Object value)
Adds the given value to the set associated with the given key. |
boolean |
addAll(java.lang.Object key,
java.util.Set values)
Adds all elements of the given set to the set associated with the given key. |
void |
clear()
|
java.lang.Object |
clone()
Returns a shallow copy of this multi-map. |
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
protected java.util.Set |
copySet(java.util.Set orig)
|
protected java.util.Set |
emptySet()
|
java.util.Set |
entrySet()
|
boolean |
equals(java.lang.Object o)
|
java.lang.Object |
get(java.lang.Object key)
Returns the set associated with the given key. |
int |
hashCode()
|
java.util.Set |
keySet()
|
protected java.util.Set |
newSet()
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the given key with the given value, which must be a Set. |
java.lang.Object |
remove(java.lang.Object key)
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
Removes the given value from the set associated with the given key. |
boolean |
removeAll(java.lang.Object key,
java.util.Set values)
Removes all elements of the given set from the set associated with the given key. |
int |
size()
|
Methods inherited from class java.util.AbstractMap |
---|
isEmpty, putAll, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
isEmpty, putAll, values |
Field Detail |
---|
protected java.util.HashMap map
protected boolean maintainOrder
Constructor Detail |
---|
public HashMultiMap()
public HashMultiMap(boolean maintainOrder)
maintainOrder
is true, then this instance uses a LinkedHashMap and LinkedHashSets
so that the iteration orders for keys, and for elements of value
sets, are predictable.
public HashMultiMap(MultiMap orig)
Method Detail |
---|
public int size()
size
in interface java.util.Map
size
in class java.util.AbstractMap
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
containsKey
in class java.util.AbstractMap
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
containsValue
in class java.util.AbstractMap
public java.lang.Object get(java.lang.Object key)
MultiMap
put
method is called or if all the values for the
given key are removed.
get
in interface MultiMap
get
in interface java.util.Map
get
in class java.util.AbstractMap
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
MultiMap
put
in interface MultiMap
put
in interface java.util.Map
put
in class java.util.AbstractMap
public boolean add(java.lang.Object key, java.lang.Object value)
MultiMap
add
in interface MultiMap
public boolean addAll(java.lang.Object key, java.util.Set values)
MultiMap
addAll
in interface MultiMap
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.AbstractMap
public boolean remove(java.lang.Object key, java.lang.Object value)
MultiMap
remove
in interface MultiMap
public boolean removeAll(java.lang.Object key, java.util.Set values)
MultiMap
removeAll
in interface MultiMap
public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public java.util.Set keySet()
keySet
in interface java.util.Map
keySet
in class java.util.AbstractMap
public boolean equals(java.lang.Object o)
equals
in interface java.util.Map
equals
in class java.util.AbstractMap
public int hashCode()
hashCode
in interface java.util.Map
hashCode
in class java.util.AbstractMap
public java.lang.Object clone()
clone
in class java.util.AbstractMap
protected java.util.Set emptySet()
protected java.util.Set newSet()
protected java.util.Set copySet(java.util.Set orig)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |