Deprecated
since 4.1, use MultiValuedMap instead
A MultiMap is a Map with slightly different semantics.
Putting a value into the map will add the value to a Collection at that key.
Getting a value will return a Collection, holding all the values put to that key.
This implementation is a decorator, allowing any Map implementation to be used as the base.
In addition, this implementation allows the type of collection used
for the values to be controlled. By default, an ArrayList
is used, however a Class to instantiate may be specified,
or a factory that returns a Collection instance.
Note that MultiValueMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. This class may throw exceptions when accessed by concurrent threads without synchronization.
| Modifier and Type | Class and Description |
|---|---|
| private static class | MultiValueMap.ReflectionFactory<T extends Collection
Inner class that provides a simple reflection factory. |
| private class | MultiValueMap.Values
Inner class that provides the values view. |
| private class | MultiValueMap.ValuesIterator
Inner class that provides the values iterator. |
| Modifier and Type | Field and Description |
|---|---|
| private final Factory | collectionFactory
The factory for creating value collections. |
| private static final long | serialVersionUID
Serialization version |
| private transient Collection | valuesView
The cached values. |
| Access | Constructor and Description |
|---|---|
| public | MultiValueMap()
Creates a MultiValueMap based on a |
| protected < the collection class type C extends Collection | MultiValueMap(final Map<K, ? super C>
the map to decorate map, final Factory<C> the collection factory which must return a Collection instance collectionFactory)Creates a MultiValueMap which decorates the given |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Overrides org. Implements java. |
| public boolean | Returns: true if the map contains the valuethe value to search for value)Overrides org. Implements org. |
| public boolean | Returns: true if the map contains the valuethe key to search for key, final Object the value to search for value)Checks whether the collection at the specified key contains the value. |
| protected Collection | Returns: the new collectionthe collection size that is about to be added size)Creates a new instance of the map value Collection container using the factory. |
| public Set | entrySet()
Overrides org. Implements java. Set view of the mappings contained in this map.
|
| public Collection | Returns: the collection mapped to the key, null if no mappingthe key to retrieve key)Gets the collection mapped to the specified key. |
| public Iterator | |
| public Iterator | Returns: the iterator of all mappings in this mapGets an iterator for all mappings stored in this |
| public static < the key type K, the value type V> MultiValueMap | Returns: a new multi-value mapthe map to wrap map)
Deprecated
as a consequence of
Creates a map which wraps the given map and
maps keys to ArrayLists.
MultiValueMap being deprecated.
|
| public static < the key type K, the value type V, the collection class type C extends Collection | Returns: a new multi-value mapthe map to wrap map, final Class<C> the type of the collection class collectionClass)
Deprecated
as a consequence of
Creates a map which decorates the given MultiValueMap being deprecated.
map and
maps keys to collections of type collectionClass.
|
| public static < the key type K, the value type V, the collection class type C extends Collection | Returns: a new multi-value mapthe map to decorate map, final Factory<C> the collection factory (must return a Collection object). collectionFactory)
Deprecated
as a consequence of
Creates a map which decorates the given MultiValueMap being deprecated.
map and
creates the value collections using the supplied collectionFactory.
|
| public Object | Returns: the value added if the map changed and null if the map did not changethe key to store against key, final Object the value to add to the collection at the key value)Overrides org. Implements org. |
| public void | putAll(final Map<? extends K, ?>
the map to copy (either a normal or multi map) map)Overrides org. Implements java. |
| public boolean | Returns: true if this map changedthe key to store against key, final Collection<V> the values to add to the collection at the key, null ignored values)Adds a collection of values to the collection associated with the specified key. |
| private void | |
| public boolean | Returns: true if the mapping was removed, false otherwisethe key to remove from key, final Object the value to remove value)Implements org. |
| public int | |
| public int | Returns: the total size of the map counting all valuesGets the total size of the map by counting all the values. |
| public Collection | Returns: a collection view of the values contained in this mapOverrides org. Implements org. |
| private void |
| collectionFactory | back to summary |
|---|---|
| private final Factory<? extends Collection<V>> collectionFactory The factory for creating value collections. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version | |
| valuesView | back to summary |
|---|---|
| private transient Collection<V> valuesView The cached values. | |
| MultiValueMap | back to summary |
|---|---|
| public MultiValueMap() Creates a MultiValueMap based on a
| |
| MultiValueMap | back to summary |
|---|---|
| protected <C extends Collection Creates a MultiValueMap which decorates the given
| |
| clear | back to summary |
|---|---|
| public void clear() Overrides org. Implements java. Clear the map.
| |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(final Object value) Overrides org. Implements org. Checks whether the map contains the value specified. This checks all collections against all keys for the value, and thus could be slow.
| |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(final Object key, final Object value) Checks whether the collection at the specified key contains the value. | |
| createCollection | back to summary |
|---|---|
| protected Collection Creates a new instance of the map value Collection container using the factory. This method can be overridden to perform your own processing instead of using the factory.
| |
| entrySet | back to summary |
|---|---|
| public Set Overrides org. Implements java. Doc from java. Returns a Note the returned Entry objects will contain as value a | |
| getCollection | back to summary |
|---|---|
| public Collection Gets the collection mapped to the specified key.
This method is a convenience method to typecast the result of
| |
| iterator | back to summary |
|---|---|
| public Iterator Gets an iterator for the collection mapped to the specified key. | |
| iterator | back to summary |
|---|---|
| public Iterator Gets an iterator for all mappings stored in this The iterator will return multiple Entry objects with the same key if there are multiple values mapped to this key. Note calling | |
| multiValueMap | back to summary |
|---|---|
| public static <K, V> MultiValueMap Deprecated as a consequence of Creates a map which wraps the given map and maps keys to ArrayLists.
| |
| multiValueMap | back to summary |
|---|---|
| public static <K, V, C extends Collection Deprecated as a consequence of Creates a map which decorates the given
| |
| multiValueMap | back to summary |
|---|---|
| public static <K, V, C extends Collection Deprecated as a consequence of Creates a map which decorates the given
| |
| put | back to summary |
|---|---|
| public Object put(final K key, final Object value) Overrides org. Implements org. Adds the value to the collection associated with the specified key.
Unlike a normal
| |
| putAll | back to summary |
|---|---|
| public void putAll(final Map<? extends K, ?> map) Overrides org. Implements java. Override superclass to ensure that MultiMap instances are correctly handled.
If you call this method with a normal map, each entry is
added using
| |
| putAll | back to summary |
|---|---|
| public boolean putAll(final K key, final Collection<V> values) Adds a collection of values to the collection associated with the specified key.
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Read the map in using a custom routine.
| |
| removeMapping | back to summary |
|---|---|
| public boolean removeMapping(final Object key, final Object value) Implements org. Removes a specific value from map. The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected.
If the last value for a key is removed, | |
| size | back to summary |
|---|---|
| public int size(final Object key) Gets the size of the collection mapped to the specified key.
| |
| totalSize | back to summary |
|---|---|
| public int totalSize() Gets the total size of the map by counting all the values.
| |
| values | back to summary |
|---|---|
| public Collection Overrides org. Implements org. Gets a collection containing all the values in the map. This returns a collection containing the combination of values from all keys.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Write the map out using a custom routine.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Class | |
| private static final long | serialVersionUID
Serialization version |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public T | |
| private void |
| clazz | back to summary |
|---|---|
| private final Class<T> clazz | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version | |
| ReflectionFactory | back to summary |
|---|---|
| public ReflectionFactory(final Class<T> clazz) | |
| create | back to summary |
|---|---|
| public T create() Implements org. Doc from org. Create a new object.
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream is) throws IOException, ClassNotFoundException | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Overrides java. Implements java. |
| public Iterator | iterator()
Implements abstract java. Implements java. |
| public int | size()
Implements abstract java. Implements java. |
| Values | back to summary |
|---|---|
| private Values() | |
| clear | back to summary |
|---|---|
| public void clear() Overrides java. Implements java. Doc from java. Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements contained in this collection. | |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this collection. If this collection
contains more than
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Iterator | |
| private final Object | |
| private final Collection |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public V | |
| public void | remove()
Overrides default java. |
| iterator | back to summary |
|---|---|
| private final Iterator<V> iterator | |
| key | back to summary |
|---|---|
| private final Object key | |
| values | back to summary |
|---|---|
| private final Collection<V> values | |
| ValuesIterator | back to summary |
|---|---|
| public ValuesIterator(final Object key) | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public V next() Implements java. Doc from java. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |