Add Miscellaneous#getMapValue method
This commit is contained in:
parent
acbfd6b189
commit
c369b164a5
1 changed files with 15 additions and 0 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue