### Question:
MapPM extends AbstractPM implements IMapPM<K, V> { public Iterator<K> keyiterator() { return new Iterator<K>() { int next = 0; int last = -1; public boolean hasNext() { return next < entries.size(); } public K next() { K result = entries.getKey(next); last = next; next++; return result; } public void remove() { removeAt(last); next = last; last = -1; } }; } MapPM(); Sorter getSorter(); void setSorter(Sorter sorter); boolean isRevalidateElementsOnChangeEnabled(); void setRevalidateElementsOnChangeEnabled(boolean enabled); void revalidateElements(); boolean isEmpty(); void clear(); V put(K key, V newElement); V put(K key, V newElement, int toIndex); void swap(int indexA, int indexB); void swap(V elemA, V elemB); void reverse(); void sortBy(boolean ascending, Path... paths); void sortBy(Collection<SortKey> newSortKeys); void sortBy(SortKey... newSortKeys); Collection<SortKey> getSortKeys(); int size(); Collection<V> getAll(int startIndex, int endIndex); Collection<V> getAll(int[] indices); V getAt(int index); V get(K key); V removeAt(int index); V removeKey(K key); boolean remove(V elem); boolean removeAll(Collection<? extends V> col); Collection<V> toCollection(); Map<K, V> toMap(); Object[] toArray(); Set<K> keySet(); boolean containsKey(K key); boolean contains(V element); int indexOfKey(K key); int indexOf(V element); int[] indicesOfKeys(Collection<K> keys); int[] indicesOf(Collection elements); K getKey(V element); K getKey(int index); List<K> getKeys(int beginIndex, int endIndex); Set<K> getKeys(int[] indices); Set<K> getKeys(Collection<?> col); SelectedKeys<K> getSelectedKeys(); Selection<V> getSelection(); void addListListener(ListListener l); void removeListListener(ListListener l); Iterator<V> iterator(); ListIterator<V> listIterator(final int index); Iterator<K> keyiterator(); Collection<V> removeAllKeys(Set<K> keySet); Collection<V> retainAllKeys(Set<K> keySet); Collection<V> removeAllIndices(int[] indices); void putAll(Map<K, V> aMap); void putAll(Collection<Entry<K, V>> aEntries); void setAll(Map<K, V> newMap);  }### Answer:
@Test public void keyiterator() { MapPM<Integer, DummyPM> map = new MapPM<Integer, DummyPM>(); final int NUM = 10; populate(map, NUM); Iterator<Integer> it = map.keyiterator(); for (int i = 0; i < NUM; ++i) { assertTrue("it.hasNext()", it.hasNext()); assertEquals("it.next()", map.getKey(i), it.next()); } assertFalse("it.hasNext()", it.hasNext()); try { it.next(); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { } }