@Test public void shouldSafelyEnumerateEntries() { Iterator<Entry<String, String>> it = map.entrySet().iterator(); assertThat( it.hasNext(), is( true ) ); Entry<String, String> val = it.next(); assertThat( val.getKey(), is( "a" ) ); assertThat( val.getValue(), is( "1" ) ); assertThat( it.hasNext(), is( true ) ); val = it.next(); assertThat( val.getKey(), is( "x" ) ); assertThat( val.getValue(), is( nullValue() ) ); assertThat( it.hasNext(), is( true ) ); val = it.next(); assertThat( val.getKey(), is( "b" ) ); assertThat( val.getValue(), is( "2" ) ); assertThat( it.hasNext(), is( true ) ); val = it.next(); assertThat( val.getKey(), is( "c" ) ); assertThat( val.getValue(), is( "3" ) ); assertThat( it.hasNext(), is( true ) ); val = it.next(); assertThat( val.getKey(), is( "" ) ); assertThat( val.getValue(), is( "" ) ); assertThat( it.hasNext(), is( true ) ); val = it.next(); assertThat( val.getKey(), is( nullValue() ) ); assertThat( val.getValue(), is( "1" ) ); assertThat( it.hasNext(), is( false ) ); }
@Override public Set<Entry<K, V>> entrySet() { Set<Entry<K, V>> entries = new LinkedHashSet<>(); Node<K, V> node = first; while ( node != null ) { entries.add( node ); node = node.next; } return unmodifiableSet( entries ); }
ImmutableMap extends AbstractMap<K, V> { @Override public Set<Entry<K, V>> entrySet() { Set<Entry<K, V>> entries = new LinkedHashSet<>(); Node<K, V> node = first; while ( node != null ) { entries.add( node ); node = node.next; } return unmodifiableSet( entries ); } }
ImmutableMap extends AbstractMap<K, V> { @Override public Set<Entry<K, V>> entrySet() { Set<Entry<K, V>> entries = new LinkedHashSet<>(); Node<K, V> node = first; while ( node != null ) { entries.add( node ); node = node.next; } return unmodifiableSet( entries ); } ImmutableMap( Map<K, V> map ); }
ImmutableMap extends AbstractMap<K, V> { @Override public Set<Entry<K, V>> entrySet() { Set<Entry<K, V>> entries = new LinkedHashSet<>(); Node<K, V> node = first; while ( node != null ) { entries.add( node ); node = node.next; } return unmodifiableSet( entries ); } ImmutableMap( Map<K, V> map ); @Override Set<Entry<K, V>> entrySet(); }
ImmutableMap extends AbstractMap<K, V> { @Override public Set<Entry<K, V>> entrySet() { Set<Entry<K, V>> entries = new LinkedHashSet<>(); Node<K, V> node = first; while ( node != null ) { entries.add( node ); node = node.next; } return unmodifiableSet( entries ); } ImmutableMap( Map<K, V> map ); @Override Set<Entry<K, V>> entrySet();  }