net.sf.molae.pipe.hash
Class ListBackedMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by net.sf.molae.pipe.genimpl.KeySetBasedMap<K,V>
          extended by net.sf.molae.pipe.hash.ListBackedMap<K,V>
All Implemented Interfaces:
Map<K,V>

public final class ListBackedMap<K,V>
extends KeySetBasedMap<K,V>

This class implements the map interface with a list implementation. Prerequisite for this implementation is that

More formally: Be K the set of keys, then

∀ k1, k2 ∈ K k1 ≠ k2 &there4 h(k1) ≠ h(k2)

For a good implementation the key set should not have big gaps and the maximum key value should not be too big. Null values are allowed. Null keys are not allowed.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
ListBackedMap(List<K> universe)
          Constructs a new ListBackedMap.
ListBackedMap(List<K> universe, List<V> values)
          Constructs a new ListBackedMap.
ListBackedMap(Set<K> universe)
          Constructs a new ListBackedMap.
 
Method Summary
 V get(Object key)
          Returns the value to which this map maps the specified key.
 Set<K> keySet()
          Returns a set view of the keys contained in this map.
static
<V> Map<Integer,V>
listAsMap(List<V> base)
          Returns a map that maps integers to the list entry at the corresponding position in the base list.
 V put(K key, V value)
           
 V remove(Object key)
          Removes the mapping for this key from this map if present (optional operation).
 
Methods inherited from class net.sf.molae.pipe.genimpl.KeySetBasedMap
clear, containsKey, entrySet, size
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListBackedMap

public ListBackedMap(List<K> universe,
                     List<V> values)
Constructs a new ListBackedMap.

Parameters:
universe - a collection containing all possible keys
values - values of the map

ListBackedMap

public ListBackedMap(List<K> universe)
Constructs a new ListBackedMap.

Parameters:
universe - a collection containing all possible keys
Throws:
NullPointerException - if the specified object is null

ListBackedMap

public ListBackedMap(Set<K> universe)
Constructs a new ListBackedMap.

Parameters:
universe - a collection containing all possible keys
Throws:
NullPointerException - if the specified object is null
Method Detail

listAsMap

public static <V> Map<Integer,V> listAsMap(List<V> base)
Returns a map that maps integers to the list entry at the corresponding position in the base list.

Parameters:
base - the base list.
Returns:
a map that maps integers to the list entry at the corresponding position in the base list.

get

public V get(Object key)
Description copied from class: KeySetBasedMap
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.

Specified by:
get in interface Map<K,V>
Specified by:
get in class KeySetBasedMap<K,V>
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key.

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class AbstractMap<K,V>

remove

public V remove(Object key)
Description copied from class: KeySetBasedMap
Removes the mapping for this key from this map if present (optional operation).

This implementation removes the specified key from the keySet().

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class KeySetBasedMap<K,V>
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no entry for key. (A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.)

keySet

public Set<K> keySet()
Description copied from class: KeySetBasedMap
Returns a set view of the keys contained in this map.

Specified by:
keySet in interface Map<K,V>
Specified by:
keySet in class KeySetBasedMap<K,V>
Returns:
a set view of the keys contained in this map.