diff options
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/SmallSortedMap.java')
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/SmallSortedMap.java | 25 |
1 files changed, 14 insertions, 11 deletions
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 409fec10..279edc4d 100644 --- a/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java +++ b/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java @@ -197,6 +197,7 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { overflowEntries.entrySet(); } + @Override public int size() { return entryList.size() + overflowEntries.size(); @@ -356,6 +357,7 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { return lazyEntrySet; } + /** * @throws UnsupportedOperationException if {@link #makeImmutable()} has * has been called. @@ -525,6 +527,7 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { } } + /** * Iterator implementation that switches from the entry array to the overflow * entries appropriately. @@ -537,8 +540,8 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { @Override public boolean hasNext() { - return (pos + 1) < entryList.size() || - getOverflowIterator().hasNext(); + return (pos + 1) < entryList.size() + || (!overflowEntries.isEmpty() && getOverflowIterator().hasNext()); } @Override @@ -617,43 +620,43 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { return (Iterable<T>) ITERABLE; } } - + @Override public boolean equals(Object o) { if (this == o) { return true; } - + if (!(o instanceof SmallSortedMap)) { return super.equals(o); } - + SmallSortedMap<?, ?> other = (SmallSortedMap<?, ?>) o; final int size = size(); if (size != other.size()) { return false; } - + // Best effort try to avoid allocating an entry set. final int numArrayEntries = getNumArrayEntries(); if (numArrayEntries != other.getNumArrayEntries()) { return entrySet().equals(other.entrySet()); } - + for (int i = 0; i < numArrayEntries; i++) { if (!getArrayEntryAt(i).equals(other.getArrayEntryAt(i))) { return false; } } - + if (numArrayEntries != size) { return overflowEntries.equals(other.overflowEntries); } - - + + return true; } - + @Override public int hashCode() { int h = 0; |