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()); + } }