V - the generic type of the mapped valuespublic class HierarchyClassMap<V> extends Object implements Map<Class<?>,V>
Map which keys are instances of Class and
values are instances of generic type V.
This classes' value comes from its get(Object) and containsKey(Object)
methods being redefined to support hierarchical lookups. For example, consider types
Dog and RabidDog, such that RabidDog extends Dog. If
the map contains both keys, then the behaviour is the same as in a standard map. However,
if get(Object) is invoked the key Dog but only RabidDog is mapped,
this implementation will still find a value for Dog, since it will recursively traverse
across all entries looking for keys which are assignable from that key. When no value is found,
then the search is retried using the key's superclass. Recursion ends when the Object
class is reached or when no superclass is available (if you searched for Object in the first place)
A consistent behaviour will occur when using the containsKey(Object) method.
This also works when the key is an interface, with the difference that no recursion is performed in that case.
Dog key has a specific
value mapped, it will be preferred over a RabidDog key
get(Object) and containsKey(Object), no other method has been overridden.
Behaviour will be that of the backing map.| Constructor and Description |
|---|
HierarchyClassMap()
Creates a new instance which behaves like a
HashMap |
HierarchyClassMap(Map<Class<?>,V> delegate)
Creates a new instance which wraps the given
delegate,
inheriting its rules. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
V |
compute(Class<?> key,
BiFunction<? super Class<?>,? super V,? extends V> remappingFunction) |
V |
computeIfAbsent(Class<?> key,
Function<? super Class<?>,? extends V> mappingFunction) |
V |
computeIfPresent(Class<?> key,
BiFunction<? super Class<?>,? super V,? extends V> remappingFunction) |
boolean |
containsKey(Object key)
Determines if there's a matching mapping by the rules
described on the class javadoc.
|
boolean |
containsValue(Object value) |
Set<Map.Entry<Class<?>,V>> |
entrySet() |
boolean |
equals(Object o) |
void |
forEach(BiConsumer<? super Class<?>,? super V> action) |
V |
get(Object key)
Fetches a value associated to the given
key
following the rules described on the class javadoc |
V |
getOrDefault(Object key,
V defaultValue) |
int |
hashCode() |
boolean |
isEmpty() |
Set<Class<?>> |
keySet() |
V |
merge(Class<?> key,
V value,
BiFunction<? super V,? super V,? extends V> remappingFunction) |
V |
put(Class<?> key,
V value) |
void |
putAll(Map<? extends Class<?>,? extends V> m) |
V |
putIfAbsent(Class<?> key,
V value) |
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
V |
replace(Class<?> key,
V value) |
boolean |
replace(Class<?> key,
V oldValue,
V newValue) |
void |
replaceAll(BiFunction<? super Class<?>,? super V,? extends V> function) |
int |
size() |
Collection<V> |
values() |
public HierarchyClassMap()
HashMappublic V get(Object key)
key
following the rules described on the class javadocpublic boolean containsKey(Object key)
containsKey in interface Map<Class<?>,V>key - the considered keypublic boolean containsValue(Object value)
containsValue in interface Map<Class<?>,V>public boolean equals(Object o)
public int hashCode()
public V getOrDefault(Object key, V defaultValue)
getOrDefault in interface Map<Class<?>,V>public void forEach(BiConsumer<? super Class<?>,? super V> action)
public void replaceAll(BiFunction<? super Class<?>,? super V,? extends V> function)
replaceAll in interface Map<Class<?>,V>public V putIfAbsent(Class<?> key, V value)
putIfAbsent in interface Map<Class<?>,V>public V computeIfAbsent(Class<?> key, Function<? super Class<?>,? extends V> mappingFunction)
computeIfAbsent in interface Map<Class<?>,V>public V computeIfPresent(Class<?> key, BiFunction<? super Class<?>,? super V,? extends V> remappingFunction)
computeIfPresent in interface Map<Class<?>,V>public V compute(Class<?> key, BiFunction<? super Class<?>,? super V,? extends V> remappingFunction)
Copyright © 2017 MuleSoft, Inc.. All rights reserved.