ch.javasoft.util.map
Class AbstractMultiValueMap<K,V>

java.lang.Object
  extended by ch.javasoft.util.map.AbstractMultiValueMap<K,V>
All Implemented Interfaces:
MultiValueMap<K,V>
Direct Known Subclasses:
AbstractMutableMultiValueMap, JoinedMultiValueMap, SingleValueMap

public abstract class AbstractMultiValueMap<K,V>
extends Object
implements MultiValueMap<K,V>

Abstract implementation for MultiValueMap for most common methods. For subclasses implementing mutable maps, subclassing AbstractMutableMultiValueMap might be advantageous.


Constructor Summary
AbstractMultiValueMap()
          Constructor for an empty mapping
 
Method Summary
 boolean add(K key, V value)
          Always throws an UnsupportedOperationException
 boolean addAll(K key, Collection<? extends V> values)
          Always throws an UnsupportedOperationException
 boolean addAll(K key, V... values)
          Always throws an UnsupportedOperationException
 boolean addAll(Map<? extends K,? extends V> map)
          Always throws an UnsupportedOperationException
 boolean addAll(MultiValueMap<? extends K,? extends V> mapping)
          Always throws an UnsupportedOperationException
 boolean addAllNested(Map<? extends K,? extends Collection<? extends V>> map)
          Always throws an UnsupportedOperationException
 Map<K,? extends Collection<V>> asCollectionMap()
          Implementation returns a linked hash map containing ArrayList instances.
 Map<K,V> asSingleValueMap()
          Implementation returns a linked hash map containing the single values.
 boolean clear()
          Always throws an UnsupportedOperationException
 boolean contains(Object key)
          Returns true if the value collection is non-empty
 boolean equals(Object obj)
           
 V getFirst(Object key)
          Returns the first value of the value collection, or null if no such value exists
 int hashCode()
           
 MultiValueMap<V,K> invert()
          Implementation returns a new DefaultMultiValueMap instance.
 boolean isEmpty()
          Returns true if this map is empty
 int keySize()
          Returns the number of keys contained in this mapping
 boolean remove(Object key)
          Always throws an UnsupportedOperationException
 boolean remove(Object key, V value)
          Always throws an UnsupportedOperationException
 String toString()
           
 Iterable<V> values()
          Returns an unmodifiable iterator for all values
 int valueSize()
          Returns the number of values contained in this mapping
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.javasoft.util.map.MultiValueMap
contains, count, get, keySet
 

Constructor Detail

AbstractMultiValueMap

public AbstractMultiValueMap()
Constructor for an empty mapping

Method Detail

add

public boolean add(K key,
                   V value)
Always throws an UnsupportedOperationException

Specified by:
add in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
value - the value to add
Returns:
true if this map has changed, which is usually the case. If sets are used as key collections, however, the method could also return false if the given value already existed.

addAll

public boolean addAll(K key,
                      Collection<? extends V> values)
Always throws an UnsupportedOperationException

Specified by:
addAll in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
values - the values to add
Returns:
true if this map has changed as a consequence of this operation

addAll

public boolean addAll(K key,
                      V... values)
Always throws an UnsupportedOperationException

Specified by:
addAll in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
values - the values to add
Returns:
true if this map has changed as a consequence of this operation

addAll

public boolean addAll(Map<? extends K,? extends V> map)
Always throws an UnsupportedOperationException

Specified by:
addAll in interface MultiValueMap<K,V>
Parameters:
map - the map containing key/value-collection entries to add
Returns:
true if this map has changed as a consequence of this operation

addAll

public boolean addAll(MultiValueMap<? extends K,? extends V> mapping)
Always throws an UnsupportedOperationException

Specified by:
addAll in interface MultiValueMap<K,V>
Parameters:
mapping - the mapping containing key/value-collection entries to add
Returns:
true if this map has changed as a consequence of this operation

addAllNested

public boolean addAllNested(Map<? extends K,? extends Collection<? extends V>> map)
Always throws an UnsupportedOperationException

Specified by:
addAllNested in interface MultiValueMap<K,V>
Parameters:
map - the map containing key/value-collection entries to add
Returns:
true if this map has changed as a consequence of this operation

clear

public boolean clear()
Always throws an UnsupportedOperationException

Specified by:
clear in interface MultiValueMap<K,V>
Returns:
true if this mapping has changed as a consequence of this operation

remove

public boolean remove(Object key)
Always throws an UnsupportedOperationException

Specified by:
remove in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
Returns:
true if this map has changed as a consequence of this operation

remove

public boolean remove(Object key,
                      V value)
Always throws an UnsupportedOperationException

Specified by:
remove in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
value - the value to remove
Returns:
true if this map has changed as a consequence of this operation

getFirst

public V getFirst(Object key)
Description copied from interface: MultiValueMap
Returns the first value of the value collection, or null if no such value exists

Specified by:
getFirst in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
Returns:
the first value of the value collection, or null if no such value exists

contains

public boolean contains(Object key)
Description copied from interface: MultiValueMap
Returns true if the value collection is non-empty

Specified by:
contains in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
Returns:
true if at least one value exists in the value collection

asCollectionMap

public Map<K,? extends Collection<V>> asCollectionMap()
Implementation returns a linked hash map containing ArrayList instances.

Changing the returned map does not affect this multi value map.

Specified by:
asCollectionMap in interface MultiValueMap<K,V>
Returns:
a map with key/collection-of-value entries
See Also:
MultiValueMap.asCollectionMap()

asSingleValueMap

public Map<K,V> asSingleValueMap()
Implementation returns a linked hash map containing the single values.

Changing the returned map does not affect this multi value map.

Specified by:
asSingleValueMap in interface MultiValueMap<K,V>
Returns:
a map with key and first associated value
See Also:
MultiValueMap.asSingleValueMap()

invert

public MultiValueMap<V,K> invert()
Implementation returns a new DefaultMultiValueMap instance.

Changing the returned map does not affect this multi value map.

Specified by:
invert in interface MultiValueMap<K,V>
Returns:
the inverted value-key mapping
See Also:
MultiValueMap.invert()

keySize

public int keySize()
Description copied from interface: MultiValueMap
Returns the number of keys contained in this mapping

Specified by:
keySize in interface MultiValueMap<K,V>

valueSize

public int valueSize()
Description copied from interface: MultiValueMap
Returns the number of values contained in this mapping

Specified by:
valueSize in interface MultiValueMap<K,V>
Returns:
the total number of values

isEmpty

public boolean isEmpty()
Description copied from interface: MultiValueMap
Returns true if this map is empty

Specified by:
isEmpty in interface MultiValueMap<K,V>
Returns:
true if this map is empty

values

public Iterable<V> values()
Returns an unmodifiable iterator for all values

Specified by:
values in interface MultiValueMap<K,V>
Returns:
an iterator for all values contained in this mapping
See Also:
MultiValueMap.values()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object