UnionMap extends AbstractMap<K, V> { @Override public V get(Object key) { final V value = first.get(key); return value != null ? value : second.get(key); } UnionMap(Map<K, V> first, Map<K, V> second); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override V remove(Object key); @Override void clear(); @Override Set<Entry<K, V>> entrySet();  }
@Test void testGet() { assertThat(new UnionMap<>(of("1", "a"), of("2", "b"))).containsEntry("1", "a"); assertThat(new UnionMap<>(of("1", "a"), of("2", "b"))).containsEntry("2", "b"); assertThat(new UnionMap<>(of("1", "a"), of("1", "b"))).containsEntry("1", "a"); }