IK
- the inner key type, i.e. the type of the keys contained in the wrapped/inner mapOK
- the outer key type, i.e. the type of keys appearing to be in this mapIV
- the inner value type, i.e. the type of the values contained in the wrapped/inner mapOV
- the outer value type, i.e. the type of values appearing to be in this mappublic final class TransformingMap<IK,OK,IV,OV> extends Object
Map
which decorates another map and transforms the key and value types from the inner types IK
,
IV
to outer types OK
, OV
.
See the package
documentation for general comments on transformation.
This implementation mitigates the type safety problems by using tokens of the inner and the outer types to check
instances against them. This solves some of the critical situations but not all of them. In those other cases
ClassCastException
s might occur when an element can not be transformed by the transformation functions.
Null keys and values are allowed unless the inner map does not accept them. These are handled explicitly and fixed to
the transformation null -> null
. The transforming functions specified during construction neither have to
handle that case nor are they allowed to produce null elements.
If the streams
returned by this map's views are told to
sort
themself, they will do so on the base of the comparator returned by the
inner map view's spliterator (e.g. based on the natural order of IK
or IV
if it has one).
TransformingMap
s are created with a TransformingMapBuilder
.
Modifier and Type | Method and Description |
---|---|
void |
clear() |
OV |
compute(OK key,
BiFunction<? super OK,? super OV,? extends OV> remappingFunction) |
OV |
computeIfAbsent(OK key,
Function<? super OK,? extends OV> mappingFunction) |
OV |
computeIfPresent(OK key,
BiFunction<? super OK,? super OV,? extends OV> remappingFunction) |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<OK,OV>> |
entrySet() |
boolean |
equals(Object object) |
void |
forEach(BiConsumer<? super OK,? super OV> action) |
OV |
get(Object key) |
protected Map<IK,IV> |
getInnerMap() |
OV |
getOrDefault(Object key,
OV defaultValue) |
int |
hashCode() |
boolean |
isEmpty() |
protected boolean |
isInnerKey(Object object)
Checks whether the specified object might be an inner key.
|
protected boolean |
isInnerValue(Object object)
Checks whether the specified object might be an inner value.
|
protected boolean |
isOuterKey(Object object)
Checks whether the specified object might be an outer key.
|
protected boolean |
isOuterValue(Object object)
Checks whether the specified object might be an outer value.
|
protected boolean |
isThisMap(Map<?,?> otherMap)
Indicates whether the specified collection is equivalent to this one.
|
Set<OK> |
keySet() |
OV |
merge(OK key,
OV value,
BiFunction<? super OV,? super OV,? extends OV> remappingFunction) |
OV |
put(OK key,
OV value) |
void |
putAll(Map<? extends OK,? extends OV> outerMap) |
OV |
putIfAbsent(OK key,
OV value) |
OV |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
OV |
replace(OK key,
OV value) |
boolean |
replace(OK key,
OV oldValue,
OV newValue) |
void |
replaceAll(BiFunction<? super OK,? super OV,? extends OV> function) |
int |
size() |
String |
toString() |
protected IK |
transformToInnerKey(OK outerKey)
Transforms the specified key to an instance of the inner key type.
|
protected IV |
transformToInnerValue(OV outerValue)
Transforms the specified value to an instance of the inner value type.
|
protected OK |
transformToOuterKey(IK innerKey)
Transforms the specified key to an instance of the outer key type.
|
protected OV |
transformToOuterValue(IV innerValue)
Transforms the specified value to an instance of the outer value type.
|
Collection<OV> |
values() |
protected Map<IK,IV> getInnerMap()
protected boolean isInnerKey(Object object)
This method does not have to be exact (which might be impossible due to involved generic types) and might produce false positives (but no false negatives).
object
- the object to check; may be nullprotected OK transformToOuterKey(IK innerKey)
It can not be guaranteed that the specified key is really of the inner key type. If not, an exception can be thrown.
innerKey
- the key to transform; may be nullprotected boolean isOuterKey(Object object)
This method does not have to be exact (which might be impossible due to involved generic types) and might produce false positives (but no false negatives).
object
- the object to check; may be nullprotected IK transformToInnerKey(OK outerKey)
It can not be guaranteed that the specified key is really of the outer key type. If not, an exception can be thrown.
outerKey
- the key to transform; may be nullprotected boolean isInnerValue(Object object)
This method does not have to be exact (which might be impossible due to involved generic types) and might produce false positives (but no false negatives).
object
- the object to check; may be nullprotected OV transformToOuterValue(IV innerValue)
It can not be guaranteed that the specified value is really of the inner value type. If not, an exception can be thrown.
innerValue
- the value to transform; may be nullprotected boolean isOuterValue(Object object)
This method does not have to be exact (which might be impossible due to involved generic types) and might produce false positives (but no false negatives).
object
- the object to check; may be nullprotected IV transformToInnerValue(OV outerValue)
It can not be guaranteed that the specified value is really of the outer value type. If not, an exception can be thrown.
outerValue
- the value to transform; may be nullprotected final boolean isThisMap(Map<?,?> otherMap)
AbstractTransformingMap
and wraps the same innerMap
.otherMap
- the Collection
which is compared with this onepublic boolean containsKey(Object key)
containsKey
in interface Map<OK,OV>
public boolean containsValue(Object value)
containsValue
in interface Map<OK,OV>
public OV getOrDefault(Object key, OV defaultValue)
getOrDefault
in interface Map<OK,OV>
public OV putIfAbsent(OK key, OV value)
putIfAbsent
in interface Map<OK,OV>
public void putAll(Map<? extends OK,? extends OV> outerMap)
public OV compute(OK key, BiFunction<? super OK,? super OV,? extends OV> remappingFunction)
public OV computeIfAbsent(OK key, Function<? super OK,? extends OV> mappingFunction)
computeIfAbsent
in interface Map<OK,OV>
public OV computeIfPresent(OK key, BiFunction<? super OK,? super OV,? extends OV> remappingFunction)
computeIfPresent
in interface Map<OK,OV>
public OV merge(OK key, OV value, BiFunction<? super OV,? super OV,? extends OV> remappingFunction)
public boolean replace(OK key, OV oldValue, OV newValue)
public void replaceAll(BiFunction<? super OK,? super OV,? extends OV> function)
replaceAll
in interface Map<OK,OV>
public void forEach(BiConsumer<? super OK,? super OV> action)
public Collection<OV> values()
public final boolean equals(Object object)
public final int hashCode()
This documentation is licensed under CC-BY 4.0, attributed to Nicolai Parlog from CodeFX.