Skip to content

Commit

Permalink
use common MapUtils in MapUtil
Browse files Browse the repository at this point in the history
???
  • Loading branch information
HSGamer committed Mar 18, 2023
1 parent 1af6ce1 commit 5bd305c
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/main/java/me/hsgamer/bettergui/util/MapUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.hsgamer.bettergui.util;

import me.hsgamer.hscore.common.MapUtils;

import java.util.Map;
import java.util.Optional;

Expand All @@ -24,12 +26,7 @@ private MapUtil() {
*/
@SafeVarargs
public static <K, V> V getIfFoundOrDefault(Map<K, V> map, V defaultValue, K... key) {
for (K k : key) {
if (map.containsKey(k)) {
return map.get(k);
}
}
return defaultValue;
return MapUtils.getIfFoundOrDefault(map, defaultValue, key);
}

/**
Expand All @@ -44,7 +41,7 @@ public static <K, V> V getIfFoundOrDefault(Map<K, V> map, V defaultValue, K... k
*/
@SafeVarargs
public static <K, V> V getIfFound(Map<K, V> map, K... key) {
return getIfFoundOrDefault(map, null, key);
return MapUtils.getIfFound(map, key);
}

/**
Expand All @@ -58,12 +55,7 @@ public static <K, V> V getIfFound(Map<K, V> map, K... key) {
*/
@SafeVarargs
public static <K> boolean containsAnyKey(Map<K, ?> map, K... key) {
for (K k : key) {
if (map.containsKey(k)) {
return true;
}
}
return false;
return MapUtils.containsAnyKey(map, key);
}

/**
Expand All @@ -74,10 +66,6 @@ public static <K> boolean containsAnyKey(Map<K, ?> map, K... key) {
* @return the map
*/
public static Optional<Map<String, Object>> castOptionalStringObjectMap(Object object) {
if (object instanceof Map) {
// noinspection unchecked
return Optional.of((Map<String, Object>) object);
}
return Optional.empty();
return MapUtils.castOptionalStringObjectMap(object);
}
}

0 comments on commit 5bd305c

Please sign in to comment.