@Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIfMapperSuppliedToGetOrAddIsNull() throws Exception { Map<Integer, String> input = Literals.mapBuilderWithKeyValuePair(1, "one") .andKeyValuePair(2, "two") .andKeyValuePair(3, "three") .build(HashMap.class); Mapper<? super Integer, ? extends String> mapper = null; Maps.getOrAdd(input, 5, mapper); }
public static <U, V> V getOrAdd(Map<U, V> map, U key, UnaryFunction<? super U, ? extends V> mapper) { if (map.containsKey(key)) { return map.get(key); } else { V newValue = mapper.call(key); map.put(key, newValue); return newValue; } }
Maps { public static <U, V> V getOrAdd(Map<U, V> map, U key, UnaryFunction<? super U, ? extends V> mapper) { if (map.containsKey(key)) { return map.get(key); } else { V newValue = mapper.call(key); map.put(key, newValue); return newValue; } } }
Maps { public static <U, V> V getOrAdd(Map<U, V> map, U key, UnaryFunction<? super U, ? extends V> mapper) { if (map.containsKey(key)) { return map.get(key); } else { V newValue = mapper.call(key); map.put(key, newValue); return newValue; } } private  Maps(); }
Maps { public static <U, V> V getOrAdd(Map<U, V> map, U key, UnaryFunction<? super U, ? extends V> mapper) { if (map.containsKey(key)) { return map.get(key); } else { V newValue = mapper.call(key); map.put(key, newValue); return newValue; } } private  Maps(); static V getOrAdd(Map<U, V> map, U key, UnaryFunction<? super U, ? extends V> mapper); static V getOrAdd(Map<U, V> map, U key, final NullaryFunction<? extends V> factory); static Mapper<? super Map<K, V>, Set<Map.Entry<K, V>>> toEntrySet(); }
Maps { public static <U, V> V getOrAdd(Map<U, V> map, U key, UnaryFunction<? super U, ? extends V> mapper) { if (map.containsKey(key)) { return map.get(key); } else { V newValue = mapper.call(key); map.put(key, newValue); return newValue; } } private  Maps(); static V getOrAdd(Map<U, V> map, U key, UnaryFunction<? super U, ? extends V> mapper); static V getOrAdd(Map<U, V> map, U key, final NullaryFunction<? extends V> factory); static Mapper<? super Map<K, V>, Set<Map.Entry<K, V>>> toEntrySet();  }