|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<K,V>
org.clapper.util.misc.MultiValueMap<K,V>
public class MultiValueMap<K,V>
MultivalueMap implements a hash table that permits multiple values per key. It's very similar to the MultiValueMap class provided by the Jakarta Commons Collections API, except that this class uses Java 5 generics.
Any value placed into a MultivalueMap must implement java.lang.Comparable.
| Nested Class Summary | |
|---|---|
static interface |
MultiValueMap.ValuesCollectionAllocator<V>
Used to allocate a new Collection for the values associated with a key. |
| 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 java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
MultiValueMap()
Constructs a new, empty map with a default capacity and load factor. |
|
MultiValueMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity and the default load factor. |
|
MultiValueMap(int initialCapacity,
float loadFactor)
Constructs a new, empty map with the specified initial capacity and the specified load factor. |
|
MultiValueMap(int initialCapacity,
float loadFactor,
MultiValueMap.ValuesCollectionAllocator<V> valuesCollectionAllocator)
Constructs a new, empty map with the specified initial capacity and the specified load factor. |
|
MultiValueMap(MultiValueMap.ValuesCollectionAllocator<V> valuesCollectionAllocator)
Constructs a new, empty map with a default capacity and load factor. |
|
MultiValueMap(MultiValueMap<K,V> otherMap)
Construct a new map from the contents of an existing map. |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all mappings from this map. |
java.lang.Object |
clone()
Returns a shallow copy of this MultivalueMap instance. |
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains at least one value for the specified key. |
boolean |
containsKeyValue(K key,
V value)
Returns true if this map contains the specified value for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value. |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns an unmodifiable Set view of the mappings contained in this map. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this map for equality. |
V |
get(java.lang.Object key)
Synonym for getFirstValueForKey(K), required by the Map
interface. |
java.util.Collection<V> |
getCollection(K key)
Returns an unmodifiable Collection containing all values associated with the the specified key. |
V |
getFirstValueForKey(K key)
Returns the first value in the set of values associated with a key. |
java.util.Collection<V> |
getValuesForKey(K key)
Return an unmodifiable Collection of all the values for a specific key. |
int |
getValuesForKey(K key,
java.util.Collection<V> values)
Copy all the values for a specific key into a caller-supplied Collection. |
int |
hashCode()
Returns the hash code value for this map. |
boolean |
isEmpty()
Determine whether the map is empty. |
java.util.Set<K> |
keySet()
Returns a Set containing all the keys in this map. |
V |
put(K key,
V value)
Associates the specified value with the specified key in this map. |
void |
putAll(K key,
java.util.Collection<V> values)
Assocates all the objects in a Collection with a key. |
void |
putAll(java.util.Map<? extends K,? extends V> fromMap)
Copies all of the mappings from the specified Map to this map. |
void |
putAll(MultiValueMap<K,V> fromMap)
Copies all of the mappings from the specified MultivalueMap to this map. |
java.util.Collection<V> |
remove(K key)
Removes all mappings for a key from this map, if present. |
boolean |
remove(K key,
V value)
Removes a single value from the set of values associated with a key. |
int |
size()
Returns the number of key-value mappings in this map. |
int |
totalValuesForKey(K key)
Gets the total number of values mapped to a specific key. |
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this map. |
| Methods inherited from class java.util.AbstractMap |
|---|
remove, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MultiValueMap()
public MultiValueMap(MultiValueMap.ValuesCollectionAllocator<V> valuesCollectionAllocator)
valuesCollectionAllocator - object to use to allocate collections
of values for a key.
public MultiValueMap(int initialCapacity,
float loadFactor)
initialCapacity - the initial capacity of the MaploadFactor - the load factor
java.lang.IllegalArgumentException - if the initial capacity is negative,
or if the load factor is nonpostive.
public MultiValueMap(int initialCapacity,
float loadFactor,
MultiValueMap.ValuesCollectionAllocator<V> valuesCollectionAllocator)
initialCapacity - the initial capacityloadFactor - the load factorvaluesCollectionAllocator - object to use to allocate collections
of values for a key.
java.lang.IllegalArgumentException - if the initial capacity is negative,
or if the load factor is nonpostive.public MultiValueMap(int initialCapacity)
initialCapacity - the initial capacity
java.lang.IllegalArgumentException - if the initial capacity is negative,
or if the load factor is nonpostive.public MultiValueMap(MultiValueMap<K,V> otherMap)
otherMap - the map to clone| Method Detail |
|---|
public void clear()
clear in interface java.util.Map<K,V>clear in class java.util.AbstractMap<K,V>
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class java.util.AbstractMap<K,V>java.lang.CloneNotSupportedException - never, but it's part of the signaturepublic boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<K,V>containsKey in class java.util.AbstractMap<K,V>key - key whose presence in this map is to be tested
java.lang.ClassCastException - if the key is of an inappropriate type for
this map.
java.lang.NullPointerException - if the key is null and this map
does not not permit null keys.totalValuesForKey(K)public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<K,V>containsValue in class java.util.AbstractMap<K,V>value - value whose presence in this map is to be tested.
public boolean containsKeyValue(K key,
V value)
key - the keyvalue - the value
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet in interface java.util.Map<K,V>entrySet in class java.util.AbstractMap<K,V>keySet(),
values()public boolean equals(java.lang.Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a MultivalueMap and the two maps represent the same mappings. maps t1 and t2 represent the same mappings if t1.entrySet().equals(t2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.
Warning:: Because this method must compare the actual values stored in the map, and the values in a file, this method can be quite slow.
equals in interface java.util.Map<K,V>equals in class java.util.AbstractMap<K,V>o - object to be compared for equality with this map.
public java.util.Collection<V> getCollection(K key)
Returns an unmodifiable Collection containing all values associated with the the specified key. Returns null if the map contains no mapping for this key.
key - key whose associated collection of values is to be returned.
java.lang.ClassCastException - if the key is of an inappropriate type for
this map.
java.lang.NullPointerException - if the key is null and this map
does not not permit null keys.containsKey(java.lang.Object),
getFirstValueForKey(K)public V get(java.lang.Object key)
getFirstValueForKey(K), required by the Map
interface.
get in interface java.util.Map<K,V>get in class java.util.AbstractMap<K,V>key - the key
public V getFirstValueForKey(K key)
Returns the first value in the set of values associated with a key. This method is especially useful when you know that there is only a single value associated with the key. Note that "first" does not mean "first value ever associated with the key." Instead, it means "first value in the sorted list of values for the key."
key - key whose associated value is to be returned.
java.lang.NullPointerException - if the key is null and this map
does not not permit null keys.containsKey(java.lang.Object),
get(java.lang.Object),
totalValuesForKey(K)public int hashCode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two maps t1 and t2, as required by the general contract of Object.hashCode.
hashCode in interface java.util.Map<K,V>hashCode in class java.util.AbstractMap<K,V>equals(Object)public boolean isEmpty()
isEmpty in interface java.util.Map<K,V>isEmpty in class java.util.AbstractMap<K,V>public java.util.Set<K> keySet()
The set is backed by the map, so changes to the map are reflected in the set. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. Neither the set nor its associated iterator supports any of the set-modification methods (e.g., add(), remove(), etc). If you attempt to call any of those methods, the called method will throw an UnsupportedOperationException.
keySet in interface java.util.Map<K,V>keySet in class java.util.AbstractMap<K,V>getValuesForKey(K),
values()
public V put(K key,
V value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, this value is added to the list of values associated with the key. This map class does not permit a null value to be stored.
put in interface java.util.Map<K,V>put in class java.util.AbstractMap<K,V>key - key with which the specified value is to be associated.value - value to be associated with the specified key.
java.lang.ClassCastException - if the class of the specified key or
value prevents it from being stored
in this map.
java.lang.IllegalArgumentException - if some aspect of this key or value
prevents it from being stored in this
map.
java.lang.NullPointerException - the specified key or value is
null.public void putAll(java.util.Map<? extends K,? extends V> fromMap)
Copies all of the mappings from the specified Map to this map. These mappings will be added to any mappings that this map had for any of the keys currently in the specified map.
putAll in interface java.util.Map<K,V>putAll in class java.util.AbstractMap<K,V>fromMap - Mappings to be stored in this map.
java.lang.ClassCastException - if the class of a key or value in the
specified map prevents it from being
stored in this map.
java.lang.IllegalArgumentException - some aspect of a key or value in the
specified map prevents it from being
stored in this map.
java.lang.NullPointerException - the specified key or value is
null.public void putAll(MultiValueMap<K,V> fromMap)
Copies all of the mappings from the specified MultivalueMap to this map. These mappings will be added to any mappings that this map had for any of the keys currently in the specified map.
fromMap - Mappings to be stored in this map.
java.lang.ClassCastException - if the class of a key or value in the
specified map prevents it from being
stored in this map.
java.lang.IllegalArgumentException - some aspect of a key or value in the
specified map prevents it from being
stored in this map.
java.lang.NullPointerException - the specified key or value is
null.
public void putAll(K key,
java.util.Collection<V> values)
for (Iterator it = values.iterator(); it.hasNext(); )
map.put (key, it.next());
key - the keyvalues - the collection of values to associate with the keypublic java.util.Collection<V> remove(K key)
Removes all mappings for a key from this map, if present.
key - key whose mappings are to be removed from the map.
public boolean remove(K key,
V value)
key - the keyvalue - the value to find and remove
public int size()
Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
size in interface java.util.Map<K,V>size in class java.util.AbstractMap<K,V>public int totalValuesForKey(K key)
key - the key to test
java.lang.NullPointerException - if the key is null and this map
does not not permit null keys.getValuesForKey(K)public java.util.Collection<V> values()
Returns a collection view of the values contained in this map. The returned collection is a "thin" view of the values contained in this map. If a value is associated with more than one key (as determined by the value's equals() method), it will only appear once in the returned Collection. The values are sorted (via their compareTo() methods) in the returned Collection.
Warning: Unlike the SDK's Map class, the returned Collection is not backed by this map; instead, it represents a snapshot of the values in the map. Subsequent changes to this map object are not reflected in the returned Collection.
values in interface java.util.Map<K,V>values in class java.util.AbstractMap<K,V>keySet(),
getValuesForKey(K)public java.util.Collection<V> getValuesForKey(K key)
key - The key
java.lang.NullPointerException - if the key is null and this map
does not not permit null keys.keySet(),
totalValuesForKey(K),
values()
public int getValuesForKey(K key,
java.util.Collection<V> values)
key - The keyvalues - The Collection to receive the values
java.lang.NullPointerException - if the key is null and this map
does not not permit null keys.keySet(),
totalValuesForKey(K),
values()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||