diff options
Diffstat (limited to 'guava/src/com/google/common/collect/ImmutableMap.java')
-rw-r--r-- | guava/src/com/google/common/collect/ImmutableMap.java | 43 |
1 files changed, 39 insertions, 4 deletions
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; } |