Skip to content

Commit

Permalink
getOptional in MapUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Feb 24, 2024
1 parent d3049bb commit cde74bb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hscore-common/src/main/java/me/hsgamer/hscore/common/MapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public static <K, V> V getIfFound(Map<K, V> map, K... key) {
return getIfFoundOrDefault(map, null, key);
}

/**
* Get the value given the key from the map
*
* @param map the map
* @param key the key
* @param <K> the key type
* @param <V> the value type
*
* @return the value, or empty optional if not found
*/
@SafeVarargs
public static <K, V> Optional<V> getOptional(Map<K, V> map, K... key) {
return Optional.ofNullable(getIfFound(map, key));
}

/**
* Check if the map contains any of the keys
*
Expand Down

0 comments on commit cde74bb

Please sign in to comment.