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

java.lang.Object
  extended by ch.javasoft.util.map.AbstractMultiValueMap<K,V>
      extended by ch.javasoft.util.map.SingleValueMap<K,V>
All Implemented Interfaces:
MultiValueMap<K,V>, Serializable

public class SingleValueMap<K,V>
extends AbstractMultiValueMap<K,V>
implements Serializable

The SingleValueMap is pretty much the same as a Map, but it implements the MultiValueMap interface, e.g. to use normal maps in a join (see JoinedMultiValueMap).

This class does not copy the values of the original java map, but encapsulates the java map.

See Also:
Serialized Form

Constructor Summary
SingleValueMap(Map<K,V> map)
           
 
Method Summary
 Map<K,V> asSingleValueMap()
          Implementation returns the underlying map.
 boolean contains(Object key)
          Returns true if the value collection is non-empty
 boolean contains(Object key, V value)
          Returns true if the value collection contains at least one occurrence of the given value
 int count(Object key)
          Returns the number of values in the value collection
 boolean equals(Object obj)
           
 Collection<V> get(Object key)
          Returns a collection for all values belonging to the specified key, or an empty collection if no such key collection exists yet.
 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 SingleValueMap instance if the mapping from values to keys is unambiguous, and a DefaultMultiValueMap if this is not the case.
 boolean isEmpty()
          Returns true if this map is empty
 Set<K> keySet()
          Returns a set containing all keys.
 int keySize()
          Returns the number of keys contained in this mapping
 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 ch.javasoft.util.map.AbstractMultiValueMap
add, addAll, addAll, addAll, addAll, addAllNested, asCollectionMap, clear, remove, remove
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SingleValueMap

public SingleValueMap(Map<K,V> map)
Method Detail

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>
Overrides:
contains in class AbstractMultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
Returns:
true if at least one value exists in the value collection

count

public int count(Object key)
Description copied from interface: MultiValueMap
Returns the number of values in the value collection

Specified by:
count in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
Returns:
the number of values in the value collection

contains

public boolean contains(Object key,
                        V value)
Description copied from interface: MultiValueMap
Returns true if the value collection contains at least one occurrence of the given value

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

get

public Collection<V> get(Object key)
Description copied from interface: MultiValueMap
Returns a collection for all values belonging to the specified key, or an empty collection if no such key collection exists yet. For existing keys, the returned collection is non-empty.

Specified by:
get in interface MultiValueMap<K,V>
Parameters:
key - the key which identifies the value collection
Returns:
the value collection for the given key, never null, and non-empty for existing keys

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>
Overrides:
getFirst in class AbstractMultiValueMap<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

keySet

public Set<K> keySet()
Description copied from interface: MultiValueMap
Returns a set containing all keys. Each value collection associated with the returned keys is non-empty

Specified by:
keySet in interface MultiValueMap<K,V>
Returns:
the set of keys identifying non-empty value collections

asSingleValueMap

public Map<K,V> asSingleValueMap()
Implementation returns the underlying map.

Changing the returned map also affects this single value map.

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

invert

public MultiValueMap<V,K> invert()
Implementation returns a SingleValueMap instance if the mapping from values to keys is unambiguous, and a DefaultMultiValueMap if this is not the case.

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

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

isEmpty

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

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

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>
Overrides:
keySize in class AbstractMultiValueMap<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>
Overrides:
valueSize in class AbstractMultiValueMap<K,V>
Returns:
the total number of values

values

public Iterable<V> values()
Description copied from class: AbstractMultiValueMap
Returns an unmodifiable iterator for all values

Specified by:
values in interface MultiValueMap<K,V>
Overrides:
values in class AbstractMultiValueMap<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 AbstractMultiValueMap<K,V>

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractMultiValueMap<K,V>

toString

public String toString()
Overrides:
toString in class AbstractMultiValueMap<K,V>