net.sf.molae.pipe.filter
Class KeyFilteredMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by net.sf.molae.pipe.basic.AbstractMapWithSet<K,V>
          extended by net.sf.molae.pipe.filter.KeyFilteredMap<K,V>
All Implemented Interfaces:
Map<K,V>

public final class KeyFilteredMap<K,V>
extends AbstractMapWithSet<K,V>

Implements a map that contains all entries of a base map of which the key matches a filter condition.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.molae.pipe.basic.AbstractMapWithSet
AbstractMapWithSet.EntrySet
 
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
KeyFilteredMap(Map<K,V> base, TypedPredicate<? super K> filter)
          Constructs a filtered map from the specified map and filter.
 
Method Summary
protected  void assertRange(K key)
          Checks if the specified object fulfils the filter predicate of this class.
 boolean containsKey(Object key)
          Returns true if the base map contains a mapping for the specified key and the key matches the underlying filter.
 V get(Object key)
          Returns the value to which the base map maps the specified key if the key matches the underlying filter.
protected  Iterator<Map.Entry<K,V>> getEntrySetIterator()
          Returns the iterator of the entry set.
 Set<K> keySet()
          Returns a set view of the keys contained in this map.
 V put(K key, V value)
          Associates the specified value with the specified key in the base map if the key matches the underlying filter.
 V remove(Object key)
          Removes the mapping for this key from this map if present and the key matches the underlying filter.
 
Methods inherited from class net.sf.molae.pipe.basic.AbstractMapWithSet
entrySet, size
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, isEmpty, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeyFilteredMap

public KeyFilteredMap(Map<K,V> base,
                      TypedPredicate<? super K> filter)
Constructs a filtered map from the specified map and filter.

Parameters:
base - the underlying map
filter - predicate that determines which keys belong to the map
Throws:
NullPointerException - if the specified objects are null.
Method Detail

getEntrySetIterator

protected Iterator<Map.Entry<K,V>> getEntrySetIterator()
Description copied from class: AbstractMapWithSet
Returns the iterator of the entry set.

Specified by:
getEntrySetIterator in class AbstractMapWithSet<K,V>
Returns:
the iterator of the entry set.

assertRange

protected void assertRange(K key)
Checks if the specified object fulfils the filter predicate of this class.

Parameters:
key - parameter of another method of this class.
Throws:
IllegalArgumentException - if the specified object does not fulfil the filter predicate of this class.

containsKey

public boolean containsKey(Object key)
Returns true if the base map contains a mapping for the specified key and the key matches the underlying filter.

Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>
Throws:
ClassCastException - depending on the base map
NullPointerException - depending on the base map

get

public V get(Object key)
Returns the value to which the base map maps the specified key if the key matches the underlying filter.

Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>
Throws:
ClassCastException - depending on the base map
NullPointerException - depending on the base map

put

public V put(K key,
             V value)
Associates the specified value with the specified key in the base map if the key matches the underlying filter.

Specified by:
put in interface Map<K,V>
Overrides:
put in class AbstractMap<K,V>
Throws:
UnsupportedOperationException - depending on the base map
ClassCastException - depending on the base map
IllegalArgumentException - depending on the base map
NullPointerException - depending on the base map

remove

public V remove(Object key)
Removes the mapping for this key from this map if present and the key matches the underlying filter.

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class AbstractMap<K,V>
Throws:
UnsupportedOperationException - depending on the base map

keySet

public Set<K> keySet()
Description copied from class: AbstractMapWithSet
Returns a set view of the keys contained in this map. This implementation returns a typesafe version of the key set from AbstractMap

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