MapUtil { public static void putIfAbsent(Map<String, String> map, String name, String value) { if (map != null && !map.containsKey(name)) { map.put(name, value); } } private  MapUtil(); static void putIfAbsent(Map<String, String> map, String name, String value); static void mergeIfAbsent(Map<String, String> map, Map<String, String> toMerge); static Map<K,V> mergeMaps(Map<K, V> map1, Map<K, V> map2); static void putAllIfNotNull(Map<String, String> ret, Map<String, String> toPut);  }
@Test public void testPutIfAbsent() { Map<String, String> map = createMap("eins", "one"); MapUtil.putIfAbsent(map, "eins", "un"); assertEquals(1,map.size()); assertEquals("one", map.get("eins")); MapUtil.putIfAbsent(map, "zwei", "deux"); assertEquals(2, map.size()); assertEquals("one", map.get("eins")); assertEquals("deux", map.get("zwei")); }