net.sf.molae.pipe.genimpl
Class KeySetBasedMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by net.sf.molae.pipe.genimpl.KeySetBasedMap<K,V>
All Implemented Interfaces:
Map<K,V>
Direct Known Subclasses:
CubeAsMap, ElementwiseMap, KeySetIteratorBasedMap, ListBackedMap

public abstract class KeySetBasedMap<K,V>
extends AbstractMap<K,V>

Base class for maps that are defined by a key set and a mapping that defines the key for each value. Inheriting classes must implement keySet() and get(Object). To implement a modifiable map, the programmer must additionally override this class's put(Object,Object) method (which otherwise throws an UnsupportedOperationException), and the iterator returned by keySet().iterator() must additionally implement its remove method.


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
KeySetBasedMap()
           
 
Method Summary
 void clear()
          Removes all mappings from this map (optional operation).
 boolean containsKey(Object key)
          Returns true if this map contains a mapping for the specified key.
 Set<Map.Entry<K,V>> entrySet()
          Returns a set view of the mappings contained in this map.
abstract  V get(Object key)
          Returns the value to which this map maps the specified key.
abstract  Set<K> keySet()
          Returns a set view of the keys contained in this map.
 V remove(Object key)
          Removes the mapping for this key from this map if present (optional operation).
 int size()
          Returns the number of mappings in this map.
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, put, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeySetBasedMap

public KeySetBasedMap()
Method Detail

entrySet

public Set<Map.Entry<K,V>> entrySet()
Returns a set view of the mappings contained in this map. This implementation returns a transformed collection based on the key set and a transformer that maps keys to map entries.

Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>
Returns:
a set view of the mappings contained in this map.

size

public int size()
Returns the number of mappings in this map. This implementation returns the size of the keySet.

Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>
Returns:
the number of mappings in this map

containsKey

public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key. This implementation calls keySet().contains(key).

Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>
Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.

get

public abstract V get(Object key)
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>
Overrides:
get in class AbstractMap<K,V>
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key.
Throws:
ClassCastException - if the specified key is of an inappropriate type for this map.
NullPointerException - if the key is null and this map does not not permit null keys.

remove

public V remove(Object key)
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 AbstractMap<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.)
Throws:
UnsupportedOperationException - if the remove operation is not supported by the key set.

clear

public void clear()
Removes all mappings from this map (optional operation). This implementation calls keySet().clear().

Specified by:
clear in interface Map<K,V>
Overrides:
clear in class AbstractMap<K,V>
Throws:
UnsupportedOperationException - clear is not supported by this map.

keySet

public abstract Set<K> keySet()
Returns a set view of the keys contained in this map.

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