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>

public final class TransformingMap<K,InternalV,ExternalV> extends AbstractMap<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.