public final class Mapper<K,V> extends Object implements IMapper<K,V>
IMapper implementation backed by a Map.
A DefaultValue can be set that is returned for keys that don't have an explicit value set.
It is legal to use null as key (provided K is a reference or nullable type), which can be assigned a
value just like other keys.
| Constructor and Description |
|---|
Mapper()
Creates an instance using a
HashMap as the backing store. |
Mapper(Map<K,V> map)
Creates an instance using the provided
Map as the backing store. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Calls
HashMap.clear() on the backing implementation. |
V |
getDefaultValue()
Gets the default value to return if no specific value has been set for a given key.
|
Iterable<Map.Entry<K,V>> |
getEntries()
Gets an enumerable over all entries in this (dictionary based) mapper.
|
V |
getItem(K key)
Finds the associated value for the given key in the mapping or (re-)associates the given key with the value provided,
removing previous associations.
|
V |
getValue(K key)
Gets the value for a given key in the mapping.
|
void |
removeValue(K key) |
void |
setDefaultValue(V value)
Sets the default value to return if no specific value has been set for a given key.
|
void |
setItem(K key,
V value)
Finds the associated value for the given key in the mapping or (re-)associates the given key with the value provided,
removing previous associations.
|
void |
setValue(K key,
V value)
Sets the value for a given key in the mapping.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfromConstant, fromFunctionpublic Mapper()
HashMap as the backing store.
The value for the null item is stored separately.
public final void clear()
HashMap.clear() on the backing implementation.public final V getDefaultValue()
setDefaultValue(java.lang.Object)public final Iterable<Map.Entry<K,V>> getEntries()
public final V getItem(K key)
In order to remove an association the removeValue(Object) method should be preferred over calling this method
using a default value. This implementation simply delegates to setValue(Object, Object) and getValue(Object)
respectively.
key - The key to use as the index.removeValue(Object),
getValue(Object),
setValue(Object, Object),
setItem(Object, Object)public final V getValue(K key)
IMapperSetting a value for an already existing key overwrites the previous value.
It depends on the specific implementation of the mapper whether a mapping can be removed. If an implementation provides
a way to remove a mapping, that should be preferred over setting a null value. For example, Mapper
provides the removeValue(java.lang.Object) method.
getValue in interface IMapper<K,V>key - The key of the mapping.IMapper.setValue(java.lang.Object, java.lang.Object)public final void removeValue(K key)
public final void setDefaultValue(V value)
value - The DefaultValue to set.getDefaultValue()public final void setItem(K key, V value)
In order to remove an association the removeValue(Object) method should be preferred over calling this method
using a default value. This implementation simply delegates to setValue(Object, Object) and getValue(Object)
respectively.
key - The key to use as the index.value - The value.removeValue(Object),
getValue(Object),
setValue(Object, Object),
getItem(Object)public final void setValue(K key, V value)
IMapperSetting a value for an already existing key overwrites the previous value.
It depends on the specific implementation of the mapper whether a mapping can be removed. If an implementation provides
a way to remove a mapping, that should be preferred over setting a null value. For example, Mapper
provides the removeValue(java.lang.Object) method.
setValue in interface IMapper<K,V>key - The key of the mapping.value - The value.IMapper.getValue(java.lang.Object)