@Test public void iterateOverMapEntries() { HazelcastClient hClient = getHazelcastClient(); IMap<String, String> map = hClient.getMap("iterateOverMapEntries"); map.put("1", "A"); map.put("2", "B"); map.put("3", "C"); Set<Entry<String, String>> entrySet = map.entrySet(); assertEquals(3, entrySet.size()); Set<String> keySet = map.keySet(); for (Entry<String, String> entry : entrySet) { assertTrue(keySet.contains(entry.getKey())); assertEquals(entry.getValue(), map.get(entry.getKey())); } Iterator<Entry<String, String>> it = entrySet.iterator(); for (String key : keySet) { MapEntry mapEntry = map.getMapEntry(key); assertEquals(1, mapEntry.getHits()); } while (it.hasNext()) { it.next(); it.remove(); } assertTrue(map.isEmpty()); }
@Override public Iterator iterator() { final Iterator i = _map.keySet().iterator(); final ILookup l = this; return new Iterator() { @Override public boolean hasNext() { return i.hasNext(); } @Override public Object next() { Object k = i.next(); return new clojure.lang.MapEntry(k, l.valAt(k, null)); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
@Override public boolean containsKey(Object k) { return _map.keySet().contains(k); }
@Override public int count() { return _map.keySet().size(); }