You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2021/10/05 09:44:08 UTC
[brooklyn-server] 01/03: another transforming convenience for the
MutableMap
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 6c7a22f149fbfd9273c58e3e0b5c027377cb5aa6
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Tue Oct 5 10:36:24 2021 +0100
another transforming convenience for the MutableMap
---
.../java/org/apache/brooklyn/util/collections/MutableMap.java | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableMap.java b/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableMap.java
index 280caa2..f6ae6b4 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableMap.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableMap.java
@@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.function.BiFunction;
import java.util.function.Function;
import javax.annotation.Nullable;
@@ -125,6 +126,15 @@ public class MutableMap<K,V> extends LinkedHashMap<K,V> {
return result;
}
+ /** creates a copy of a map, transforming the values */
+ public static <K,V1,V2> MutableMap<K,V2> copyOf(@Nullable Map<? extends K, ? extends V1> orig, BiFunction<K,V1,V2> transform) {
+ MutableMap<K,V2> result = new MutableMap<>();
+ if (orig!=null) {
+ orig.forEach( (k,v) -> result.put(k, transform.apply(k, v)) );
+ }
+ return result;
+ }
+
public MutableMap() {}
@SuppressWarnings("unchecked")
public MutableMap(@SuppressWarnings("rawtypes") Map source) { super(source); }