Skip to content

Commit

Permalink
code cleanup; remove now obsolete LangUtil.map() method
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Dec 8, 2023
1 parent d64e082 commit 91bd540
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
23 changes: 4 additions & 19 deletions utility/src/main/java/com/dua3/utility/lang/LangUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ public static String trimWithByteOrderMark(String s) {
* @param items the key-value pairs to put into the map
*/
@SafeVarargs
public static <K, V> void putAllIfAbsent(Map<? super K, ? super V> map, Pair<K, V>... items) {
Arrays.stream(items).forEach(item -> map.putIfAbsent(item.first(), item.second()));
public static <K, V> void putAllIfAbsent(Map<? super K, ? super V> map, Map.Entry<K, V>... items) {
Arrays.stream(items).forEach(item -> map.putIfAbsent(item.getKey(), item.getValue()));
}

/**
Expand All @@ -373,23 +373,8 @@ public static <K, V> void putAllIfAbsent(Map<? super K, ? super V> map, Pair<K,
* @param items the key-value pairs to put into the map
*/
@SafeVarargs
public static <K, V> void putAll(Map<? super K, ? super V> map, Pair<K, V>... items) {
Arrays.stream(items).forEach(item -> map.put(item.first(), item.second()));
}

/**
* Create an unmodifiable map from key-value pairs.
*
* @param <K> the key type
* @param <V> the value type
* @param items the key-value pairs to put into the map
* @return unmodifiable map
*/
@SafeVarargs
public static <K, V> Map<K, V> map(Pair<K, V>... items) {
Map<K, V> map = new HashMap<>();
putAllIfAbsent(map, items);
return Collections.unmodifiableMap(map);
public static <K, V> void putAll(Map<? super K, ? super V> map, Map.Entry<K, V>... items) {
Arrays.stream(items).forEach(item -> map.put(item.getKey(), item.getValue()));
}

/**
Expand Down
12 changes: 0 additions & 12 deletions utility/src/test/java/com/dua3/utility/lang/LangUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,6 @@ void putAll() {
assertEquals(expected, map);
}

@Test
void map() {
Map<Integer, String> map = LangUtil.map(Pair.of(1, "a"), Pair.of(3, "c"), Pair.of(2, "b"));

Map<Integer, String> expected = new HashMap<>();
expected.put(1, "a");
expected.put(2, "b");
expected.put(3, "c");

assertEquals(expected, map);
}

@SuppressWarnings("ZeroLengthArrayAllocation")
@Test
void testEquals() {
Expand Down

0 comments on commit 91bd540

Please sign in to comment.