Package io.blt.util
Class Ctr
java.lang.Object
io.blt.util.Ctr
Static utility methods for operating on implementations of
Collection and Map i.e. Containers.
For methods that return a modification of a passed container, the result will be of the same type if possible.
This is accomplished using Obj.newInstanceOf(Object) and its limitations apply.
-
Method Summary
Modifier and TypeMethodDescriptiontransformValues(Map<K, V> source, ThrowingFunction<? super V, R, E> transform)
-
Method Details
-
transformValues
public static <K,V, Map<K,R, E extends Throwable> R> transformValues(Map<K, V> source, ThrowingFunction<? super V, throws ER, E> transform) Returns a newMapcontaining the entries ofsourcewithtransformapplied to the values.If possible, the result is of the same type as the passed
e.g.sourcemap.var scores = Map.of("Louis", 95, "Greg", 92, "Mike", 71, "Phil", 86); var grades = Ctr.transformValues(scores, score -> { if (score >= 90) { return "A"; } else if (score >= 80) { return "B"; } else if (score >= 70) { return "C"; } else if (score >= 60) { return "D"; } else { return "F"; } }); // grades = Map.of("Louis", "A", "Greg", "A", "Mike", "C", "Phil", "B")- Type Parameters:
K-mapkey typeV-mapvalue typeR- returned map value typeE- type oftransformthrowable- Parameters:
source-Mapwhose values should be transformedtransform- value transformation function- Returns:
- a new
Mapcontaining the entries ofsourcewithtransformapplied to the values - Throws:
E extends Throwable- See Also:
-