@Test public void testIterable(){ MyIterableHashMap<Integer, String> map = new MyIterableHashMap<>(); map.put(0, "a"); map.put(1, "b"); map.put(2, "c"); String buffer = ""; for(String value : map){ buffer += value; } assertEquals(3, buffer.length()); assertTrue(buffer.contains("a")); assertTrue(buffer.contains("b")); assertTrue(buffer.contains("c")); }
@Override public void put(K key, V value) { modificationCounter++; int i = index(key); if(data[i] == null){ data[i] = new ArrayList<>(); } List<Entry> list = data[i]; for(int j=0; j<list.size(); j++){ Entry entry = list.get(j); if(key.equals(entry.key)){ entry.value = value; return; } } list.add(new Entry(key, value)); }
MyIterableHashMap implements MyHashMap<K,V>, Iterable<V> { @Override public void put(K key, V value) { modificationCounter++; int i = index(key); if(data[i] == null){ data[i] = new ArrayList<>(); } List<Entry> list = data[i]; for(int j=0; j<list.size(); j++){ Entry entry = list.get(j); if(key.equals(entry.key)){ entry.value = value; return; } } list.add(new Entry(key, value)); } }
MyIterableHashMap implements MyHashMap<K,V>, Iterable<V> { @Override public void put(K key, V value) { modificationCounter++; int i = index(key); if(data[i] == null){ data[i] = new ArrayList<>(); } List<Entry> list = data[i]; for(int j=0; j<list.size(); j++){ Entry entry = list.get(j); if(key.equals(entry.key)){ entry.value = value; return; } } list.add(new Entry(key, value)); } MyIterableHashMap();  MyIterableHashMap(int capacity); }
MyIterableHashMap implements MyHashMap<K,V>, Iterable<V> { @Override public void put(K key, V value) { modificationCounter++; int i = index(key); if(data[i] == null){ data[i] = new ArrayList<>(); } List<Entry> list = data[i]; for(int j=0; j<list.size(); j++){ Entry entry = list.get(j); if(key.equals(entry.key)){ entry.value = value; return; } } list.add(new Entry(key, value)); } MyIterableHashMap();  MyIterableHashMap(int capacity); @Override Iterator<V> iterator(); @Override void put(K key, V value); @Override void delete(K key); @Override V get(K key); @Override int size(); }
MyIterableHashMap implements MyHashMap<K,V>, Iterable<V> { @Override public void put(K key, V value) { modificationCounter++; int i = index(key); if(data[i] == null){ data[i] = new ArrayList<>(); } List<Entry> list = data[i]; for(int j=0; j<list.size(); j++){ Entry entry = list.get(j); if(key.equals(entry.key)){ entry.value = value; return; } } list.add(new Entry(key, value)); } MyIterableHashMap();  MyIterableHashMap(int capacity); @Override Iterator<V> iterator(); @Override void put(K key, V value); @Override void delete(K key); @Override V get(K key); @Override int size();  }