Add Miscellaneous#getMapValue method

This commit is contained in:
JeremyStar™ 2024-06-11 16:35:26 +02:00
parent acbfd6b189
commit c369b164a5
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

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