de.unkrig.commons.lang.protocol
Class Mapping<K,V>
java.lang.Object
de.unkrig.commons.lang.protocol.Mapping<K,V>
- Type Parameters:
K - The 'key' typeV - The 'value' type
public abstract class Mapping<K,V>
- extends java.lang.Object
A map that computes a value only when get(Object) is invoked. Consequently, in contrast with Map,
it has no specific size, and thus no Map.entrySet(), Map.keySet() and Map.values() set. Also
the modifying operations (Map.put(Object, Object), Map.putAll(Map), Map.remove(Object),
Map.clear()) are all missing, because a Mapping is not changed by 'putting' key-value-pairs into it.
Actually Map should extend Mapping, but it doesn't - thus there are the asMap() and
Mappings.fromMap(Map) helpers.
The relationship between Mapping and Map is very much like that between Predicate and
Collection.
|
Method Summary |
java.util.Map<K,V> |
asMap()
Returns a proxy Map for a Mapping where all methods declared by Map but not by
Mapping throw an UnsupportedOperationException. |
abstract boolean |
containsKey(java.lang.Object key)
|
abstract V |
get(java.lang.Object key)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Mapping
public Mapping()
containsKey
public abstract boolean containsKey(@Nullable
java.lang.Object key)
- See Also:
Map.containsKey(Object)
get
@Nullable
public abstract V get(@Nullable
java.lang.Object key)
- See Also:
Map.get(Object)
asMap
public final java.util.Map<K,V> asMap()
- Returns a proxy
Map for a Mapping where all methods declared by Map but not by
Mapping throw an UnsupportedOperationException.