@Test public void sortedEntriesTest() { SortedMap<Integer, String> sorted_map = new SortedMap<>(dataSet, cmp); String prev_val = null; for (Map.Entry<Integer, String> entry: sorted_map.entrySet()) { if (prev_val != null) { Assert.assertTrue(entry.getValue().compareTo(prev_val) >= 0); } prev_val = entry.getValue(); } }
@Override public Set<Entry<K, V>> entrySet() { return new AbstractSet() { @Override public Iterator iterator() { final Iterator<K> it = iterableKeys.iterator(); return new Iterator() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Object next() { K key = it.next(); return new AbstractMap.SimpleImmutableEntry<>(key, index.get(key)); } @Override public void remove() { throw new UnsupportedOperationException("Read only."); } }; } @Override public int size() { return index.size(); } }; }
SortedMap implements Map<K, V> { @Override public Set<Entry<K, V>> entrySet() { return new AbstractSet() { @Override public Iterator iterator() { final Iterator<K> it = iterableKeys.iterator(); return new Iterator() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Object next() { K key = it.next(); return new AbstractMap.SimpleImmutableEntry<>(key, index.get(key)); } @Override public void remove() { throw new UnsupportedOperationException("Read only."); } }; } @Override public int size() { return index.size(); } }; } }
SortedMap implements Map<K, V> { @Override public Set<Entry<K, V>> entrySet() { return new AbstractSet() { @Override public Iterator iterator() { final Iterator<K> it = iterableKeys.iterator(); return new Iterator() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Object next() { K key = it.next(); return new AbstractMap.SimpleImmutableEntry<>(key, index.get(key)); } @Override public void remove() { throw new UnsupportedOperationException("Read only."); } }; } @Override public int size() { return index.size(); } }; } SortedMap(Map<K,V> to_sort, final Comparator<? super V> cmp); }
SortedMap implements Map<K, V> { @Override public Set<Entry<K, V>> entrySet() { return new AbstractSet() { @Override public Iterator iterator() { final Iterator<K> it = iterableKeys.iterator(); return new Iterator() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Object next() { K key = it.next(); return new AbstractMap.SimpleImmutableEntry<>(key, index.get(key)); } @Override public void remove() { throw new UnsupportedOperationException("Read only."); } }; } @Override public int size() { return index.size(); } }; } SortedMap(Map<K,V> to_sort, final Comparator<? super V> cmp); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); @Override V put(K key, V value); @Override V remove(Object key); @Override void putAll(Map<? extends K, ? extends V> m); @Override void clear(); }
SortedMap implements Map<K, V> { @Override public Set<Entry<K, V>> entrySet() { return new AbstractSet() { @Override public Iterator iterator() { final Iterator<K> it = iterableKeys.iterator(); return new Iterator() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Object next() { K key = it.next(); return new AbstractMap.SimpleImmutableEntry<>(key, index.get(key)); } @Override public void remove() { throw new UnsupportedOperationException("Read only."); } }; } @Override public int size() { return index.size(); } }; } SortedMap(Map<K,V> to_sort, final Comparator<? super V> cmp); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); @Override V put(K key, V value); @Override V remove(Object key); @Override void putAll(Map<? extends K, ? extends V> m); @Override void clear();  }