BK
- The type of keys in the backing map.K
- The type of keys in this map.V
- The type of values in both this map and the underlying map.public abstract class DerivedMap<BK,K,V> extends AbstractMap<K,V> implements Serializable
baseToDerived(BK)
and derivedToBase(K)
methods. This set do not supports null
key,
since null
is used when no mapping from base to this
exists. This
class is serializable if the underlying base set is serializable too.
This class is not thread-safe. Synchronizations (if wanted) are user's reponsability.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected Map<BK,V> |
base
The base map whose keys are derived from.
|
Constructor and Description |
---|
DerivedMap(Map<BK,V> base)
Deprecated.
Use
#DerivedMap(Map, Class instead. |
DerivedMap(Map<BK,V> base,
Class<K> keyType)
Creates a new derived map from the specified base map.
|
Modifier and Type | Method and Description |
---|---|
protected abstract K |
baseToDerived(BK key)
Transforms a key from the base map to a key in this map.
|
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 one or more keys to this value. |
protected abstract BK |
derivedToBase(K key)
Transforms a key from this derived map to a key in the base map.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this map.
|
V |
get(Object key)
Returns the value to which this map maps the specified key.
|
boolean |
isEmpty()
Returns
true if this map contains no key-value mappings. |
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 this map.
|
V |
remove(Object key)
Removes the mapping for this key from this map if present.
|
int |
size()
Returns the number of key-value mappings in this map.
|
Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
protected final Map<BK,V> base
baseToDerived(BK)
,
derivedToBase(K)
public DerivedMap(Map<BK,V> base)
#DerivedMap(Map, Class
instead.base
- The base map.protected abstract K baseToDerived(BK key)
null
.key
- A ley from the base map.key
, or null
.protected abstract BK derivedToBase(K key)
key
- A key in this map.public int size()
public boolean isEmpty()
true
if this map contains no key-value mappings.public boolean containsValue(Object value)
true
if this map maps one or more keys to this value. The default
implementation invokes base.containsValue(value)
.containsValue
in interface Map<K,V>
containsValue
in class AbstractMap<K,V>
true
if this map maps one or more keys to this value.public boolean containsKey(Object key)
true
if this map contains a mapping for the specified key. The default
implementation invokes
base.containsKey(derivedToBase(key))
.containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
key
- key whose presence in this map is to be tested.true
if this map contains a mapping for the specified key.public V get(Object key)
base.get(derivedToBase(key))
.public V put(K key, V value) throws UnsupportedOperationException
base.put(derivedToBase(key), value)
.put
in interface Map<K,V>
put
in class AbstractMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.null
if there was no mapping
for key.UnsupportedOperationException
- if the base map doesn't supports the
put
operation.public V remove(Object key) throws UnsupportedOperationException
base.remove(derivedToBase(key))
.remove
in interface Map<K,V>
remove
in class AbstractMap<K,V>
key
- key whose mapping is to be removed from the map.null
if there was no entry
for key.UnsupportedOperationException
- if the base map doesn't supports the
remove
operation.public Collection<V> values()
Copyright © 1996–2019 Geotools. All rights reserved.