Map to transform objects that are added.
The Map put methods and Map.Entry setValue method are affected by this class. Thus objects must be removed or searched for using their transformed form. For example, if the transformation converts Strings to Integers, you must use the Integer form to remove objects.
Note that TransformedMap is not synchronized and is not
thread-safe. If you wish to use this map from multiple threads
concurrently, you must use appropriate synchronization. The simplest approach
is to wrap this map using java..
This class may throw exceptions when accessed by concurrent threads without
synchronization.
The "put" and "get" type constraints of this class are mutually independent;
contrast with org. which,
by virtue of its implementing Map<K, V>, must be constructed in such
a way that its read and write parameters are generalized to a common (super-)type.
In practice this would often mean >Object, Object>, defeating
much of the usefulness of having parameterized types.
On the downside, this class is not drop-in compatible with java.
but is intended to be worked with either directly or by Put and
Get generalizations.
org.apache.commons.collections4.SplitMapUtils#readableMap(org.apache.commons.collections4.Get) , org.apache.commons.collections4.SplitMapUtils#writableMap(Put)
| Modifier and Type | Field and Description |
|---|---|
| private final Transformer | keyTransformer
The transformer to use for the key |
| private static final long | serialVersionUID
Serialization version |
| private final Transformer | valueTransformer
The transformer to use for the value |
| Access | Constructor and Description |
|---|---|
| protected | TransformedSplitMap(final Map<K, V>
the map to decorate, must not be null map, final Transformer<? super J, ? extends K> the transformer to use for key conversion, must not be null keyTransformer, final Transformer<? super U, ? extends V> the transformer to use for value conversion, must not be null valueTransformer)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| protected V | Returns: the transformed valuethe value to transform value)Override to transform the value when using |
| public void | |
| public V | put(final J
key with which the specified value is to be associated key, final U value to be associated with the specified key value)Implements org. |
| public void | putAll(final Map<? extends J, ? extends U>
mappings to be stored in this map mapToCopy)Implements org. |
| private void | |
| public static < the input key type J, the output key type K, the input value type U, the output value type V> TransformedSplitMap | Returns: a new transformed mapthe map to decorate, must not be null map, final Transformer<? super J, ? extends K> the transformer to use for key conversion, must not be null keyTransformer, final Transformer<? super U, ? extends V> the transformer to use for value conversion, must not be null valueTransformer)Factory method to create a transforming map. |
| protected K | |
| protected Map | Returns: the transformed objectthe map to transform map)Transforms a map. |
| protected V | Returns: the transformed objectthe object to transform object)Transforms a value. |
| private void |
| keyTransformer | back to summary |
|---|---|
| private final Transformer<? super J, ? extends K> keyTransformer The transformer to use for the key | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version | |
| valueTransformer | back to summary |
|---|---|
| private final Transformer<? super U, ? extends V> valueTransformer The transformer to use for the value | |
| TransformedSplitMap | back to summary |
|---|---|
| protected TransformedSplitMap(final Map<K, V> map, final Transformer<? super J, ? extends K> keyTransformer, final Transformer<? super U, ? extends V> valueTransformer) Constructor that wraps (not copies). If there are any elements already in the collection being decorated, they are NOT transformed.
| |
| checkSetValue | back to summary |
|---|---|
| protected V checkSetValue(final U value) Override to transform the value when using
| |
| clear | back to summary |
|---|---|
| public void clear() Implements org.
| |
| put | back to summary |
|---|---|
| public V put(final J key, final U value) Implements org. Doc from org. Note that the return type is Object, rather than V as in the Map interface. See the class Javadoc for further info.
| |
| putAll | back to summary |
|---|---|
| public void putAll(final Map<? extends J, ? extends U> mapToCopy) Implements org.
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Read the map in using a custom routine.
| |
| transformingMap | back to summary |
|---|---|
| public static <J, K, U, V> TransformedSplitMap Factory method to create a transforming map. If there are any elements already in the map being decorated, they are NOT transformed.
| |
| transformKey | back to summary |
|---|---|
| protected K transformKey(final J object) Transforms a key. The transformer itself may throw an exception if necessary.
| |
| transformMap | back to summary |
|---|---|
| protected Map Transforms a map. The transformer itself may throw an exception if necessary.
| |
| transformValue | back to summary |
|---|---|
| protected V transformValue(final U object) Transforms a value. The transformer itself may throw an exception if necessary.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Write the map out using a custom routine.
| |