net.sf.molae.pipe.trafo
Class InvertedMap
java.lang.Object
|
+--java.util.AbstractMap
|
+--net.sf.molae.pipe.basic.AbstractMapWithSet
|
+--net.sf.molae.pipe.trafo.EntryTransformedMap
|
+--net.sf.molae.pipe.trafo.InvertedMap
- All Implemented Interfaces:
- Map
- public final class InvertedMap
- extends EntryTransformedMap
A map that exchanges keys and values for each entry.
Before using this class, it must be ensured,
that values are unique in the base map.
Note that this class has a bad performance in general.
Therefore it is recommended to store the result in another map.
- See Also:
MapAsTransformer
|
Constructor Summary |
InvertedMap(Map m)
Constructs an InvertedMap object. |
|
Method Summary |
boolean |
containsKey(Object key)
Returns true if this map contains a mapping for the
specified key. |
boolean |
containsValue(Object value)
Returns true if this map maps a key to
the specified value. |
protected Transformer |
getTransformer()
Returns the underlying transformer. |
static boolean |
isInvertible(Map m)
Checks that no value occurs twice in the specified map. |
Set |
keySet()
Returns a set view of the keys contained in this map. |
Collection |
values()
Returns a collection view of the values contained in this map. |
InvertedMap
public InvertedMap(Map m)
- Constructs an InvertedMap object.
- Parameters:
m - underlying map.- Throws:
NullPointerException - if any of the specified objects is
null.
getTransformer
protected Transformer getTransformer()
- Description copied from class:
EntryTransformedMap
- Returns the underlying transformer.
- Overrides:
getTransformer in class EntryTransformedMap
- Following copied from class:
net.sf.molae.pipe.trafo.EntryTransformedMap
- Returns:
- the underlying transformer
containsKey
public boolean containsKey(Object key)
- Returns
true if this map contains a mapping for the
specified key.
This is the case if the base map contains the specified key as a
value.
- Overrides:
containsKey in class AbstractMap
- Parameters:
key - key whose presence in this map is to be tested.- Returns:
true if this map contains a mapping for the
specified key.
containsValue
public boolean containsValue(Object value)
- Returns
true if this map maps a key to
the specified value.
This is the case if the base map contains the specified value as a
key.
- Overrides:
containsValue in class AbstractMap
- Parameters:
value - value whose presence in this map is to be tested.- Returns:
true if this map maps a key to
the specified value
keySet
public Set keySet()
- Returns a set view of the keys contained in this map.
This is a set representation of the
values() of the
base map.
- Overrides:
keySet in class AbstractMapWithSet
- Returns:
- a set view of the keys contained in this map
values
public Collection values()
- Returns a collection view of the values contained in this map.
This is the
keySet() of the base map.
- Overrides:
values in class AbstractMap
- Returns:
- a collection view of the values contained in this map
isInvertible
public static boolean isInvertible(Map m)
- Checks that no value occurs twice in the specified map.
- Parameters:
m - the map to be examined.- Returns:
- true, iff each value in
m corresponds to a unique
key.