net.sf.molae.pipe.binop
Class ElementwiseMap<K,V,S1,S2>
java.lang.Object
java.util.AbstractMap<K,V>
net.sf.molae.pipe.genimpl.KeySetBasedMap<K,V>
net.sf.molae.pipe.binop.ElementwiseMap<K,V,S1,S2>
- All Implemented Interfaces:
- Map<K,V>
public class ElementwiseMap<K,V,S1,S2>
- extends KeySetBasedMap<K,V>
A map where the value of each mapping is computed from the values of
the two corresponding base mappings.
Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
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
|
newInstance(BinaryFunction<S1,? super S2,V> operation,
Map<K,S1> base1,
Map<? super K,S2> base2)
Constructs an ElementwiseMap from the specified maps and
operation. |
V |
put(K key,
V value)
Associates the specified value with the specified key in this map. |
ElementwiseMap
public ElementwiseMap(BinaryFunction<S1,? super S2,V> operation,
Map<K,S1> base1,
Map<? super K,S2> base2)
- Constructs an ElementwiseMap from the specified maps and
operation.
- Parameters:
operation
- the underlying binary functionbase1
- the map containing the first operands of the underlying
operation.base2
- the map containing the second operands of the underlying
operation.
- Throws:
NullPointerException
- if any argument is null
or if the specified operation has no permuted function.
newInstance
public static <K,V,S1,S2> ElementwiseMap<K,V,S1,S2> newInstance(BinaryFunction<S1,? super S2,V> operation,
Map<K,S1> base1,
Map<? super K,S2> base2)
- Constructs an ElementwiseMap from the specified maps and
operation.
- Parameters:
operation
- the underlying binary functionbase1
- the map containing the first operands of the underlying
operation.base2
- the map containing the second operands of the underlying
operation.
- Throws:
NullPointerException
- if any argument is null
or if the specified operation has no permuted function.- Since:
- 2.0
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)
- Associates the specified value with the specified key in this map.
The value for the first base map is calculated from the specified
value and the value in the second base map and stored in the first map.
- Specified by:
put
in interface Map<K,V>
- Overrides:
put
in class AbstractMap<K,V>
- Parameters:
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
- Returns:
- previous value associated with specified key,
or
null
if there was no mapping for key.
- Throws:
ClassCastException
- The base computation or the first
base map does not accept the specified value.
IllegalArgumentException
- The base computation
does not accept the specified value or
the second base map does not contain the key
or the first base map does not accept the result.
NullPointerException
- The specified value is
null
and the base computation and/or the base map
do not accept null
values.
UnsupportedOperationException
- inverse operation cannot be
computed
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.