diff --git a/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java b/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java index 17e8d77dba0a8..55934d21875fc 100644 --- a/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java +++ b/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java @@ -14,7 +14,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -169,13 +168,13 @@ public int getNumOverflowEntries() { /** @return An iterable over the overflow entries. */ public Iterable> getOverflowEntries() { return overflowEntries.isEmpty() - ? EmptySet.>iterable() + ? Collections.emptySet() : overflowEntries.entrySet(); } Iterable> getOverflowEntriesDescending() { return overflowEntriesDescending.isEmpty() - ? EmptySet.>iterable() + ? Collections.emptySet() : overflowEntriesDescending.entrySet(); } @@ -597,45 +596,6 @@ private Iterator> getOverflowIterator() { } } - /** - * Helper class that holds immutable instances of an Iterable/Iterator that we return when the - * overflow entries is empty. This eliminates the creation of an Iterator object when there is - * nothing to iterate over. - */ - private static class EmptySet { - - private static final Iterator ITERATOR = - new Iterator() { - @Override - public boolean hasNext() { - return false; - } - - @Override - public Object next() { - throw new NoSuchElementException(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - - private static final Iterable ITERABLE = - new Iterable() { - @Override - public Iterator iterator() { - return ITERATOR; - } - }; - - @SuppressWarnings("unchecked") - static Iterable iterable() { - return (Iterable) ITERABLE; - } - } - @Override public boolean equals(Object o) { if (this == o) {