SafeIterableMap implements Iterable<Map.Entry<K, V>> { public Iterator<Map.Entry<K, V>> descendingIterator() { DescendingIterator<K, V> iterator = new DescendingIterator<>(mEnd, mStart); mIterators.put(iterator, false); return iterator; }  V putIfAbsent(@NonNull K key, @NonNull V v); V remove(@NonNull K key); int size(); @NonNull @Override Iterator<Map.Entry<K, V>> iterator(); Iterator<Map.Entry<K, V>> descendingIterator(); IteratorWithAdditions iteratorWithAdditions(); Map.Entry<K, V> eldest(); Map.Entry<K, V> newest(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testDescendingIteration() { SafeIterableMap<Integer, Boolean> map = mapOf(1, 2, 3, 4); int[] expected = new int[]{4, 3, 2, 1}; int index = 0; for (Iterator<Entry<Integer, Boolean>> iter = map.descendingIterator(); iter.hasNext(); ) { assertThat(iter.next().getKey(), is(expected[index++])); } assertThat(index, is(4)); }
@Test public void testDescendingIteratorEmpty() { SafeIterableMap<Integer, Boolean> map = mapOf(); Iterator<Entry<Integer, Boolean>> iterator = map.descendingIterator(); assertThat(iterator.hasNext(), is(false)); }