K
- the type of keys maintained by this mapV
- the type of mapped valuespublic final class EqualityTransformingMap<K,V> extends Object
equals
and
hashCode
which are used for the map's keys.
It does so by storing the entries in an inner map and providing a transforming view on them. See the
package
documentation for general comments on that. Note that instances
of EqualityTransformingMap
s are created with a builder
.
This implementation mitigates the type safety problems by optionally using a token of the (outer) key type to check
instances against them. This solves some of the critical situations but not all of them. In those other cases
ClassCastException
s might still occur.
By default the inner map will be a new HashMap
but the another map can be provided to the builder. Such
instances must be empty and not be referenced anywhere else. The implementations of equals
and
hashCode
are provided as functions to the builder - see there for details.
The transformations used by this map preserve object identity of outer keys and values. This means if keys and values are added to this map, an iteration over it will return the same instances.
EqualityTransformingMap
s are created with a EqualityTransformingCollectionBuilder
.
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<org.codefx.libfx.collection.transform.EqHash<K>,V> |
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 org.codefx.libfx.collection.transform.EqHash<K> |
transformToInnerKey(K outerKey)
Transforms the specified key to an instance of the inner key type.
|
protected V |
transformToInnerValue(V outerValue)
Transforms the specified value to an instance of the inner value type.
|
protected K |
transformToOuterKey(org.codefx.libfx.collection.transform.EqHash<K> innerKey)
Transforms the specified key to an instance of the outer key type.
|
protected V |
transformToOuterValue(V innerValue)
Transforms the specified value to an instance of the outer value type.
|
Collection<OV> |
values() |
protected Map<org.codefx.libfx.collection.transform.EqHash<K>,V> 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 K transformToOuterKey(org.codefx.libfx.collection.transform.EqHash<K> innerKey) throws ClassCastException
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 nullClassCastException
- if the specified key is not of the correct typeprotected 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 org.codefx.libfx.collection.transform.EqHash<K> transformToInnerKey(K outerKey) throws ClassCastException
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 nullClassCastException
- if the specified key is not of the correct typeprotected 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 V transformToOuterValue(V innerValue) throws ClassCastException
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 nullClassCastException
- if the specified value is not of the correct typeprotected 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 V transformToInnerValue(V outerValue) throws ClassCastException
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 nullClassCastException
- if the specified value is not of the correct typeprotected 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.