From c369b164a56f54e63829b8c2200d814efe3bb522 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 11 Jun 2024 16:35:26 +0200 Subject: [PATCH] Add Miscellaneous#getMapValue method --- .../sosengine/base/utility/Miscellaneous.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/Miscellaneous.java b/base/src/main/java/de/staropensource/sosengine/base/utility/Miscellaneous.java index 51bed51e..05e8de5f 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/Miscellaneous.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/Miscellaneous.java @@ -22,6 +22,10 @@ package de.staropensource.sosengine.base.utility; import org.jetbrains.annotations.NotNull; import java.lang.ref.WeakReference; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * Contains smaller functions that don't fit into other utility classes. @@ -76,4 +80,15 @@ public final class Miscellaneous { runnable.run(); return System.currentTimeMillis() - initTime; } + + /** + * Searches for a value in a {@link Map}. + * + * @param map map to use + * @param value value to search for + * @since 1-alpha0 + */ + public static Set getMapValue(Map map, Object value) { + return map.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), value)).map(Map.Entry::getKey).collect(Collectors.toSet()); + } }