aboutsummaryrefslogtreecommitdiffstats
path: root/guava/src/com/google/common/collect/RegularImmutableMultiset.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava/src/com/google/common/collect/RegularImmutableMultiset.java')
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableMultiset.java57
1 files changed, 22 insertions, 35 deletions
diff --git a/guava/src/com/google/common/collect/RegularImmutableMultiset.java b/guava/src/com/google/common/collect/RegularImmutableMultiset.java
index e46f424..090c091 100644
--- a/guava/src/com/google/common/collect/RegularImmutableMultiset.java
+++ b/guava/src/com/google/common/collect/RegularImmutableMultiset.java
@@ -18,13 +18,14 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import java.util.Iterator;
import java.util.Map;
import javax.annotation.Nullable;
/**
* Implementation of {@link ImmutableMultiset} with one or more elements.
- *
+ *
* @author Jared Levy
* @author Louis Wasserman
*/
@@ -66,45 +67,31 @@ class RegularImmutableMultiset<E> extends ImmutableMultiset<E> {
return map.keySet();
}
- private static <E> Entry<E> entryFromMapEntry(Map.Entry<E, Integer> entry) {
- return Multisets.immutableEntry(entry.getKey(), entry.getValue());
- }
-
@Override
- ImmutableSet<Entry<E>> createEntrySet() {
- return new EntrySet();
- }
-
- private class EntrySet extends ImmutableMultiset<E>.EntrySet {
- @Override
- public int size() {
- return map.size();
- }
-
- @Override
- public UnmodifiableIterator<Entry<E>> iterator() {
- return asList().iterator();
- }
-
- @Override
- ImmutableList<Entry<E>> createAsList() {
- final ImmutableList<Map.Entry<E, Integer>> entryList = map.entrySet().asList();
- return new ImmutableAsList<Entry<E>>() {
- @Override
- public Entry<E> get(int index) {
- return entryFromMapEntry(entryList.get(index));
- }
-
- @Override
- ImmutableCollection<Entry<E>> delegateCollection() {
- return EntrySet.this;
- }
- };
- }
+ UnmodifiableIterator<Entry<E>> entryIterator() {
+ final Iterator<Map.Entry<E, Integer>> mapIterator =
+ map.entrySet().iterator();
+ return new UnmodifiableIterator<Entry<E>>() {
+ @Override
+ public boolean hasNext() {
+ return mapIterator.hasNext();
+ }
+
+ @Override
+ public Entry<E> next() {
+ Map.Entry<E, Integer> mapEntry = mapIterator.next();
+ return Multisets.immutableEntry(mapEntry.getKey(), mapEntry.getValue());
+ }
+ };
}
@Override
public int hashCode() {
return map.hashCode();
}
+
+ @Override
+ int distinctElements() {
+ return map.size();
+ }
}