diff options
Diffstat (limited to 'guava/src/com/google/common/collect/ImmutableMapValues.java')
-rw-r--r-- | guava/src/com/google/common/collect/ImmutableMapValues.java | 48 |
1 files changed, 9 insertions, 39 deletions
diff --git a/guava/src/com/google/common/collect/ImmutableMapValues.java b/guava/src/com/google/common/collect/ImmutableMapValues.java index 2c13c472c..379b14dc0 100644 --- a/guava/src/com/google/common/collect/ImmutableMapValues.java +++ b/guava/src/com/google/common/collect/ImmutableMapValues.java @@ -16,15 +16,13 @@ package com.google.common.collect; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; + import java.io.Serializable; import java.util.Map.Entry; -import java.util.Spliterator; -import java.util.function.Consumer; -import org.checkerframework.checker.nullness.qual.Nullable; + +import javax.annotation.Nullable; /** * {@code values()} implementation for {@link ImmutableMap}. @@ -35,7 +33,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; @GwtCompatible(emulated = true) final class ImmutableMapValues<K, V> extends ImmutableCollection<V> { private final ImmutableMap<K, V> map; - + ImmutableMapValues(ImmutableMap<K, V> map) { this.map = map; } @@ -47,24 +45,7 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> { @Override public UnmodifiableIterator<V> iterator() { - return new UnmodifiableIterator<V>() { - final UnmodifiableIterator<Entry<K, V>> entryItr = map.entrySet().iterator(); - - @Override - public boolean hasNext() { - return entryItr.hasNext(); - } - - @Override - public V next() { - return entryItr.next().getValue(); - } - }; - } - - @Override - public Spliterator<V> spliterator() { - return CollectSpliterators.map(map.entrySet().spliterator(), Entry::getValue); + return Maps.valueIterator(map.entrySet().iterator()); } @Override @@ -78,7 +59,7 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> { } @Override - public ImmutableList<V> asList() { + ImmutableList<V> createAsList() { final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList(); return new ImmutableAsList<V>() { @Override @@ -93,31 +74,20 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> { }; } - @GwtIncompatible // serialization - @Override - public void forEach(Consumer<? super V> action) { - checkNotNull(action); - map.forEach((k, v) -> action.accept(v)); - } - - @GwtIncompatible // serialization - @Override - Object writeReplace() { + @GwtIncompatible("serialization") + @Override Object writeReplace() { return new SerializedForm<V>(map); } - @GwtIncompatible // serialization + @GwtIncompatible("serialization") private static class SerializedForm<V> implements Serializable { final ImmutableMap<?, V> map; - SerializedForm(ImmutableMap<?, V> map) { this.map = map; } - Object readResolve() { return map.values(); } - private static final long serialVersionUID = 0; } } |