SafeIterableMap implements Iterable<Map.Entry<K, V>> { public V putIfAbsent(@NonNull K key, @NonNull V v) { Entry<K, V> entry = get(key); if (entry != null) { return entry.mValue; } put(key, v); return null; }  V putIfAbsent(@NonNull K key, @NonNull V v); V remove(@NonNull K key); int size(); @NonNull @Override Iterator<Map.Entry<K, V>> iterator(); Iterator<Map.Entry<K, V>> descendingIterator(); IteratorWithAdditions iteratorWithAdditions(); Map.Entry<K, V> eldest(); Map.Entry<K, V> newest(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testAddExisted() { SafeIterableMap<Integer, Integer> map = from(1, 2, 3, 4).to(10, 20, 261, 40); assertThat(map.putIfAbsent(3, 239), is(261)); assertThat(map, is(from(1, 2, 3, 4).to(10, 20, 261, 40))); }
@Test public void testAdditionDuringIteration() { SafeIterableMap<Integer, Boolean> map = mapOf(1, 2, 3, 4); int[] expected = new int[]{1, 2, 3, 4}; int index = 0; for (Entry<Integer, Boolean> entry : map) { assertThat(entry.getKey(), is(expected[index++])); if (index == 1) { map.putIfAbsent(5, true); } } }