diff --git a/utility/src/main/java/com/dua3/utility/lang/LangUtil.java b/utility/src/main/java/com/dua3/utility/lang/LangUtil.java index 573c7bee..a7af0167 100644 --- a/utility/src/main/java/com/dua3/utility/lang/LangUtil.java +++ b/utility/src/main/java/com/dua3/utility/lang/LangUtil.java @@ -360,8 +360,8 @@ public static String trimWithByteOrderMark(String s) { * @param items the key-value pairs to put into the map */ @SafeVarargs - public static void putAllIfAbsent(Map map, Pair... items) { - Arrays.stream(items).forEach(item -> map.putIfAbsent(item.first(), item.second())); + public static void putAllIfAbsent(Map map, Map.Entry... items) { + Arrays.stream(items).forEach(item -> map.putIfAbsent(item.getKey(), item.getValue())); } /** @@ -373,23 +373,8 @@ public static void putAllIfAbsent(Map map, Pair void putAll(Map map, Pair... items) { - Arrays.stream(items).forEach(item -> map.put(item.first(), item.second())); - } - - /** - * Create an unmodifiable map from key-value pairs. - * - * @param the key type - * @param the value type - * @param items the key-value pairs to put into the map - * @return unmodifiable map - */ - @SafeVarargs - public static Map map(Pair... items) { - Map map = new HashMap<>(); - putAllIfAbsent(map, items); - return Collections.unmodifiableMap(map); + public static void putAll(Map map, Map.Entry... items) { + Arrays.stream(items).forEach(item -> map.put(item.getKey(), item.getValue())); } /** diff --git a/utility/src/test/java/com/dua3/utility/lang/LangUtilTest.java b/utility/src/test/java/com/dua3/utility/lang/LangUtilTest.java index 44bbd8e7..0b5045c5 100644 --- a/utility/src/test/java/com/dua3/utility/lang/LangUtilTest.java +++ b/utility/src/test/java/com/dua3/utility/lang/LangUtilTest.java @@ -161,18 +161,6 @@ void putAll() { assertEquals(expected, map); } - @Test - void map() { - Map map = LangUtil.map(Pair.of(1, "a"), Pair.of(3, "c"), Pair.of(2, "b")); - - Map expected = new HashMap<>(); - expected.put(1, "a"); - expected.put(2, "b"); - expected.put(3, "c"); - - assertEquals(expected, map); - } - @SuppressWarnings("ZeroLengthArrayAllocation") @Test void testEquals() {