aboutsummaryrefslogtreecommitdiff
path: root/android/guava/src/com/google/common/collect/ImmutableBiMap.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava/src/com/google/common/collect/ImmutableBiMap.java')
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableBiMap.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/android/guava/src/com/google/common/collect/ImmutableBiMap.java b/android/guava/src/com/google/common/collect/ImmutableBiMap.java
index 30e293ebf..d18d5b6f1 100644
--- a/android/guava/src/com/google/common/collect/ImmutableBiMap.java
+++ b/android/guava/src/com/google/common/collect/ImmutableBiMap.java
@@ -29,7 +29,12 @@ import java.util.Arrays;
import java.util.Collection;
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;
import javax.annotation.CheckForNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* A {@link BiMap} whose contents will never change, with many other important properties detailed
@@ -43,6 +48,24 @@ import javax.annotation.CheckForNull;
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
+ * and values are the result of applying the provided mapping functions to the input elements.
+ * Entries appear in the result {@code ImmutableBiMap} in encounter order.
+ *
+ * <p>If the mapped keys or values contain duplicates (according to {@link
+ * Object#equals(Object)}), an {@code IllegalArgumentException} is thrown when the collection
+ * operation is performed. (This differs from the {@code Collector} returned by {@link
+ * Collectors#toMap(Function, Function)}, which throws an {@code IllegalStateException}.)
+ */
+ @SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
+ @IgnoreJRERequirement // Users will use this only if they're already using streams.
+ static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableBiMap<K, V>> toImmutableBiMap(
+ Function<? super T, ? extends K> keyFunction,
+ Function<? super T, ? extends V> valueFunction) {
+ return CollectCollectors.toImmutableBiMap(keyFunction, valueFunction);
+ }
+
+ /**
* Returns the empty bimap.
*
* <p><b>Performance note:</b> the instance returned is a singleton.
@@ -591,4 +614,42 @@ public abstract class ImmutableBiMap<K, V> extends ImmutableMap<K, V> implements
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")
+ @SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
+ @IgnoreJRERequirement // Users will use this only if they're already using streams.
+ 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")
+ @SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
+ @IgnoreJRERequirement // Users will use this only if they're already using streams.
+ 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 = 0xdecaf;
}