Rename Lang.getOrPut() to computeIfAbsent()

See Map.computeIfAbsent() in java9
This commit is contained in:
yushijinhun
2018-02-18 15:33:58 +08:00
parent d081a6ee92
commit 470045f228
2 changed files with 7 additions and 7 deletions

View File

@@ -28,14 +28,14 @@ public final class Lang {
return map; return map;
} }
public static <K, V> V getOrPut(Map<K, V> map, K key, Supplier<V> defaultValue) { public static <K, V> V computeIfAbsent(Map<K, V> map, K key, Supplier<V> computingFunction) {
V value = map.get(key); V value = map.get(key);
if (value == null) { if (value == null) {
V answer = defaultValue.get(); V newValue = computingFunction.get();
map.put(key, answer); map.put(key, newValue);
return answer; return newValue;
} else }
return value; return value;
} }
public static <E extends Throwable> void throwable(Throwable exception) throws E { public static <E extends Throwable> void throwable(Throwable exception) throws E {

View File

@@ -62,7 +62,7 @@ public final class SimpleMultimap<K, V> {
} }
public Collection<V> get(K key) { public Collection<V> get(K key) {
return Lang.getOrPut(map, key, valuer); return Lang.computeIfAbsent(map, key, valuer);
} }
public void put(K key, V value) { public void put(K key, V value) {