Class TransformingMap<K,InternalV,ExternalV>
java.lang.Object
java.util.AbstractMap<K,ExternalV>
com.electronwill.nightconfig.core.utils.TransformingMap<K,InternalV,ExternalV>
- All Implemented Interfaces:
Map<K,ExternalV>
A TransformingMap contains an internal
Map<K, InternalV> values, and exposes the
features of a Map<K, ExternalV> applying transformations to the values.
The transformations are applied "just in time", that is, the values are converted only when they are used, not during the construction of the TransformingMap.
For instance, if you have a Map<String, String> and you want to convert its values
"just in time" to integers, you use a TransformingMap<String, String, Integer>.
To get one, you create these three functions:
- one that converts a String to an Integer: that's the parse transformation. It converts an Integer read from the internal map to a String.
- one that converts an Integer to a String: that's the write transformation. It converts a String given to the TransformingMap to an Integer.
- one that converts an Object to another Object: that's the search transformation. It is used
(mainly) by the
containsKey(Object)method of the TransformingMap. If its argument is an Integer then it should convert it to an String in the same way as the write transformation. Otherwise, it is free to try to convert it to a String if possible, or not to.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()computeIfAbsent(K key, Function<? super K, ? extends ExternalV> mappingFunction) computeIfPresent(K key, BiFunction<? super K, ? super ExternalV, ? extends ExternalV> remappingFunction) booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()voidforEach(BiConsumer<? super K, ? super ExternalV> action) getOrDefault(Object key, ExternalV defaultValue) booleanisEmpty()keySet()merge(K key, ExternalV value, BiFunction<? super ExternalV, ? super ExternalV, ? extends ExternalV> remappingFunction) voidputIfAbsent(K key, ExternalV value) booleanbooleanvoidreplaceAll(BiFunction<? super K, ? super ExternalV, ? extends ExternalV> function) intsize()values()Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, toString
-
Constructor Details
-
TransformingMap
public TransformingMap(Map<K, InternalV> map, Function<? super InternalV, ? extends ExternalV> readTransformation, Function<? super ExternalV, ? extends InternalV> writeTransformation, Function<Object, Object> searchTransformation) Create a new TransformingMap.- Parameters:
map- the internal map to usereadTransformation- the parse transformation (see javadoc of the class)writeTransformation- the write transformation (see javadoc of the class)searchTransformation- the search transformation (see javadoc of the class)
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,InternalV> - Overrides:
containsKeyin classAbstractMap<K,ExternalV>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,InternalV> - Overrides:
containsValuein classAbstractMap<K,ExternalV>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
getOrDefault
-
forEach
-
replaceAll
-
putIfAbsent
-
remove
-
replace
-
replace
-
computeIfAbsent
-
computeIfPresent
-
compute
-
merge
-