diff options
Diffstat (limited to 'guava/src/com/google/common/collect')
73 files changed, 1457 insertions, 964 deletions
diff --git a/guava/src/com/google/common/collect/AbstractBiMap.java b/guava/src/com/google/common/collect/AbstractBiMap.java index 0563ea0e8..fab709a54 100644 --- a/guava/src/com/google/common/collect/AbstractBiMap.java +++ b/guava/src/com/google/common/collect/AbstractBiMap.java @@ -19,6 +19,7 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT; +import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; @@ -502,7 +503,7 @@ abstract class AbstractBiMap<K extends @Nullable Object, V extends @Nullable Obj @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - setInverse((AbstractBiMap<V, K>) stream.readObject()); + setInverse((AbstractBiMap<V, K>) requireNonNull(stream.readObject())); } @GwtIncompatible // Not needed in the emulated source. diff --git a/guava/src/com/google/common/collect/AbstractMapBasedMultimap.java b/guava/src/com/google/common/collect/AbstractMapBasedMultimap.java index 1e48281bf..d9108f16c 100644 --- a/guava/src/com/google/common/collect/AbstractMapBasedMultimap.java +++ b/guava/src/com/google/common/collect/AbstractMapBasedMultimap.java @@ -1063,7 +1063,7 @@ abstract class AbstractMapBasedMultimap<K extends @Nullable Object, V extends @N } @WeakOuter - class NavigableKeySet extends SortedKeySet implements NavigableSet<K> { + private final class NavigableKeySet extends SortedKeySet implements NavigableSet<K> { NavigableKeySet(NavigableMap<K, Collection<V>> subMap) { super(subMap); } @@ -1552,7 +1552,7 @@ abstract class AbstractMapBasedMultimap<K extends @Nullable Object, V extends @N } } - class NavigableAsMap extends SortedAsMap implements NavigableMap<K, Collection<V>> { + private final class NavigableAsMap extends SortedAsMap implements NavigableMap<K, Collection<V>> { NavigableAsMap(NavigableMap<K, Collection<V>> submap) { super(submap); diff --git a/guava/src/com/google/common/collect/CartesianList.java b/guava/src/com/google/common/collect/CartesianList.java index 4c31b1299..a93fb032f 100644 --- a/guava/src/com/google/common/collect/CartesianList.java +++ b/guava/src/com/google/common/collect/CartesianList.java @@ -17,6 +17,8 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkElementIndex; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.math.IntMath; import java.util.AbstractList; import java.util.List; @@ -132,6 +134,15 @@ final class CartesianList<E> extends AbstractList<List<E>> implements RandomAcce boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @J2ktIncompatible // serialization + @Override + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } diff --git a/guava/src/com/google/common/collect/CollectCollectors.java b/guava/src/com/google/common/collect/CollectCollectors.java index e0982ab0f..2b23bd25a 100644 --- a/guava/src/com/google/common/collect/CollectCollectors.java +++ b/guava/src/com/google/common/collect/CollectCollectors.java @@ -195,14 +195,13 @@ final class CollectCollectors { ImmutableMap.Builder<K, V>::new, (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)), ImmutableMap.Builder::combine, - ImmutableMap.Builder::build); + ImmutableMap.Builder::buildOrThrow); } - public static <T extends @Nullable Object, K, V> - Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction, - BinaryOperator<V> mergeFunction) { + static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction, + BinaryOperator<V> mergeFunction) { checkNotNull(keyFunction); checkNotNull(valueFunction); checkNotNull(mergeFunction); @@ -227,7 +226,7 @@ final class CollectCollectors { () -> new ImmutableSortedMap.Builder<K, V>(comparator), (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)), ImmutableSortedMap.Builder::combine, - ImmutableSortedMap.Builder::build, + ImmutableSortedMap.Builder::buildOrThrow, Collector.Characteristics.UNORDERED); } @@ -256,7 +255,7 @@ final class CollectCollectors { ImmutableBiMap.Builder<K, V>::new, (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)), ImmutableBiMap.Builder::combine, - ImmutableBiMap.Builder::build, + ImmutableBiMap.Builder::buildOrThrow, new Collector.Characteristics[0]); } @@ -464,4 +463,6 @@ final class CollectCollectors { return multimap1; }); } + + private CollectCollectors() {} } diff --git a/guava/src/com/google/common/collect/ConcurrentHashMultiset.java b/guava/src/com/google/common/collect/ConcurrentHashMultiset.java index 723ab0696..a84e3cee7 100644 --- a/guava/src/com/google/common/collect/ConcurrentHashMultiset.java +++ b/guava/src/com/google/common/collect/ConcurrentHashMultiset.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.CollectPreconditions.checkNonnegative; +import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; @@ -599,7 +600,7 @@ public final class ConcurrentHashMultiset<E> extends AbstractMultiset<E> impleme stream.defaultReadObject(); @SuppressWarnings("unchecked") // reading data stored by writeObject ConcurrentMap<E, Integer> deserializedCountMap = - (ConcurrentMap<E, Integer>) stream.readObject(); + (ConcurrentMap<E, Integer>) requireNonNull(stream.readObject()); FieldSettersHolder.COUNT_MAP_FIELD_SETTER.set(this, deserializedCountMap); } diff --git a/guava/src/com/google/common/collect/ContiguousSet.java b/guava/src/com/google/common/collect/ContiguousSet.java index d0792054e..539c67383 100644 --- a/guava/src/com/google/common/collect/ContiguousSet.java +++ b/guava/src/com/google/common/collect/ContiguousSet.java @@ -20,6 +20,7 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.DoNotCall; import java.util.Collections; import java.util.NoSuchElementException; @@ -259,4 +260,13 @@ public abstract class ContiguousSet<C extends Comparable> extends ImmutableSorte public static <E> ImmutableSortedSet.Builder<E> builder() { throw new UnsupportedOperationException(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @J2ktIncompatible // serialization + @Override + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/DenseImmutableTable.java b/guava/src/com/google/common/collect/DenseImmutableTable.java index 9de77c57f..a8e96e382 100644 --- a/guava/src/com/google/common/collect/DenseImmutableTable.java +++ b/guava/src/com/google/common/collect/DenseImmutableTable.java @@ -17,6 +17,8 @@ package com.google.common.collect; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap; import com.google.errorprone.annotations.Immutable; import com.google.j2objc.annotations.WeakOuter; @@ -144,6 +146,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> } }; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @J2ktIncompatible // serialization + @Override + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } private final class Row extends ImmutableArrayMap<C, V> { @@ -169,6 +180,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } private final class Column extends ImmutableArrayMap<R, V> { @@ -194,6 +214,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @WeakOuter @@ -216,6 +245,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> boolean isPartialView() { return false; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @WeakOuter @@ -238,6 +276,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> boolean isPartialView() { return false; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @Override @@ -285,7 +332,9 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> } @Override - SerializedForm createSerializedForm() { + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { return SerializedForm.create(this, cellRowIndices, cellColumnIndices); } } diff --git a/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java b/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java index 181731cc4..931c3e72c 100644 --- a/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java +++ b/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java @@ -15,6 +15,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import javax.annotation.CheckForNull; /** @@ -83,4 +84,12 @@ final class DescendingImmutableSortedMultiset<E> extends ImmutableSortedMultiset boolean isPartialView() { return forward.isPartialView(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java index 88c7d6b5c..10b3fa866 100644 --- a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java +++ b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java @@ -17,6 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import javax.annotation.CheckForNull; /** @@ -121,4 +122,12 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> { boolean isPartialView() { return forward.isPartialView(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/EnumBiMap.java b/guava/src/com/google/common/collect/EnumBiMap.java index c4b540b56..b7d297272 100644 --- a/guava/src/com/google/common/collect/EnumBiMap.java +++ b/guava/src/com/google/common/collect/EnumBiMap.java @@ -19,6 +19,7 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Platform.getDeclaringClassOrObjectForJ2cl; +import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; @@ -151,8 +152,8 @@ public final class EnumBiMap<K extends Enum<K>, V extends Enum<V>> extends Abstr @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - keyTypeOrObjectUnderJ2cl = (Class<K>) stream.readObject(); - valueTypeOrObjectUnderJ2cl = (Class<V>) stream.readObject(); + keyTypeOrObjectUnderJ2cl = (Class<K>) requireNonNull(stream.readObject()); + valueTypeOrObjectUnderJ2cl = (Class<V>) requireNonNull(stream.readObject()); setDelegates( new EnumMap<K, V>(keyTypeOrObjectUnderJ2cl), new EnumMap<V, K>(valueTypeOrObjectUnderJ2cl)); Serialization.populateMap(this, stream); diff --git a/guava/src/com/google/common/collect/EnumHashBiMap.java b/guava/src/com/google/common/collect/EnumHashBiMap.java index 33b45b95c..c7432d404 100644 --- a/guava/src/com/google/common/collect/EnumHashBiMap.java +++ b/guava/src/com/google/common/collect/EnumHashBiMap.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; @@ -128,7 +129,7 @@ public final class EnumHashBiMap<K extends Enum<K>, V extends @Nullable Object> @GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - keyTypeOrObjectUnderJ2cl = (Class<K>) stream.readObject(); + keyTypeOrObjectUnderJ2cl = (Class<K>) requireNonNull(stream.readObject()); /* * TODO: cpovirk - Pre-size the HashMap based on the number of enum values? (But *not* based on * the number of entries in the map, as that makes it easy for hostile inputs to trigger lots of diff --git a/guava/src/com/google/common/collect/EnumMultiset.java b/guava/src/com/google/common/collect/EnumMultiset.java index d6ced718b..04126f8aa 100644 --- a/guava/src/com/google/common/collect/EnumMultiset.java +++ b/guava/src/com/google/common/collect/EnumMultiset.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static com.google.common.collect.CollectPreconditions.checkRemove; +import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; @@ -309,7 +310,7 @@ public final class EnumMultiset<E extends Enum<E>> extends AbstractMultiset<E> private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); @SuppressWarnings("unchecked") // reading data stored by writeObject - Class<E> localType = (Class<E>) stream.readObject(); + Class<E> localType = (Class<E>) requireNonNull(stream.readObject()); type = localType; enumConstants = type.getEnumConstants(); counts = new int[enumConstants.length]; diff --git a/guava/src/com/google/common/collect/HashBiMap.java b/guava/src/com/google/common/collect/HashBiMap.java index f6ce5d42b..066056774 100644 --- a/guava/src/com/google/common/collect/HashBiMap.java +++ b/guava/src/com/google/common/collect/HashBiMap.java @@ -90,7 +90,7 @@ public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Obj return bimap; } - private static final class BiEntry<K extends @Nullable Object, V extends @Nullable Object> + static final class BiEntry<K extends @Nullable Object, V extends @Nullable Object> extends ImmutableEntry<K, V> { final int keyHash; final int valueHash; @@ -438,7 +438,7 @@ public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Obj return size; } - abstract class Itr<T extends @Nullable Object> implements Iterator<T> { + private abstract class Itr<T extends @Nullable Object> implements Iterator<T> { @CheckForNull BiEntry<K, V> next = firstInKeyInsertionOrder; @CheckForNull BiEntry<K, V> toRemove = null; int expectedModCount = modCount; @@ -531,7 +531,7 @@ public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Obj } class MapEntry extends AbstractMapEntry<K, V> { - BiEntry<K, V> delegate; + private BiEntry<K, V> delegate; MapEntry(BiEntry<K, V> entry) { this.delegate = entry; @@ -708,7 +708,7 @@ public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Obj } class InverseEntry extends AbstractMapEntry<V, K> { - BiEntry<K, V> delegate; + private BiEntry<K, V> delegate; InverseEntry(BiEntry<K, V> entry) { this.delegate = entry; diff --git a/guava/src/com/google/common/collect/ImmutableBiMap.java b/guava/src/com/google/common/collect/ImmutableBiMap.java index c0d3ed715..f1777e62e 100644 --- a/guava/src/com/google/common/collect/ImmutableBiMap.java +++ b/guava/src/com/google/common/collect/ImmutableBiMap.java @@ -30,6 +30,7 @@ import java.io.ObjectInputStream; import java.util.Arrays; import java.util.Comparator; import java.util.Map; +import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.stream.Collector; import java.util.stream.Collectors; @@ -45,8 +46,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ @GwtCompatible(serializable = true, emulated = true) @ElementTypesAreNonnullByDefault -public abstract class ImmutableBiMap<K, V> extends ImmutableBiMapFauxverideShim<K, V> - implements BiMap<K, V> { +public abstract class ImmutableBiMap<K, V> extends ImmutableMap<K, V> implements BiMap<K, V> { /** * Returns a {@link Collector} that accumulates elements into an {@code ImmutableBiMap} whose keys @@ -642,4 +642,40 @@ public abstract class ImmutableBiMap<K, V> extends ImmutableBiMapFauxverideShim< private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Use SerializedForm"); } + + /** + * Not supported. Use {@link #toImmutableBiMap} instead. This method exists only to hide {@link + * ImmutableMap#toImmutableMap(Function, Function)} from consumers of {@code ImmutableBiMap}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableBiMap#toImmutableBiMap}. + */ + @Deprecated + @DoNotCall("Use toImmutableBiMap") + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. This method does not make sense for {@code BiMap}. This method exists only to + * hide {@link ImmutableMap#toImmutableMap(Function, Function, BinaryOperator)} from consumers of + * {@code ImmutableBiMap}. + * + * @throws UnsupportedOperationException always + * @deprecated + */ + @Deprecated + @DoNotCall("Use toImmutableBiMap") + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction, + BinaryOperator<V> mergeFunction) { + throw new UnsupportedOperationException(); + } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableBiMapFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableBiMapFauxverideShim.java deleted file mode 100644 index 2f1f25c82..000000000 --- a/guava/src/com/google/common/collect/ImmutableBiMapFauxverideShim.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2015 The Guava Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.common.collect; - -import com.google.common.annotations.GwtIncompatible; -import com.google.errorprone.annotations.DoNotCall; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.stream.Collector; -import org.checkerframework.checker.nullness.qual.Nullable; - -/** - * "Overrides" the {@link ImmutableMap} static methods that lack {@link ImmutableBiMap} equivalents - * with deprecated, exception-throwing versions. See {@link ImmutableSortedSetFauxverideShim} for - * details. - * - * @author Louis Wasserman - */ -@GwtIncompatible -@ElementTypesAreNonnullByDefault -abstract class ImmutableBiMapFauxverideShim<K, V> extends ImmutableMap<K, V> { - /** - * Not supported. Use {@link ImmutableBiMap#toImmutableBiMap} instead. This method exists only to - * hide {@link ImmutableMap#toImmutableMap(Function, Function)} from consumers of {@code - * ImmutableBiMap}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableBiMap#toImmutableBiMap}. - */ - @Deprecated - @DoNotCall("Use toImmutableBiMap") - public static <T extends @Nullable Object, K, V> - Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. This method does not make sense for {@code BiMap}. This method exists only to - * hide {@link ImmutableMap#toImmutableMap(Function, Function, BinaryOperator)} from consumers of - * {@code ImmutableBiMap}. - * - * @throws UnsupportedOperationException always - * @deprecated - */ - @Deprecated - @DoNotCall("Use toImmutableBiMap") - public static <T extends @Nullable Object, K, V> - Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction, - BinaryOperator<V> mergeFunction) { - throw new UnsupportedOperationException(); - } -} diff --git a/guava/src/com/google/common/collect/ImmutableCollection.java b/guava/src/com/google/common/collect/ImmutableCollection.java index 68b175ffa..ee18f0d9c 100644 --- a/guava/src/com/google/common/collect/ImmutableCollection.java +++ b/guava/src/com/google/common/collect/ImmutableCollection.java @@ -19,6 +19,7 @@ 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 com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.DoNotCall; @@ -392,6 +393,7 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple } @J2ktIncompatible // serialization + @GwtIncompatible // serialization Object writeReplace() { // We serialize by default to ImmutableList, the simplest thing that works. return new ImmutableList.SerializedForm(toArray()); @@ -504,4 +506,6 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple */ public abstract ImmutableCollection<E> build(); } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableList.java b/guava/src/com/google/common/collect/ImmutableList.java index 9c60caf3f..7c7801dbc 100644 --- a/guava/src/com/google/common/collect/ImmutableList.java +++ b/guava/src/com/google/common/collect/ImmutableList.java @@ -26,6 +26,7 @@ import static com.google.common.collect.RegularImmutableList.EMPTY; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -444,6 +445,12 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> * Returns an immutable list of the elements between the specified {@code fromIndex}, inclusive, * and {@code toIndex}, exclusive. (If {@code fromIndex} and {@code toIndex} are equal, the empty * immutable list is returned.) + * + * <p><b>Note:</b> in almost all circumstances, the returned {@link ImmutableList} retains a + * strong reference to {@code this}, which may prevent the original list from being garbage + * collected. If you want the original list to be eligible for garbage collection, you should + * create and use a copy of the sub list (e.g., {@code + * ImmutableList.copyOf(originalList.subList(...))}). */ @Override public ImmutableList<E> subList(int fromIndex, int toIndex) { @@ -498,6 +505,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } /** @@ -678,6 +694,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> boolean isPartialView() { return forwardList.isPartialView(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @Override @@ -724,6 +749,7 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> @Override @J2ktIncompatible // serialization + @GwtIncompatible // serialization Object writeReplace() { return new SerializedForm(toArray()); } @@ -901,4 +927,6 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> return asImmutableList(contents, size); } } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableListMultimap.java b/guava/src/com/google/common/collect/ImmutableListMultimap.java index b46e7ae40..e70927484 100644 --- a/guava/src/com/google/common/collect/ImmutableListMultimap.java +++ b/guava/src/com/google/common/collect/ImmutableListMultimap.java @@ -16,6 +16,8 @@ package com.google.common.collect; +import static java.util.Objects.requireNonNull; + import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; @@ -473,7 +475,7 @@ public class ImmutableListMultimap<K, V> extends ImmutableMultimap<K, V> int tmpSize = 0; for (int i = 0; i < keyCount; i++) { - Object key = stream.readObject(); + Object key = requireNonNull(stream.readObject()); int valueCount = stream.readInt(); if (valueCount <= 0) { throw new InvalidObjectException("Invalid value count " + valueCount); @@ -481,7 +483,7 @@ public class ImmutableListMultimap<K, V> extends ImmutableMultimap<K, V> ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder(); for (int j = 0; j < valueCount; j++) { - valuesBuilder.add(stream.readObject()); + valuesBuilder.add(requireNonNull(stream.readObject())); } builder.put(key, valuesBuilder.build()); tmpSize += valueCount; diff --git a/guava/src/com/google/common/collect/ImmutableMap.java b/guava/src/com/google/common/collect/ImmutableMap.java index c370e5248..7a185b5d3 100644 --- a/guava/src/com/google/common/collect/ImmutableMap.java +++ b/guava/src/com/google/common/collect/ImmutableMap.java @@ -23,6 +23,7 @@ import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -96,8 +97,11 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable { * and values are the result of applying the provided mapping functions to the input elements. * * <p>If the mapped keys contain duplicates (according to {@link Object#equals(Object)}), the - * values are merged using the specified merging function. Entries will appear in the encounter - * order of the first occurrence of the key. + * values are merged using the specified merging function. If the merging function returns {@code + * null}, then the collector removes the value that has been computed for the key thus far (though + * future occurrences of the key would reinsert it). + * + * <p>Entries will appear in the encounter order of the first occurrence of the key. * * @since 21.0 */ @@ -754,6 +758,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable { public UnmodifiableIterator<Entry<K, V>> iterator() { return entryIterator(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } return new EntrySetImpl(); } @@ -762,6 +775,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable { ImmutableCollection<V> createValues() { return new ImmutableMapValues<>(this); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } ImmutableMap() {} @@ -845,8 +867,9 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable { @Deprecated @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final V computeIfPresent( - K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { + K key, BiFunction<? super K, ? super V, ? extends @Nullable V> remappingFunction) { throw new UnsupportedOperationException(); } @@ -859,8 +882,9 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable { @Deprecated @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final V compute( - K key, BiFunction<? super K, ? super @Nullable V, ? extends V> remappingFunction) { + K key, BiFunction<? super K, ? super @Nullable V, ? extends @Nullable V> remappingFunction) { throw new UnsupportedOperationException(); } @@ -1165,6 +1189,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable { } }; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @Override @@ -1282,4 +1315,6 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable { private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Use SerializedForm"); } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableMapEntrySet.java b/guava/src/com/google/common/collect/ImmutableMapEntrySet.java index 46df158b0..19f75cbbb 100644 --- a/guava/src/com/google/common/collect/ImmutableMapEntrySet.java +++ b/guava/src/com/google/common/collect/ImmutableMapEntrySet.java @@ -80,6 +80,15 @@ abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet.CachingAsList<Ent ImmutableList<Entry<K, V>> createAsList() { return new RegularImmutableAsList<>(this, entries); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } ImmutableMapEntrySet() {} diff --git a/guava/src/com/google/common/collect/ImmutableMapKeySet.java b/guava/src/com/google/common/collect/ImmutableMapKeySet.java index 6d1b51671..fb2661f47 100644 --- a/guava/src/com/google/common/collect/ImmutableMapKeySet.java +++ b/guava/src/com/google/common/collect/ImmutableMapKeySet.java @@ -77,6 +77,15 @@ final class ImmutableMapKeySet<K, V> extends IndexedImmutableSet<K> { return true; } + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } + // No longer used for new writes, but kept so that old data can still be read. @GwtIncompatible // serialization @J2ktIncompatible diff --git a/guava/src/com/google/common/collect/ImmutableMapValues.java b/guava/src/com/google/common/collect/ImmutableMapValues.java index 8884c1af6..831364599 100644 --- a/guava/src/com/google/common/collect/ImmutableMapValues.java +++ b/guava/src/com/google/common/collect/ImmutableMapValues.java @@ -92,6 +92,15 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> { ImmutableCollection<V> delegateCollection() { return ImmutableMapValues.this; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } @@ -102,6 +111,15 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> { map.forEach((k, v) -> action.accept(v)); } + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } + // No longer used for new writes, but kept so that old data can still be read. @GwtIncompatible // serialization @J2ktIncompatible diff --git a/guava/src/com/google/common/collect/ImmutableMultimap.java b/guava/src/com/google/common/collect/ImmutableMultimap.java index f1f654645..02dbd5e67 100644 --- a/guava/src/com/google/common/collect/ImmutableMultimap.java +++ b/guava/src/com/google/common/collect/ImmutableMultimap.java @@ -578,6 +578,15 @@ public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V return false; } + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } + private static final long serialVersionUID = 0; } @@ -781,6 +790,15 @@ public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V return true; } + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } + @J2ktIncompatible // serialization private static final long serialVersionUID = 0; } diff --git a/guava/src/com/google/common/collect/ImmutableMultiset.java b/guava/src/com/google/common/collect/ImmutableMultiset.java index cdc9f405a..f0197433f 100644 --- a/guava/src/com/google/common/collect/ImmutableMultiset.java +++ b/guava/src/com/google/common/collect/ImmutableMultiset.java @@ -630,6 +630,15 @@ public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializa public int size() { return entries.size(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @J2ktIncompatible @@ -660,4 +669,6 @@ public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializa private static final long serialVersionUID = 0; } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableRangeMap.java b/guava/src/com/google/common/collect/ImmutableRangeMap.java index 72444245f..88ad7d889 100644 --- a/guava/src/com/google/common/collect/ImmutableRangeMap.java +++ b/guava/src/com/google/common/collect/ImmutableRangeMap.java @@ -372,6 +372,14 @@ public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; final ImmutableRangeMap<K, V> outer = this; return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) { @@ -383,6 +391,14 @@ public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K return ImmutableRangeMap.of(); } } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } diff --git a/guava/src/com/google/common/collect/ImmutableRangeSet.java b/guava/src/com/google/common/collect/ImmutableRangeSet.java index afd421cd7..165b6e652 100644 --- a/guava/src/com/google/common/collect/ImmutableRangeSet.java +++ b/guava/src/com/google/common/collect/ImmutableRangeSet.java @@ -368,6 +368,14 @@ public final class ImmutableRangeSet<C extends Comparable> extends AbstractRange boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @Override @@ -487,6 +495,15 @@ public final class ImmutableRangeSet<C extends Comparable> extends AbstractRange boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } } diff --git a/guava/src/com/google/common/collect/ImmutableSet.java b/guava/src/com/google/common/collect/ImmutableSet.java index f4912a328..eeed833bf 100644 --- a/guava/src/com/google/common/collect/ImmutableSet.java +++ b/guava/src/com/google/common/collect/ImmutableSet.java @@ -22,6 +22,7 @@ import static com.google.common.collect.CollectPreconditions.checkNonnegative; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.math.IntMath; @@ -354,6 +355,15 @@ public abstract class ImmutableSet<E> extends ImmutableCollection<E> implements ImmutableList<E> createAsList() { return new RegularImmutableAsList<E>(this, toArray()); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } abstract static class Indexed<E> extends CachingAsList<E> { @@ -395,8 +405,26 @@ public abstract class ImmutableSet<E> extends ImmutableCollection<E> implements Indexed<E> delegateCollection() { return Indexed.this; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } /* @@ -989,4 +1017,6 @@ public abstract class ImmutableSet<E> extends ImmutableCollection<E> implements } } } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableSetMultimap.java b/guava/src/com/google/common/collect/ImmutableSetMultimap.java index 4887ae79b..b1f8438cd 100644 --- a/guava/src/com/google/common/collect/ImmutableSetMultimap.java +++ b/guava/src/com/google/common/collect/ImmutableSetMultimap.java @@ -17,6 +17,7 @@ package com.google.common.collect; import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; @@ -552,6 +553,15 @@ public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V> boolean isPartialView() { return false; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } private static <V> ImmutableSet<V> valueSet( @@ -615,7 +625,7 @@ public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V> int tmpSize = 0; for (int i = 0; i < keyCount; i++) { - Object key = stream.readObject(); + Object key = requireNonNull(stream.readObject()); int valueCount = stream.readInt(); if (valueCount <= 0) { throw new InvalidObjectException("Invalid value count " + valueCount); @@ -623,7 +633,7 @@ public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V> ImmutableSet.Builder<Object> valuesBuilder = valuesBuilder(valueComparator); for (int j = 0; j < valueCount; j++) { - valuesBuilder.add(stream.readObject()); + valuesBuilder.add(requireNonNull(stream.readObject())); } ImmutableSet<Object> valueSet = valuesBuilder.build(); if (valueSet.size() != valueCount) { diff --git a/guava/src/com/google/common/collect/ImmutableSortedAsList.java b/guava/src/com/google/common/collect/ImmutableSortedAsList.java index 30f19a02e..1736f2b8e 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedAsList.java +++ b/guava/src/com/google/common/collect/ImmutableSortedAsList.java @@ -16,6 +16,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import java.util.Comparator; import java.util.Spliterator; import javax.annotation.CheckForNull; @@ -93,4 +94,13 @@ final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E> delegateList()::get, comparator()); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/ImmutableSortedMap.java b/guava/src/com/google/common/collect/ImmutableSortedMap.java index f38922e43..ba0b91c95 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedMap.java +++ b/guava/src/com/google/common/collect/ImmutableSortedMap.java @@ -23,6 +23,7 @@ import static com.google.common.collect.Maps.keyOrNull; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.DoNotCall; @@ -64,7 +65,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ @GwtCompatible(serializable = true, emulated = true) @ElementTypesAreNonnullByDefault -public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxverideShim<K, V> +public final class ImmutableSortedMap<K, V> extends ImmutableMap<K, V> implements NavigableMap<K, V> { /** * Returns a {@link Collector} that accumulates elements into an {@code ImmutableSortedMap} whose @@ -844,6 +845,15 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride ImmutableCollection<Entry<K, V>> delegateCollection() { return EntrySet.this; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } @@ -851,6 +861,15 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride ImmutableMap<K, V> map() { return ImmutableSortedMap.this; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } return isEmpty() ? ImmutableSet.<Entry<K, V>>of() : new EntrySet(); } @@ -1167,4 +1186,290 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride // This class is never actually serialized directly, but we have to make the // warning go away (and suppressing would suppress for all nested classes too) private static final long serialVersionUID = 0; + + /** + * Not supported. Use {@link #toImmutableSortedMap}, which offers better type-safety, instead. + * This method exists only to hide {@link ImmutableMap#toImmutableMap} from consumers of {@code + * ImmutableSortedMap}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}. + */ + @DoNotCall("Use toImmutableSortedMap") + @Deprecated + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. Use {@link #toImmutableSortedMap}, which offers better type-safety, instead. + * This method exists only to hide {@link ImmutableMap#toImmutableMap} from consumers of {@code + * ImmutableSortedMap}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}. + */ + @DoNotCall("Use toImmutableSortedMap") + @Deprecated + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction, + BinaryOperator<V> mergeFunction) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. Use {@link #naturalOrder}, which offers better type-safety, instead. This method + * exists only to hide {@link ImmutableMap#builder} from consumers of {@code ImmutableSortedMap}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety. + */ + @DoNotCall("Use naturalOrder") + @Deprecated + public static <K, V> ImmutableSortedMap.Builder<K, V> builder() { + throw new UnsupportedOperationException(); + } + + /** + * Not supported for ImmutableSortedMap. + * + * @throws UnsupportedOperationException always + * @deprecated Not supported for ImmutableSortedMap. + */ + @DoNotCall("Use naturalOrder (which does not accept an expected size)") + @Deprecated + public static <K, V> ImmutableSortedMap.Builder<K, V> builderWithExpectedSize(int expectedSize) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain a non-{@code Comparable} + * key.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this dummy + * version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass a key of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object)}.</b> + */ + @DoNotCall("Pass a key of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls to will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, + * Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, + * Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of( + K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, + * Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of( + K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, + * Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of( + K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, + * Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6, + K k7, + V v7, + K k8, + V v8) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, + * Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6, + K k7, + V v7, + K k8, + V v8, + K k9, + V v9) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} + * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass keys of type {@code Comparable} to use {@link + * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, + * Comparable, Object, Comparable, Object)}.</b> + */ + @DoNotCall("Pass keys of type Comparable") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> of( + K k1, + V v1, + K k2, + V v2, + K k3, + V v3, + K k4, + V v4, + K k5, + V v5, + K k6, + V v6, + K k7, + V v7, + K k8, + V v8, + K k9, + V v9, + K k10, + V v10) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. Use {@code ImmutableSortedMap.copyOf(ImmutableMap.ofEntries(...))}. + * + * @deprecated Use {@code ImmutableSortedMap.copyOf(ImmutableMap.ofEntries(...))}. + */ + @DoNotCall("ImmutableSortedMap.ofEntries not currently available; use ImmutableSortedMap.copyOf") + @Deprecated + public static <K, V> ImmutableSortedMap<K, V> ofEntries( + Entry<? extends K, ? extends V>... entries) { + throw new UnsupportedOperationException(); + } } diff --git a/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java deleted file mode 100644 index 7b2e4d755..000000000 --- a/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (C) 2009 The Guava Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.common.collect; - -import com.google.common.annotations.GwtIncompatible; -import com.google.errorprone.annotations.DoNotCall; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.stream.Collector; -import org.checkerframework.checker.nullness.qual.Nullable; - -/** - * "Overrides" the {@link ImmutableMap} static methods that lack {@link ImmutableSortedMap} - * equivalents with deprecated, exception-throwing versions. See {@link - * ImmutableSortedSetFauxverideShim} for details. - * - * @author Chris Povirk - */ -@GwtIncompatible -@ElementTypesAreNonnullByDefault -abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> { - /** - * Not supported. Use {@link ImmutableSortedMap#toImmutableSortedMap}, which offers better - * type-safety, instead. This method exists only to hide {@link ImmutableMap#toImmutableMap} from - * consumers of {@code ImmutableSortedMap}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}. - */ - @DoNotCall("Use toImmutableSortedMap") - @Deprecated - public static <T extends @Nullable Object, K, V> - Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. Use {@link ImmutableSortedMap#toImmutableSortedMap}, which offers better - * type-safety, instead. This method exists only to hide {@link ImmutableMap#toImmutableMap} from - * consumers of {@code ImmutableSortedMap}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}. - */ - @DoNotCall("Use toImmutableSortedMap") - @Deprecated - public static <T extends @Nullable Object, K, V> - Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction, - BinaryOperator<V> mergeFunction) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety, - * instead. This method exists only to hide {@link ImmutableMap#builder} from consumers of {@code - * ImmutableSortedMap}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety. - */ - @DoNotCall("Use naturalOrder") - @Deprecated - public static <K, V> ImmutableSortedMap.Builder<K, V> builder() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported for ImmutableSortedMap. - * - * @throws UnsupportedOperationException always - * @deprecated Not supported for ImmutableSortedMap. - */ - @DoNotCall("Use naturalOrder (which does not accept an expected size)") - @Deprecated - public static <K, V> ImmutableSortedMap.Builder<K, V> builderWithExpectedSize(int expectedSize) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain a non-{@code Comparable} - * key.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this dummy - * version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass a key of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object)}.</b> - */ - @DoNotCall("Pass a key of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls to will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, - * Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of( - K k1, - V v1, - K k2, - V v2, - K k3, - V v3, - K k4, - V v4, - K k5, - V v5, - K k6, - V v6, - K k7, - V v7, - K k8, - V v8) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of( - K k1, - V v1, - K k2, - V v2, - K k3, - V v3, - K k4, - V v4, - K k5, - V v5, - K k6, - V v6, - K k7, - V v7, - K k8, - V v8, - K k9, - V v9) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a map that may contain non-{@code Comparable} - * keys.</b> Proper calls will resolve to the version in {@code ImmutableSortedMap}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object)}.</b> - */ - @DoNotCall("Pass keys of type Comparable") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> of( - K k1, - V v1, - K k2, - V v2, - K k3, - V v3, - K k4, - V v4, - K k5, - V v5, - K k6, - V v6, - K k7, - V v7, - K k8, - V v8, - K k9, - V v9, - K k10, - V v10) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. Use {@code ImmutableSortedMap.copyOf(ImmutableMap.ofEntries(...))}. - * - * @deprecated Use {@code ImmutableSortedMap.copyOf(ImmutableMap.ofEntries(...))}. - */ - @DoNotCall("ImmutableSortedMap.ofEntries not currently available; use ImmutableSortedMap.copyOf") - @Deprecated - public static <K, V> ImmutableSortedMap<K, V> ofEntries( - Entry<? extends K, ? extends V>... entries) { - throw new UnsupportedOperationException(); - } - - // No copyOf() fauxveride; see ImmutableSortedSetFauxverideShim. -} diff --git a/guava/src/com/google/common/collect/ImmutableSortedMultiset.java b/guava/src/com/google/common/collect/ImmutableSortedMultiset.java index d2991bce9..454a77569 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedMultiset.java +++ b/guava/src/com/google/common/collect/ImmutableSortedMultiset.java @@ -55,7 +55,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ @GwtIncompatible // hasn't been tested yet @ElementTypesAreNonnullByDefault -public abstract class ImmutableSortedMultiset<E> extends ImmutableSortedMultisetFauxverideShim<E> +public abstract class ImmutableSortedMultiset<E> extends ImmutableMultiset<E> implements SortedMultiset<E> { // TODO(lowasser): GWT compatibility @@ -606,4 +606,162 @@ public abstract class ImmutableSortedMultiset<E> extends ImmutableSortedMultiset private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Use SerializedForm"); } + + /** + * Not supported. Use {@link #toImmutableSortedMultiset} instead. This method exists only to hide + * {@link ImmutableMultiset#toImmutableMultiset} from consumers of {@code + * ImmutableSortedMultiset}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. + * @since 21.0 + */ + @DoNotCall("Use toImmutableSortedMultiset.") + @Deprecated + public static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. Use {@link #toImmutableSortedMultiset} instead. This method exists only to hide + * {@link ImmutableMultiset#toImmutableMultiset} from consumers of {@code + * ImmutableSortedMultiset}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. + * @since 22.0 + */ + @DoNotCall("Use toImmutableSortedMultiset.") + @Deprecated + public static <T extends @Nullable Object, E> + Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset( + Function<? super T, ? extends E> elementFunction, + ToIntFunction<? super T> countFunction) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. Use {@link #naturalOrder}, which offers better type-safety, instead. This method + * exists only to hide {@link ImmutableMultiset#builder} from consumers of {@code + * ImmutableSortedMultiset}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better type-safety. + */ + @DoNotCall("Use naturalOrder.") + @Deprecated + public static <E> ImmutableSortedMultiset.Builder<E> builder() { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code + * Comparable} element.</b> Proper calls will resolve to the version in {@code + * ImmutableSortedMultiset}, not this dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link + * ImmutableSortedMultiset#of(Comparable)}.</b> + */ + @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") + @Deprecated + public static <E> ImmutableSortedMultiset<E> of(E element) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code + * Comparable} element.</b> Proper calls will resolve to the version in {@code + * ImmutableSortedMultiset}, not this dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedMultiset#of(Comparable, Comparable)}.</b> + */ + @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") + @Deprecated + public static <E> ImmutableSortedMultiset<E> of(E e1, E e2) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code + * Comparable} element.</b> Proper calls will resolve to the version in {@code + * ImmutableSortedMultiset}, not this dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable)}.</b> + */ + @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") + @Deprecated + public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code + * Comparable} element.</b> Proper calls will resolve to the version in {@code + * ImmutableSortedMultiset}, not this dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable)}. </b> + */ + @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") + @Deprecated + public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code + * Comparable} element.</b> Proper calls will resolve to the version in {@code + * ImmutableSortedMultiset}, not this dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable)} . + * </b> + */ + @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") + @Deprecated + public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code + * Comparable} element.</b> Proper calls will resolve to the version in {@code + * ImmutableSortedMultiset}, not this dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable, + * Comparable, Comparable...)} . </b> + */ + @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") + @Deprecated + public static <E> ImmutableSortedMultiset<E> of( + E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a multiset that may contain non-{@code + * Comparable} elements.</b> Proper calls will resolve to the version in {@code + * ImmutableSortedMultiset}, not this dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link + * ImmutableSortedMultiset#copyOf(Comparable[])}.</b> + */ + @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") + @Deprecated + // The usage of "Z" here works around bugs in Javadoc (JDK-8318093) and JDiff. + public static <Z> ImmutableSortedMultiset<Z> copyOf(Z[] elements) { + throw new UnsupportedOperationException(); + } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableSortedMultisetFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableSortedMultisetFauxverideShim.java deleted file mode 100644 index 94a2f560d..000000000 --- a/guava/src/com/google/common/collect/ImmutableSortedMultisetFauxverideShim.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2011 The Guava Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.common.collect; - -import com.google.common.annotations.GwtIncompatible; -import com.google.errorprone.annotations.DoNotCall; -import java.util.function.Function; -import java.util.function.ToIntFunction; -import java.util.stream.Collector; -import org.checkerframework.checker.nullness.qual.Nullable; - -/** - * "Overrides" the {@link ImmutableMultiset} static methods that lack {@link - * ImmutableSortedMultiset} equivalents with deprecated, exception-throwing versions. This prevents - * accidents like the following: - * - * <pre>{@code - * List<Object> objects = ...; - * // Sort them: - * Set<Object> sorted = ImmutableSortedMultiset.copyOf(objects); - * // BAD CODE! The returned multiset is actually an unsorted ImmutableMultiset! - * }</pre> - * - * <p>While we could put the overrides in {@link ImmutableSortedMultiset} itself, it seems clearer - * to separate these "do not call" methods from those intended for normal use. - * - * @author Louis Wasserman - */ -@GwtIncompatible -@ElementTypesAreNonnullByDefault -abstract class ImmutableSortedMultisetFauxverideShim<E> extends ImmutableMultiset<E> { - /** - * Not supported. Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset} instead. This - * method exists only to hide {@link ImmutableMultiset#toImmutableMultiset} from consumers of - * {@code ImmutableSortedMultiset}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. - * @since 21.0 - */ - @DoNotCall("Use toImmutableSortedMultiset.") - @Deprecated - public static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset} instead. This - * method exists only to hide {@link ImmutableMultiset#toImmutableMultiset} from consumers of - * {@code ImmutableSortedMultiset}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedMultiset#toImmutableSortedMultiset}. - * @since 22.0 - */ - @DoNotCall("Use toImmutableSortedMultiset.") - @Deprecated - public static <T extends @Nullable Object, E> - Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset( - Function<? super T, ? extends E> elementFunction, - ToIntFunction<? super T> countFunction) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better - * type-safety, instead. This method exists only to hide {@link ImmutableMultiset#builder} from - * consumers of {@code ImmutableSortedMultiset}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedMultiset#naturalOrder}, which offers better type-safety. - */ - @DoNotCall("Use naturalOrder.") - @Deprecated - public static <E> ImmutableSortedMultiset.Builder<E> builder() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code - * Comparable} element.</b> Proper calls will resolve to the version in {@code - * ImmutableSortedMultiset}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link - * ImmutableSortedMultiset#of(Comparable)}.</b> - */ - @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") - @Deprecated - public static <E> ImmutableSortedMultiset<E> of(E element) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code - * Comparable} element.</b> Proper calls will resolve to the version in {@code - * ImmutableSortedMultiset}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedMultiset#of(Comparable, Comparable)}.</b> - */ - @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") - @Deprecated - public static <E> ImmutableSortedMultiset<E> of(E e1, E e2) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code - * Comparable} element.</b> Proper calls will resolve to the version in {@code - * ImmutableSortedMultiset}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable)}.</b> - */ - @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") - @Deprecated - public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code - * Comparable} element.</b> Proper calls will resolve to the version in {@code - * ImmutableSortedMultiset}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable)}. </b> - */ - @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") - @Deprecated - public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code - * Comparable} element.</b> Proper calls will resolve to the version in {@code - * ImmutableSortedMultiset}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable)} . - * </b> - */ - @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") - @Deprecated - public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a multiset that may contain a non-{@code - * Comparable} element.</b> Proper calls will resolve to the version in {@code - * ImmutableSortedMultiset}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedMultiset#of(Comparable, Comparable, Comparable, Comparable, Comparable, - * Comparable, Comparable...)} . </b> - */ - @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") - @Deprecated - public static <E> ImmutableSortedMultiset<E> of( - E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a multiset that may contain non-{@code - * Comparable} elements.</b> Proper calls will resolve to the version in {@code - * ImmutableSortedMultiset}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link - * ImmutableSortedMultiset#copyOf(Comparable[])}.</b> - */ - @DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)") - @Deprecated - public static <E> ImmutableSortedMultiset<E> copyOf(E[] elements) { - throw new UnsupportedOperationException(); - } - - /* - * We would like to include an unsupported "<E> copyOf(Iterable<E>)" here, providing only the - * properly typed "<E extends Comparable<E>> copyOf(Iterable<E>)" in ImmutableSortedMultiset (and - * likewise for the Iterator equivalent). However, due to a change in Sun's interpretation of the - * JLS (as described at http://bugs.sun.com/view_bug.do?bug_id=6182950), the OpenJDK 7 compiler - * available as of this writing rejects our attempts. To maintain compatibility with that version - * and with any other compilers that interpret the JLS similarly, there is no definition of - * copyOf() here, and the definition in ImmutableSortedMultiset matches that in - * ImmutableMultiset. - * - * The result is that ImmutableSortedMultiset.copyOf() may be called on non-Comparable elements. - * We have not discovered a better solution. In retrospect, the static factory methods should - * have gone in a separate class so that ImmutableSortedMultiset wouldn't "inherit" - * too-permissive factory methods from ImmutableMultiset. - */ -} diff --git a/guava/src/com/google/common/collect/ImmutableSortedSet.java b/guava/src/com/google/common/collect/ImmutableSortedSet.java index c730fa496..dc88e3983 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedSet.java +++ b/guava/src/com/google/common/collect/ImmutableSortedSet.java @@ -64,7 +64,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; @GwtCompatible(serializable = true, emulated = true) @SuppressWarnings("serial") // we're overriding default serialization @ElementTypesAreNonnullByDefault -public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E> +public abstract class ImmutableSortedSet<E> extends ImmutableSet.CachingAsList<E> implements NavigableSet<E>, SortedIterable<E> { static final int SPLITERATOR_CHARACTERISTICS = ImmutableSet.SPLITERATOR_CHARACTERISTICS | Spliterator.SORTED; @@ -854,4 +854,153 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride Object writeReplace() { return new SerializedForm<E>(comparator, toArray()); } + + /** + * Not supported. Use {@link #toImmutableSortedSet} instead. This method exists only to hide + * {@link ImmutableSet#toImmutableSet} from consumers of {@code ImmutableSortedSet}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedSet#toImmutableSortedSet}. + * @since 21.0 + */ + @DoNotCall("Use toImmutableSortedSet") + @Deprecated + public static <E> Collector<E, ?, ImmutableSet<E>> toImmutableSet() { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. Use {@link #naturalOrder}, which offers better type-safety, instead. This method + * exists only to hide {@link ImmutableSet#builder} from consumers of {@code ImmutableSortedSet}. + * + * @throws UnsupportedOperationException always + * @deprecated Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety. + */ + @DoNotCall("Use naturalOrder") + @Deprecated + public static <E> ImmutableSortedSet.Builder<E> builder() { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. This method exists only to hide {@link ImmutableSet#builderWithExpectedSize} + * from consumers of {@code ImmutableSortedSet}. + * + * @throws UnsupportedOperationException always + * @deprecated Not supported by ImmutableSortedSet. + */ + @DoNotCall("Use naturalOrder (which does not accept an expected size)") + @Deprecated + public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expectedSize) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} + * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link + * ImmutableSortedSet#of(Comparable)}.</b> + */ + @DoNotCall("Pass a parameter of type Comparable") + @Deprecated + public static <E> ImmutableSortedSet<E> of(E element) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} + * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedSet#of(Comparable, Comparable)}.</b> + */ + @DoNotCall("Pass parameters of type Comparable") + @Deprecated + public static <E> ImmutableSortedSet<E> of(E e1, E e2) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} + * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedSet#of(Comparable, Comparable, Comparable)}.</b> + */ + @DoNotCall("Pass parameters of type Comparable") + @Deprecated + public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} + * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. </b> + */ + @DoNotCall("Pass parameters of type Comparable") + @Deprecated + public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} + * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedSet#of( Comparable, Comparable, Comparable, Comparable, Comparable)}. </b> + */ + @DoNotCall("Pass parameters of type Comparable") + @Deprecated + public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} + * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link + * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable, Comparable, + * Comparable, Comparable...)}. </b> + */ + @DoNotCall("Pass parameters of type Comparable") + @Deprecated + public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { + throw new UnsupportedOperationException(); + } + + /** + * Not supported. <b>You are attempting to create a set that may contain non-{@code Comparable} + * elements.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this + * dummy version. + * + * @throws UnsupportedOperationException always + * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link + * ImmutableSortedSet#copyOf(Comparable[])}.</b> + */ + @DoNotCall("Pass parameters of type Comparable") + @Deprecated + // The usage of "Z" here works around bugs in Javadoc (JDK-8318093) and JDiff. + public static <Z> ImmutableSortedSet<Z> copyOf(Z[] elements) { + throw new UnsupportedOperationException(); + } + + private static final long serialVersionUID = 0xcafebabe; } diff --git a/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java deleted file mode 100644 index ff3ac12d5..000000000 --- a/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2009 The Guava Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.common.collect; - -import com.google.common.annotations.GwtIncompatible; -import com.google.errorprone.annotations.DoNotCall; -import java.util.stream.Collector; - -/** - * "Overrides" the {@link ImmutableSet} static methods that lack {@link ImmutableSortedSet} - * equivalents with deprecated, exception-throwing versions. This prevents accidents like the - * following: - * - * <pre>{@code - * List<Object> objects = ...; - * // Sort them: - * Set<Object> sorted = ImmutableSortedSet.copyOf(objects); - * // BAD CODE! The returned set is actually an unsorted ImmutableSet! - * }</pre> - * - * <p>While we could put the overrides in {@link ImmutableSortedSet} itself, it seems clearer to - * separate these "do not call" methods from those intended for normal use. - * - * @author Chris Povirk - */ -@GwtIncompatible -@ElementTypesAreNonnullByDefault -abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet.CachingAsList<E> { - /** - * Not supported. Use {@link ImmutableSortedSet#toImmutableSortedSet} instead. This method exists - * only to hide {@link ImmutableSet#toImmutableSet} from consumers of {@code ImmutableSortedSet}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedSet#toImmutableSortedSet}. - * @since 21.0 - */ - @DoNotCall("Use toImmutableSortedSet") - @Deprecated - public static <E> Collector<E, ?, ImmutableSet<E>> toImmutableSet() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety, - * instead. This method exists only to hide {@link ImmutableSet#builder} from consumers of {@code - * ImmutableSortedSet}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety. - */ - @DoNotCall("Use naturalOrder") - @Deprecated - public static <E> ImmutableSortedSet.Builder<E> builder() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. This method exists only to hide {@link ImmutableSet#builderWithExpectedSize} - * from consumers of {@code ImmutableSortedSet}. - * - * @throws UnsupportedOperationException always - * @deprecated Not supported by ImmutableSortedSet. - */ - @DoNotCall("Use naturalOrder (which does not accept an expected size)") - @Deprecated - public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expectedSize) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} - * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable)}.</b> - */ - @DoNotCall("Pass a parameter of type Comparable") - @Deprecated - public static <E> ImmutableSortedSet<E> of(E element) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} - * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable, Comparable)}.</b> - */ - @DoNotCall("Pass parameters of type Comparable") - @Deprecated - public static <E> ImmutableSortedSet<E> of(E e1, E e2) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} - * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable, Comparable, Comparable)}.</b> - */ - @DoNotCall("Pass parameters of type Comparable") - @Deprecated - public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} - * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. </b> - */ - @DoNotCall("Pass parameters of type Comparable") - @Deprecated - public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} - * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of( Comparable, Comparable, Comparable, Comparable, Comparable)}. </b> - */ - @DoNotCall("Pass parameters of type Comparable") - @Deprecated - public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a set that may contain a non-{@code Comparable} - * element.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable, Comparable, - * Comparable, Comparable...)}. </b> - */ - @DoNotCall("Pass parameters of type Comparable") - @Deprecated - public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. <b>You are attempting to create a set that may contain non-{@code Comparable} - * elements.</b> Proper calls will resolve to the version in {@code ImmutableSortedSet}, not this - * dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#copyOf(Comparable[])}.</b> - */ - @DoNotCall("Pass parameters of type Comparable") - @Deprecated - public static <E> ImmutableSortedSet<E> copyOf(E[] elements) { - throw new UnsupportedOperationException(); - } - - /* - * We would like to include an unsupported "<E> copyOf(Iterable<E>)" here, - * providing only the properly typed - * "<E extends Comparable<E>> copyOf(Iterable<E>)" in ImmutableSortedSet (and - * likewise for the Iterator equivalent). However, due to a change in Sun's - * interpretation of the JLS (as described at - * http://bugs.sun.com/view_bug.do?bug_id=6182950), the OpenJDK 7 compiler - * available as of this writing rejects our attempts. To maintain - * compatibility with that version and with any other compilers that interpret - * the JLS similarly, there is no definition of copyOf() here, and the - * definition in ImmutableSortedSet matches that in ImmutableSet. - * - * The result is that ImmutableSortedSet.copyOf() may be called on - * non-Comparable elements. We have not discovered a better solution. In - * retrospect, the static factory methods should have gone in a separate class - * so that ImmutableSortedSet wouldn't "inherit" too-permissive factory - * methods from ImmutableSet. - */ -} diff --git a/guava/src/com/google/common/collect/ImmutableTable.java b/guava/src/com/google/common/collect/ImmutableTable.java index 62cae079f..e1db67c93 100644 --- a/guava/src/com/google/common/collect/ImmutableTable.java +++ b/guava/src/com/google/common/collect/ImmutableTable.java @@ -445,9 +445,6 @@ public abstract class ImmutableTable<R, C, V> extends AbstractTable<R, C, V> throw new UnsupportedOperationException(); } - /** Creates the common serialized form for this table. */ - abstract SerializedForm createSerializedForm(); - /** * Serialized type for all ImmutableTable instances. It captures the logical contents and * preserves iteration order of all views. @@ -503,9 +500,9 @@ public abstract class ImmutableTable<R, C, V> extends AbstractTable<R, C, V> private static final long serialVersionUID = 0; } - final Object writeReplace() { - return createSerializedForm(); - } + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + abstract Object writeReplace(); @GwtIncompatible // serialization @J2ktIncompatible diff --git a/guava/src/com/google/common/collect/IndexedImmutableSet.java b/guava/src/com/google/common/collect/IndexedImmutableSet.java index 20dfacbab..396ce6b0f 100644 --- a/guava/src/com/google/common/collect/IndexedImmutableSet.java +++ b/guava/src/com/google/common/collect/IndexedImmutableSet.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import java.util.Spliterator; import java.util.function.Consumer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -76,6 +77,24 @@ abstract class IndexedImmutableSet<E> extends ImmutableSet.CachingAsList<E> { ImmutableCollection<E> delegateCollection() { return IndexedImmutableSet.this; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/Iterators.java b/guava/src/com/google/common/collect/Iterators.java index 0699202fe..009a41cef 100644 --- a/guava/src/com/google/common/collect/Iterators.java +++ b/guava/src/com/google/common/collect/Iterators.java @@ -42,7 +42,6 @@ import java.util.Deque; import java.util.Enumeration; import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.PriorityQueue; import java.util.Queue; @@ -1056,47 +1055,40 @@ public final class Iterators { */ @SafeVarargs public static <T extends @Nullable Object> UnmodifiableIterator<T> forArray(T... array) { - return forArray(array, 0, array.length, 0); + return forArrayWithPosition(array, 0); } /** - * Returns a list iterator containing the elements in the specified range of {@code array} in - * order, starting at the specified index. + * Returns a list iterator containing the elements in the specified {@code array} in order, + * starting at the specified {@code position}. * * <p>The {@code Iterable} equivalent of this method is {@code - * Arrays.asList(array).subList(offset, offset + length).listIterator(index)}. + * Arrays.asList(array).listIterator(position)}. */ - static <T extends @Nullable Object> UnmodifiableListIterator<T> forArray( - T[] array, int offset, int length, int index) { - checkArgument(length >= 0); - int end = offset + length; - - // Technically we should give a slightly more descriptive error on overflow - Preconditions.checkPositionIndexes(offset, end, array.length); - Preconditions.checkPositionIndex(index, length); - if (length == 0) { + static <T extends @Nullable Object> UnmodifiableListIterator<T> forArrayWithPosition( + T[] array, int position) { + if (array.length == 0) { + Preconditions.checkPositionIndex(position, array.length); // otherwise checked in ArrayItr return emptyListIterator(); } - return new ArrayItr<>(array, offset, length, index); + return new ArrayItr<>(array, position); } private static final class ArrayItr<T extends @Nullable Object> extends AbstractIndexedListIterator<T> { - static final UnmodifiableListIterator<Object> EMPTY = new ArrayItr<>(new Object[0], 0, 0, 0); + static final UnmodifiableListIterator<Object> EMPTY = new ArrayItr<>(new Object[0], 0); private final T[] array; - private final int offset; - ArrayItr(T[] array, int offset, int length, int index) { - super(length, index); + ArrayItr(T[] array, int position) { + super(array.length, position); this.array = array; - this.offset = offset; } @Override @ParametricNullness protected T get(int index) { - return array[offset + index]; + return array[index]; } } @@ -1107,24 +1099,36 @@ public final class Iterators { */ public static <T extends @Nullable Object> UnmodifiableIterator<T> singletonIterator( @ParametricNullness T value) { - return new UnmodifiableIterator<T>() { - boolean done; + return new SingletonIterator<>(value); + } - @Override - public boolean hasNext() { - return !done; - } + private static final class SingletonIterator<T extends @Nullable Object> + extends UnmodifiableIterator<T> { + private static final Object SENTINEL = new Object(); - @Override - @ParametricNullness - public T next() { - if (done) { - throw new NoSuchElementException(); - } - done = true; - return value; + private Object valueOrSentinel; + + SingletonIterator(T value) { + this.valueOrSentinel = value; + } + + @Override + public boolean hasNext() { + return valueOrSentinel != SENTINEL; + } + + @Override + @ParametricNullness + public T next() { + if (valueOrSentinel == SENTINEL) { + throw new NoSuchElementException(); } - }; + // The field held either a T or SENTINEL, and it turned out not to be SENTINEL. + @SuppressWarnings("unchecked") + T t = (T) valueOrSentinel; + valueOrSentinel = SENTINEL; + return t; + } } /** @@ -1444,9 +1448,4 @@ public final class Iterators { toRemove = null; } } - - /** Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557 */ - static <T extends @Nullable Object> ListIterator<T> cast(Iterator<T> iterator) { - return (ListIterator<T>) iterator; - } } diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java b/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java index f126fdea3..bf45138f7 100644 --- a/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java +++ b/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java @@ -18,6 +18,8 @@ package com.google.common.collect; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.j2objc.annotations.RetainedWith; @@ -102,6 +104,15 @@ final class JdkBackedImmutableBiMap<K, V> extends ImmutableBiMap<K, V> { public int size() { return entries.size(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @Override @@ -124,4 +135,13 @@ final class JdkBackedImmutableBiMap<K, V> extends ImmutableBiMap<K, V> { boolean isPartialView() { return false; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableMap.java b/guava/src/com/google/common/collect/JdkBackedImmutableMap.java index 222c4deb8..0dd791923 100644 --- a/guava/src/com/google/common/collect/JdkBackedImmutableMap.java +++ b/guava/src/com/google/common/collect/JdkBackedImmutableMap.java @@ -21,6 +21,8 @@ import static com.google.common.collect.RegularImmutableMap.makeImmutable; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import java.util.HashMap; import java.util.Map; import java.util.function.BiConsumer; @@ -130,4 +132,13 @@ final class JdkBackedImmutableMap<K, V> extends ImmutableMap<K, V> { boolean isPartialView() { return false; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java b/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java index 41d95f045..8c116b351 100644 --- a/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java +++ b/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java @@ -17,6 +17,8 @@ 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 com.google.common.annotations.J2ktIncompatible; import com.google.common.primitives.Ints; import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.Collection; @@ -89,4 +91,13 @@ final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E> { public int size() { return Ints.saturatedCast(size); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableSet.java b/guava/src/com/google/common/collect/JdkBackedImmutableSet.java index c00167713..bee7076fa 100644 --- a/guava/src/com/google/common/collect/JdkBackedImmutableSet.java +++ b/guava/src/com/google/common/collect/JdkBackedImmutableSet.java @@ -15,6 +15,8 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import java.util.Set; import javax.annotation.CheckForNull; @@ -55,4 +57,13 @@ final class JdkBackedImmutableSet<E> extends IndexedImmutableSet<E> { public int size() { return delegateList.size(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/LinkedHashMultimap.java b/guava/src/com/google/common/collect/LinkedHashMultimap.java index 78afd3268..61f2a0202 100644 --- a/guava/src/com/google/common/collect/LinkedHashMultimap.java +++ b/guava/src/com/google/common/collect/LinkedHashMultimap.java @@ -193,11 +193,11 @@ public final class LinkedHashMultimap<K extends @Nullable Object, V extends @Nul * frameworks like Android that define post-construct hooks like Activity.onCreate, etc. */ - @CheckForNull ValueSetLink<K, V> predecessorInValueSet; - @CheckForNull ValueSetLink<K, V> successorInValueSet; + @CheckForNull private ValueSetLink<K, V> predecessorInValueSet; + @CheckForNull private ValueSetLink<K, V> successorInValueSet; - @CheckForNull ValueEntry<K, V> predecessorInMultimap; - @CheckForNull ValueEntry<K, V> successorInMultimap; + @CheckForNull private ValueEntry<K, V> predecessorInMultimap; + @CheckForNull private ValueEntry<K, V> successorInMultimap; ValueEntry( @ParametricNullness K key, diff --git a/guava/src/com/google/common/collect/LinkedListMultimap.java b/guava/src/com/google/common/collect/LinkedListMultimap.java index d88564ca5..d5edcb8ce 100644 --- a/guava/src/com/google/common/collect/LinkedListMultimap.java +++ b/guava/src/com/google/common/collect/LinkedListMultimap.java @@ -107,7 +107,7 @@ public class LinkedListMultimap<K extends @Nullable Object, V extends @Nullable * ValueForKeyIterator} in constant time. */ - private static final class Node<K extends @Nullable Object, V extends @Nullable Object> + static final class Node<K extends @Nullable Object, V extends @Nullable Object> extends AbstractMapEntry<K, V> { @ParametricNullness final K key; @ParametricNullness V value; diff --git a/guava/src/com/google/common/collect/Lists.java b/guava/src/com/google/common/collect/Lists.java index 0816b754a..a9c99e27a 100644 --- a/guava/src/com/google/common/collect/Lists.java +++ b/guava/src/com/google/common/collect/Lists.java @@ -780,6 +780,15 @@ public final class Lists { public int size() { return string.length(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } private static final class CharSequenceAsList extends AbstractList<Character> { diff --git a/guava/src/com/google/common/collect/Maps.java b/guava/src/com/google/common/collect/Maps.java index 173447caf..9bc33913e 100644 --- a/guava/src/com/google/common/collect/Maps.java +++ b/guava/src/com/google/common/collect/Maps.java @@ -1737,22 +1737,33 @@ public final class Maps { throw new UnsupportedOperationException(); } + /* + * TODO(cpovirk): Uncomment the @NonNull annotations below once our JDK stubs and J2KT + * emulations include them. + */ @Override + @CheckForNull public V computeIfPresent( - K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { + K key, + BiFunction<? super K, ? super /*@NonNull*/ V, ? extends @Nullable V> remappingFunction) { throw new UnsupportedOperationException(); } @Override + @CheckForNull public V compute( - K key, BiFunction<? super K, ? super @Nullable V, ? extends V> remappingFunction) { + K key, + BiFunction<? super K, ? super @Nullable V, ? extends @Nullable V> remappingFunction) { throw new UnsupportedOperationException(); } @Override @CheckForNull public V merge( - K key, V value, BiFunction<? super V, ? super V, ? extends @Nullable V> function) { + K key, + /*@NonNull*/ V value, + BiFunction<? super /*@NonNull*/ V, ? super /*@NonNull*/ V, ? extends @Nullable V> + function) { throw new UnsupportedOperationException(); } @@ -3644,22 +3655,33 @@ public final class Maps { throw new UnsupportedOperationException(); } + /* + * TODO(cpovirk): Uncomment the @NonNull annotations below once our JDK stubs and J2KT + * emulations include them. + */ @Override + @CheckForNull public V computeIfPresent( - K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { + K key, + BiFunction<? super K, ? super /*@NonNull*/ V, ? extends @Nullable V> remappingFunction) { throw new UnsupportedOperationException(); } @Override + @CheckForNull public V compute( - K key, BiFunction<? super K, ? super @Nullable V, ? extends V> remappingFunction) { + K key, + BiFunction<? super K, ? super @Nullable V, ? extends @Nullable V> remappingFunction) { throw new UnsupportedOperationException(); } @Override @CheckForNull public V merge( - K key, V value, BiFunction<? super V, ? super V, ? extends @Nullable V> function) { + K key, + /*@NonNull*/ V value, + BiFunction<? super /*@NonNull*/ V, ? super /*@NonNull*/ V, ? extends @Nullable V> + function) { throw new UnsupportedOperationException(); } diff --git a/guava/src/com/google/common/collect/MinMaxPriorityQueue.java b/guava/src/com/google/common/collect/MinMaxPriorityQueue.java index 877d6bc0b..0dfa2b2fc 100644 --- a/guava/src/com/google/common/collect/MinMaxPriorityQueue.java +++ b/guava/src/com/google/common/collect/MinMaxPriorityQueue.java @@ -521,7 +521,7 @@ public final class MinMaxPriorityQueue<E> extends AbstractQueue<E> { * sake they are stored interleaved on alternate heap levels in the same array (MMPQ.queue). */ @WeakOuter - private class Heap { + class Heap { final Ordering<E> ordering; @SuppressWarnings("nullness:initialization.field.uninitialized") diff --git a/guava/src/com/google/common/collect/Multimaps.java b/guava/src/com/google/common/collect/Multimaps.java index c614764c5..c158c6519 100644 --- a/guava/src/com/google/common/collect/Multimaps.java +++ b/guava/src/com/google/common/collect/Multimaps.java @@ -122,7 +122,7 @@ public final class Multimaps { java.util.function.Function<? super T, ? extends K> keyFunction, java.util.function.Function<? super T, ? extends V> valueFunction, java.util.function.Supplier<M> multimapSupplier) { - return CollectCollectors.toMultimap(keyFunction, valueFunction, multimapSupplier); + return CollectCollectors.<T, K, V, M>toMultimap(keyFunction, valueFunction, multimapSupplier); } /** @@ -167,7 +167,8 @@ public final class Multimaps { java.util.function.Function<? super T, ? extends K> keyFunction, java.util.function.Function<? super T, ? extends Stream<? extends V>> valueFunction, java.util.function.Supplier<M> multimapSupplier) { - return CollectCollectors.flatteningToMultimap(keyFunction, valueFunction, multimapSupplier); + return CollectCollectors.<T, K, V, M>flatteningToMultimap( + keyFunction, valueFunction, multimapSupplier); } /** @@ -285,8 +286,8 @@ public final class Multimaps { @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - factory = (Supplier<? extends Collection<V>>) stream.readObject(); - Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject(); + factory = (Supplier<? extends Collection<V>>) requireNonNull(stream.readObject()); + Map<K, Collection<V>> map = (Map<K, Collection<V>>) requireNonNull(stream.readObject()); setMap(map); } @@ -371,8 +372,8 @@ public final class Multimaps { @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - factory = (Supplier<? extends List<V>>) stream.readObject(); - Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject(); + factory = (Supplier<? extends List<V>>) requireNonNull(stream.readObject()); + Map<K, Collection<V>> map = (Map<K, Collection<V>>) requireNonNull(stream.readObject()); setMap(map); } @@ -479,8 +480,8 @@ public final class Multimaps { @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - factory = (Supplier<? extends Set<V>>) stream.readObject(); - Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject(); + factory = (Supplier<? extends Set<V>>) requireNonNull(stream.readObject()); + Map<K, Collection<V>> map = (Map<K, Collection<V>>) requireNonNull(stream.readObject()); setMap(map); } @@ -573,9 +574,9 @@ public final class Multimaps { @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - factory = (Supplier<? extends SortedSet<V>>) stream.readObject(); + factory = (Supplier<? extends SortedSet<V>>) requireNonNull(stream.readObject()); valueComparator = factory.get().comparator(); - Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject(); + Map<K, Collection<V>> map = (Map<K, Collection<V>>) requireNonNull(stream.readObject()); setMap(map); } diff --git a/guava/src/com/google/common/collect/Multisets.java b/guava/src/com/google/common/collect/Multisets.java index fcc674472..7a0eb10a3 100644 --- a/guava/src/com/google/common/collect/Multisets.java +++ b/guava/src/com/google/common/collect/Multisets.java @@ -196,6 +196,11 @@ public final class Multisets { } @Override + public boolean removeIf(java.util.function.Predicate<? super E> filter) { + throw new UnsupportedOperationException(); + } + + @Override public boolean retainAll(Collection<?> elementsToRetain) { throw new UnsupportedOperationException(); } @@ -1166,7 +1171,7 @@ public final class Multisets { } private static final class DecreasingCount implements Comparator<Entry<?>> { - static final DecreasingCount INSTANCE = new DecreasingCount(); + static final Comparator<Entry<?>> INSTANCE = new DecreasingCount(); @Override public int compare(Entry<?> entry1, Entry<?> entry2) { diff --git a/guava/src/com/google/common/collect/Platform.java b/guava/src/com/google/common/collect/Platform.java index 3f118764e..7ae061c83 100644 --- a/guava/src/com/google/common/collect/Platform.java +++ b/guava/src/com/google/common/collect/Platform.java @@ -32,8 +32,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; @GwtCompatible(emulated = true) @ElementTypesAreNonnullByDefault final class Platform { - private static final java.util.logging.Logger logger = - java.util.logging.Logger.getLogger(Platform.class.getName()); /** Returns the platform preferred implementation of a map based on a hash table. */ static <K extends @Nullable Object, V extends @Nullable Object> @@ -82,7 +80,7 @@ final class Platform { * for insertions. */ static <E extends @Nullable Object> Set<E> preservesInsertionOrderOnAddsSet() { - return Sets.newLinkedHashSet(); + return CompactHashSet.create(); } /** diff --git a/guava/src/com/google/common/collect/RegularContiguousSet.java b/guava/src/com/google/common/collect/RegularContiguousSet.java index 9c2e5a26f..8159d107b 100644 --- a/guava/src/com/google/common/collect/RegularContiguousSet.java +++ b/guava/src/com/google/common/collect/RegularContiguousSet.java @@ -143,6 +143,15 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C> checkElementIndex(i, size()); return domain.offset(first(), i); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } else { return super.createAsList(); diff --git a/guava/src/com/google/common/collect/RegularImmutableAsList.java b/guava/src/com/google/common/collect/RegularImmutableAsList.java index 0e3fe4ec8..bc4d8ae5d 100644 --- a/guava/src/com/google/common/collect/RegularImmutableAsList.java +++ b/guava/src/com/google/common/collect/RegularImmutableAsList.java @@ -18,6 +18,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import java.util.function.Consumer; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -91,4 +92,13 @@ class RegularImmutableAsList<E> extends ImmutableAsList<E> { public E get(int index) { return delegateList.get(index); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/RegularImmutableBiMap.java b/guava/src/com/google/common/collect/RegularImmutableBiMap.java index 333b80177..e97a86934 100644 --- a/guava/src/com/google/common/collect/RegularImmutableBiMap.java +++ b/guava/src/com/google/common/collect/RegularImmutableBiMap.java @@ -25,6 +25,7 @@ import static com.google.common.collect.RegularImmutableMap.checkNoConflictInKey import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMapEntry.NonTerminalImmutableBiMapEntry; @@ -285,8 +286,26 @@ class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> { ImmutableCollection<Entry<V, K>> delegateCollection() { return InverseEntrySet.this; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @Override @@ -296,6 +315,7 @@ class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> { @Override @J2ktIncompatible // serialization + @GwtIncompatible // serialization Object writeReplace() { return new InverseSerializedForm<>(RegularImmutableBiMap.this); } @@ -320,4 +340,13 @@ class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> { private static final long serialVersionUID = 1; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/RegularImmutableList.java b/guava/src/com/google/common/collect/RegularImmutableList.java index 397147d70..915c6e2c7 100644 --- a/guava/src/com/google/common/collect/RegularImmutableList.java +++ b/guava/src/com/google/common/collect/RegularImmutableList.java @@ -17,6 +17,8 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import java.util.Spliterator; import java.util.Spliterators; @@ -82,7 +84,7 @@ class RegularImmutableList<E> extends ImmutableList<E> { public UnmodifiableListIterator<E> listIterator(int index) { // for performance // The fake cast to E is safe because the creation methods only allow E's - return (UnmodifiableListIterator<E>) Iterators.forArray(array, 0, array.length, index); + return (UnmodifiableListIterator<E>) Iterators.forArrayWithPosition(array, index); } @Override @@ -91,4 +93,13 @@ class RegularImmutableList<E> extends ImmutableList<E> { } // TODO(lowasser): benchmark optimizations for equals() and see if they're worthwhile + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/RegularImmutableMap.java b/guava/src/com/google/common/collect/RegularImmutableMap.java index 42649109a..32aa2507a 100644 --- a/guava/src/com/google/common/collect/RegularImmutableMap.java +++ b/guava/src/com/google/common/collect/RegularImmutableMap.java @@ -346,6 +346,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> { return map.size(); } + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } + // No longer used for new writes, but kept so that old data can still be read. @GwtIncompatible // serialization @J2ktIncompatible @@ -394,6 +403,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> { return true; } + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } + // No longer used for new writes, but kept so that old data can still be read. @GwtIncompatible // serialization @J2ktIncompatible @@ -414,6 +432,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> { } } + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } + // This class is never actually serialized directly, but we have to make the // warning go away (and suppressing would suppress for all nested classes too) @J2ktIncompatible // serialization diff --git a/guava/src/com/google/common/collect/RegularImmutableMultiset.java b/guava/src/com/google/common/collect/RegularImmutableMultiset.java index 026919e0d..8b50345b3 100644 --- a/guava/src/com/google/common/collect/RegularImmutableMultiset.java +++ b/guava/src/com/google/common/collect/RegularImmutableMultiset.java @@ -17,6 +17,8 @@ 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 com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Objects; import com.google.common.collect.Multisets.ImmutableEntry; @@ -194,4 +196,13 @@ class RegularImmutableMultiset<E> extends ImmutableMultiset<E> { public int hashCode() { return hashCode; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/RegularImmutableSet.java b/guava/src/com/google/common/collect/RegularImmutableSet.java index 211c89304..0db235d69 100644 --- a/guava/src/com/google/common/collect/RegularImmutableSet.java +++ b/guava/src/com/google/common/collect/RegularImmutableSet.java @@ -17,6 +17,8 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import java.util.Spliterator; import java.util.Spliterators; @@ -124,4 +126,13 @@ final class RegularImmutableSet<E> extends ImmutableSet.CachingAsList<E> { boolean isHashCodeFast() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java b/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java index 4b7ba8742..258f7aa09 100644 --- a/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java +++ b/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkPositionIndexes; import static com.google.common.collect.BoundType.CLOSED; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.primitives.Ints; import java.util.Comparator; @@ -133,4 +134,12 @@ final class RegularImmutableSortedMultiset<E> extends ImmutableSortedMultiset<E> boolean isPartialView() { return offset > 0 || length < cumulativeCounts.length - 1; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java index 572e0acbf..970e85112 100644 --- a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java +++ b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -329,4 +330,13 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { ? emptySet(reversedOrder) : new RegularImmutableSortedSet<E>(elements.reverse(), reversedOrder); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/RegularImmutableTable.java b/guava/src/com/google/common/collect/RegularImmutableTable.java index 337f123b6..03def2cbc 100644 --- a/guava/src/com/google/common/collect/RegularImmutableTable.java +++ b/guava/src/com/google/common/collect/RegularImmutableTable.java @@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.j2objc.annotations.WeakOuter; import java.util.Collections; import java.util.Comparator; @@ -69,6 +71,15 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> { boolean isPartialView() { return false; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } abstract V getValue(int iterationIndex); @@ -94,6 +105,15 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> { boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } static <R, C, V> RegularImmutableTable<R, C, V> forCells( @@ -181,4 +201,10 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> { newValue, existingValue); } + + // redeclare to satisfy our test for b/310253115 + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + abstract Object writeReplace(); } diff --git a/guava/src/com/google/common/collect/Sets.java b/guava/src/com/google/common/collect/Sets.java index da3814881..c38181001 100644 --- a/guava/src/com/google/common/collect/Sets.java +++ b/guava/src/com/google/common/collect/Sets.java @@ -1432,6 +1432,15 @@ public final class Sets { boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } }; return new CartesianSet<E>(axes, new CartesianList<E>(listAxes)); } @@ -1473,7 +1482,11 @@ public final class Sets { CartesianSet<?> that = (CartesianSet<?>) object; return this.axes.equals(that.axes); } - return super.equals(object); + if (object instanceof Set) { + Set<?> that = (Set<?>) object; + return this.size() == that.size() && this.containsAll(that); + } + return false; } @Override diff --git a/guava/src/com/google/common/collect/SingletonImmutableBiMap.java b/guava/src/com/google/common/collect/SingletonImmutableBiMap.java index c5fb2b298..c2f4ae137 100644 --- a/guava/src/com/google/common/collect/SingletonImmutableBiMap.java +++ b/guava/src/com/google/common/collect/SingletonImmutableBiMap.java @@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.CollectPreconditions.checkEntryNotNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.j2objc.annotations.RetainedWith; import java.util.function.BiConsumer; @@ -110,4 +112,13 @@ final class SingletonImmutableBiMap<K, V> extends ImmutableBiMap<K, V> { } } } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/SingletonImmutableList.java b/guava/src/com/google/common/collect/SingletonImmutableList.java index a7ac8b30e..ba1b1a713 100644 --- a/guava/src/com/google/common/collect/SingletonImmutableList.java +++ b/guava/src/com/google/common/collect/SingletonImmutableList.java @@ -19,6 +19,8 @@ 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 com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; import java.util.Collections; import java.util.Spliterator; @@ -75,4 +77,13 @@ final class SingletonImmutableList<E> extends ImmutableList<E> { boolean isPartialView() { return false; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/SingletonImmutableSet.java b/guava/src/com/google/common/collect/SingletonImmutableSet.java index 088cb802f..15db1c5e5 100644 --- a/guava/src/com/google/common/collect/SingletonImmutableSet.java +++ b/guava/src/com/google/common/collect/SingletonImmutableSet.java @@ -17,6 +17,8 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -80,4 +82,13 @@ final class SingletonImmutableSet<E> extends ImmutableSet<E> { public String toString() { return '[' + element.toString() + ']'; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } diff --git a/guava/src/com/google/common/collect/SingletonImmutableTable.java b/guava/src/com/google/common/collect/SingletonImmutableTable.java index cfaeadb41..6f839ceb4 100644 --- a/guava/src/com/google/common/collect/SingletonImmutableTable.java +++ b/guava/src/com/google/common/collect/SingletonImmutableTable.java @@ -19,6 +19,8 @@ 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 com.google.common.annotations.J2ktIncompatible; import java.util.Map; /** @@ -77,7 +79,9 @@ class SingletonImmutableTable<R, C, V> extends ImmutableTable<R, C, V> { } @Override - SerializedForm createSerializedForm() { + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { return SerializedForm.create(this, new int[] {0}, new int[] {0}); } } diff --git a/guava/src/com/google/common/collect/SparseImmutableTable.java b/guava/src/com/google/common/collect/SparseImmutableTable.java index 44881fde7..f7222b120 100644 --- a/guava/src/com/google/common/collect/SparseImmutableTable.java +++ b/guava/src/com/google/common/collect/SparseImmutableTable.java @@ -17,6 +17,8 @@ package com.google.common.collect; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.util.LinkedHashMap; import java.util.Map; @@ -130,7 +132,9 @@ final class SparseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> } @Override - SerializedForm createSerializedForm() { + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { Map<C, Integer> columnKeyToIndex = Maps.indexMap(columnKeySet()); int[] cellColumnIndices = new int[cellSet().size()]; int i = 0; diff --git a/guava/src/com/google/common/collect/StandardTable.java b/guava/src/com/google/common/collect/StandardTable.java index 6ec3c6b23..f9d6f1b8e 100644 --- a/guava/src/com/google/common/collect/StandardTable.java +++ b/guava/src/com/google/common/collect/StandardTable.java @@ -846,7 +846,7 @@ class StandardTable<R, C, V> extends AbstractTable<R, C, V> implements Serializa } @WeakOuter - class EntrySet extends TableSet<Entry<R, Map<C, V>>> { + private final class EntrySet extends TableSet<Entry<R, Map<C, V>>> { @Override public Iterator<Entry<R, Map<C, V>>> iterator() { return Maps.asMapEntryIterator( @@ -935,7 +935,7 @@ class StandardTable<R, C, V> extends AbstractTable<R, C, V> implements Serializa } @WeakOuter - class ColumnMapEntrySet extends TableSet<Entry<C, Map<R, V>>> { + private final class ColumnMapEntrySet extends TableSet<Entry<C, Map<R, V>>> { @Override public Iterator<Entry<C, Map<R, V>>> iterator() { return Maps.asMapEntryIterator( diff --git a/guava/src/com/google/common/collect/Streams.java b/guava/src/com/google/common/collect/Streams.java index 0b6e88ce2..8209cedb5 100644 --- a/guava/src/com/google/common/collect/Streams.java +++ b/guava/src/com/google/common/collect/Streams.java @@ -148,11 +148,40 @@ public final class Streams { return optional.isPresent() ? DoubleStream.of(optional.getAsDouble()) : DoubleStream.empty(); } + @SuppressWarnings("CatchingUnchecked") // sneaky checked exception private static void closeAll(BaseStream<?, ?>[] toClose) { + // If one of the streams throws an exception, continue closing the others, then throw the + // exception later. If more than one stream throws an exception, the later ones are added to the + // first as suppressed exceptions. We don't catch Error on the grounds that it should be allowed + // to propagate immediately. + Exception exception = null; for (BaseStream<?, ?> stream : toClose) { - // TODO(b/80534298): Catch exceptions, rethrowing later with extras as suppressed exceptions. - stream.close(); + try { + stream.close(); + } catch (Exception e) { // sneaky checked exception + if (exception == null) { + exception = e; + } else { + exception.addSuppressed(e); + } + } + } + if (exception != null) { + // Normally this is a RuntimeException that doesn't need sneakyThrow. + // But theoretically we could see sneaky checked exception + sneakyThrow(exception); + } + } + + /** Throws an undeclared checked exception. */ + private static void sneakyThrow(Throwable t) { + class SneakyThrower<T extends Throwable> { + @SuppressWarnings("unchecked") // not really safe, but that's the point + void throwIt(Throwable t) throws T { + throw (T) t; + } } + new SneakyThrower<Error>().throwIt(t); } /** diff --git a/guava/src/com/google/common/collect/Synchronized.java b/guava/src/com/google/common/collect/Synchronized.java index b1422e316..89916cd4d 100644 --- a/guava/src/com/google/common/collect/Synchronized.java +++ b/guava/src/com/google/common/collect/Synchronized.java @@ -369,8 +369,8 @@ final class Synchronized { : new SynchronizedList<E>(list, mutex); } - private static class SynchronizedList<E extends @Nullable Object> - extends SynchronizedCollection<E> implements List<E> { + static class SynchronizedList<E extends @Nullable Object> extends SynchronizedCollection<E> + implements List<E> { SynchronizedList(List<E> delegate, @CheckForNull Object mutex) { super(delegate, mutex); } @@ -480,7 +480,7 @@ final class Synchronized { private static final long serialVersionUID = 0; } - private static class SynchronizedRandomAccessList<E extends @Nullable Object> + static final class SynchronizedRandomAccessList<E extends @Nullable Object> extends SynchronizedList<E> implements RandomAccess { SynchronizedRandomAccessList(List<E> list, @CheckForNull Object mutex) { super(list, mutex); @@ -497,7 +497,7 @@ final class Synchronized { return new SynchronizedMultiset<E>(multiset, mutex); } - private static class SynchronizedMultiset<E extends @Nullable Object> + static final class SynchronizedMultiset<E extends @Nullable Object> extends SynchronizedCollection<E> implements Multiset<E> { @CheckForNull transient Set<E> elementSet; @CheckForNull transient Set<Multiset.Entry<E>> entrySet; @@ -594,7 +594,7 @@ final class Synchronized { return new SynchronizedMultimap<>(multimap, mutex); } - private static class SynchronizedMultimap<K extends @Nullable Object, V extends @Nullable Object> + static class SynchronizedMultimap<K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedObject implements Multimap<K, V> { @CheckForNull transient Set<K> keySet; @CheckForNull transient Collection<V> valuesCollection; @@ -788,7 +788,7 @@ final class Synchronized { return new SynchronizedListMultimap<>(multimap, mutex); } - private static class SynchronizedListMultimap< + static final class SynchronizedListMultimap< K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedMultimap<K, V> implements ListMultimap<K, V> { SynchronizedListMultimap(ListMultimap<K, V> delegate, @CheckForNull Object mutex) { @@ -832,8 +832,7 @@ final class Synchronized { return new SynchronizedSetMultimap<>(multimap, mutex); } - private static class SynchronizedSetMultimap< - K extends @Nullable Object, V extends @Nullable Object> + static class SynchronizedSetMultimap<K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedMultimap<K, V> implements SetMultimap<K, V> { @CheckForNull transient Set<Map.Entry<K, V>> entrySet; @@ -889,7 +888,7 @@ final class Synchronized { return new SynchronizedSortedSetMultimap<>(multimap, mutex); } - private static class SynchronizedSortedSetMultimap< + static final class SynchronizedSortedSetMultimap< K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedSetMultimap<K, V> implements SortedSetMultimap<K, V> { SynchronizedSortedSetMultimap(SortedSetMultimap<K, V> delegate, @CheckForNull Object mutex) { @@ -956,7 +955,7 @@ final class Synchronized { } } - private static class SynchronizedAsMapEntries< + static final class SynchronizedAsMapEntries< K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedSet<Map.Entry<K, Collection<V>>> { SynchronizedAsMapEntries( @@ -1063,7 +1062,7 @@ final class Synchronized { return new SynchronizedMap<>(map, mutex); } - private static class SynchronizedMap<K extends @Nullable Object, V extends @Nullable Object> + static class SynchronizedMap<K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedObject implements Map<K, V> { @CheckForNull transient Set<K> keySet; @CheckForNull transient Collection<V> values; @@ -1188,17 +1187,25 @@ final class Synchronized { } } + /* + * TODO(cpovirk): Uncomment the @NonNull annotations below once our JDK stubs and J2KT + * emulations include them. + */ @Override + @CheckForNull public V computeIfPresent( - K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { + K key, + BiFunction<? super K, ? super /*@NonNull*/ V, ? extends @Nullable V> remappingFunction) { synchronized (mutex) { return delegate().computeIfPresent(key, remappingFunction); } } @Override + @CheckForNull public V compute( - K key, BiFunction<? super K, ? super @Nullable V, ? extends V> remappingFunction) { + K key, + BiFunction<? super K, ? super @Nullable V, ? extends @Nullable V> remappingFunction) { synchronized (mutex) { return delegate().compute(key, remappingFunction); } @@ -1207,7 +1214,10 @@ final class Synchronized { @Override @CheckForNull public V merge( - K key, V value, BiFunction<? super V, ? super V, ? extends @Nullable V> remappingFunction) { + K key, + /*@NonNull*/ V value, + BiFunction<? super /*@NonNull*/ V, ? super /*@NonNull*/ V, ? extends @Nullable V> + remappingFunction) { synchronized (mutex) { return delegate().merge(key, value, remappingFunction); } @@ -1350,8 +1360,7 @@ final class Synchronized { return new SynchronizedBiMap<>(bimap, mutex, null); } - @VisibleForTesting - static class SynchronizedBiMap<K extends @Nullable Object, V extends @Nullable Object> + static final class SynchronizedBiMap<K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedMap<K, V> implements BiMap<K, V>, Serializable { @CheckForNull private transient Set<V> valueSet; @RetainedWith @CheckForNull private transient BiMap<V, K> inverse; @@ -1398,7 +1407,7 @@ final class Synchronized { private static final long serialVersionUID = 0; } - private static class SynchronizedAsMap<K extends @Nullable Object, V extends @Nullable Object> + static final class SynchronizedAsMap<K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedMap<K, Collection<V>> { @CheckForNull transient Set<Map.Entry<K, Collection<V>>> asMapEntrySet; @CheckForNull transient Collection<Collection<V>> asMapValues; @@ -1445,7 +1454,7 @@ final class Synchronized { private static final long serialVersionUID = 0; } - private static class SynchronizedAsMapValues<V extends @Nullable Object> + static final class SynchronizedAsMapValues<V extends @Nullable Object> extends SynchronizedCollection<Collection<V>> { SynchronizedAsMapValues(Collection<Collection<V>> delegate, @CheckForNull Object mutex) { super(delegate, mutex); @@ -1467,8 +1476,8 @@ final class Synchronized { @GwtIncompatible // NavigableSet @VisibleForTesting - static class SynchronizedNavigableSet<E extends @Nullable Object> extends SynchronizedSortedSet<E> - implements NavigableSet<E> { + static final class SynchronizedNavigableSet<E extends @Nullable Object> + extends SynchronizedSortedSet<E> implements NavigableSet<E> { SynchronizedNavigableSet(NavigableSet<E> delegate, @CheckForNull Object mutex) { super(delegate, mutex); } @@ -1611,7 +1620,8 @@ final class Synchronized { @GwtIncompatible // NavigableMap @VisibleForTesting - static class SynchronizedNavigableMap<K extends @Nullable Object, V extends @Nullable Object> + static final class SynchronizedNavigableMap< + K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedSortedMap<K, V> implements NavigableMap<K, V> { SynchronizedNavigableMap(NavigableMap<K, V> delegate, @CheckForNull Object mutex) { @@ -1812,7 +1822,7 @@ final class Synchronized { } @GwtIncompatible // works but is needed only for NavigableMap - private static class SynchronizedEntry<K extends @Nullable Object, V extends @Nullable Object> + static final class SynchronizedEntry<K extends @Nullable Object, V extends @Nullable Object> extends SynchronizedObject implements Map.Entry<K, V> { SynchronizedEntry(Map.Entry<K, V> delegate, @CheckForNull Object mutex) { @@ -1867,8 +1877,8 @@ final class Synchronized { return (queue instanceof SynchronizedQueue) ? queue : new SynchronizedQueue<E>(queue, mutex); } - private static class SynchronizedQueue<E extends @Nullable Object> - extends SynchronizedCollection<E> implements Queue<E> { + static class SynchronizedQueue<E extends @Nullable Object> extends SynchronizedCollection<E> + implements Queue<E> { SynchronizedQueue(Queue<E> delegate, @CheckForNull Object mutex) { super(delegate, mutex); @@ -1923,8 +1933,8 @@ final class Synchronized { return new SynchronizedDeque<E>(deque, mutex); } - private static final class SynchronizedDeque<E extends @Nullable Object> - extends SynchronizedQueue<E> implements Deque<E> { + static final class SynchronizedDeque<E extends @Nullable Object> extends SynchronizedQueue<E> + implements Deque<E> { SynchronizedDeque(Deque<E> delegate, @CheckForNull Object mutex) { super(delegate, mutex); @@ -2066,7 +2076,7 @@ final class Synchronized { return new SynchronizedTable<>(table, mutex); } - private static final class SynchronizedTable< + static final class SynchronizedTable< R extends @Nullable Object, C extends @Nullable Object, V extends @Nullable Object> extends SynchronizedObject implements Table<R, C, V> { diff --git a/guava/src/com/google/common/collect/TableCollectors.java b/guava/src/com/google/common/collect/TableCollectors.java index 16fcb1669..0257954ee 100644 --- a/guava/src/com/google/common/collect/TableCollectors.java +++ b/guava/src/com/google/common/collect/TableCollectors.java @@ -90,7 +90,7 @@ final class TableCollectors { java.util.function.Function<? super T, ? extends C> columnFunction, java.util.function.Function<? super T, ? extends V> valueFunction, java.util.function.Supplier<I> tableSupplier) { - return toTable( + return TableCollectors.<T, R, C, V, I>toTable( rowFunction, columnFunction, valueFunction, diff --git a/guava/src/com/google/common/collect/Tables.java b/guava/src/com/google/common/collect/Tables.java index 525c05355..a9d0bb654 100644 --- a/guava/src/com/google/common/collect/Tables.java +++ b/guava/src/com/google/common/collect/Tables.java @@ -77,7 +77,8 @@ public final class Tables { java.util.function.Function<? super T, ? extends C> columnFunction, java.util.function.Function<? super T, ? extends V> valueFunction, java.util.function.Supplier<I> tableSupplier) { - return TableCollectors.toTable(rowFunction, columnFunction, valueFunction, tableSupplier); + return TableCollectors.<T, R, C, V, I>toTable( + rowFunction, columnFunction, valueFunction, tableSupplier); } /** @@ -106,7 +107,7 @@ public final class Tables { java.util.function.Function<? super T, ? extends V> valueFunction, BinaryOperator<V> mergeFunction, java.util.function.Supplier<I> tableSupplier) { - return TableCollectors.toTable( + return TableCollectors.<T, R, C, V, I>toTable( rowFunction, columnFunction, valueFunction, mergeFunction, tableSupplier); } @@ -674,7 +675,7 @@ public final class Tables { return new UnmodifiableRowSortedMap<>(table); } - static final class UnmodifiableRowSortedMap< + private static final class UnmodifiableRowSortedMap< R extends @Nullable Object, C extends @Nullable Object, V extends @Nullable Object> extends UnmodifiableTable<R, C, V> implements RowSortedTable<R, C, V> { diff --git a/guava/src/com/google/common/collect/TransformedListIterator.java b/guava/src/com/google/common/collect/TransformedListIterator.java index 66b42e4c6..22b4b7c42 100644 --- a/guava/src/com/google/common/collect/TransformedListIterator.java +++ b/guava/src/com/google/common/collect/TransformedListIterator.java @@ -36,7 +36,7 @@ abstract class TransformedListIterator<F extends @Nullable Object, T extends @Nu } private ListIterator<? extends F> backingIterator() { - return Iterators.cast(backingIterator); + return (ListIterator<? extends F>) backingIterator; } @Override diff --git a/guava/src/com/google/common/collect/TreeMultiset.java b/guava/src/com/google/common/collect/TreeMultiset.java index 7efafd8ec..8024f5ebb 100644 --- a/guava/src/com/google/common/collect/TreeMultiset.java +++ b/guava/src/com/google/common/collect/TreeMultiset.java @@ -1088,7 +1088,7 @@ public final class TreeMultiset<E extends @Nullable Object> extends AbstractSort stream.defaultReadObject(); @SuppressWarnings("unchecked") // reading data stored by writeObject - Comparator<? super E> comparator = (Comparator<? super E>) stream.readObject(); + Comparator<? super E> comparator = (Comparator<? super E>) requireNonNull(stream.readObject()); Serialization.getFieldSetter(AbstractSortedMultiset.class, "comparator").set(this, comparator); Serialization.getFieldSetter(TreeMultiset.class, "range") .set(this, GeneralRange.all(comparator)); |