aboutsummaryrefslogtreecommitdiff
path: root/android/guava/src/com/google/common/collect/Tables.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava/src/com/google/common/collect/Tables.java')
-rw-r--r--android/guava/src/com/google/common/collect/Tables.java61
1 files changed, 60 insertions, 1 deletions
diff --git a/android/guava/src/com/google/common/collect/Tables.java b/android/guava/src/com/google/common/collect/Tables.java
index 513404de1..cca3d0c3a 100644
--- a/android/guava/src/com/google/common/collect/Tables.java
+++ b/android/guava/src/com/google/common/collect/Tables.java
@@ -33,6 +33,8 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
+import java.util.function.BinaryOperator;
+import java.util.stream.Collector;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -52,6 +54,63 @@ public final class Tables {
private Tables() {}
/**
+ * Returns a {@link Collector} that accumulates elements into a {@code Table} created using the
+ * specified supplier, whose cells are generated by applying the provided mapping functions to the
+ * input elements. Cells are inserted into the generated {@code Table} in encounter order.
+ *
+ * <p>If multiple input elements map to the same row and column, an {@code IllegalStateException}
+ * is thrown when the collection operation is performed.
+ *
+ * <p>To collect to an {@link ImmutableTable}, use {@link ImmutableTable#toImmutableTable}.
+ */
+ @SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
+ @IgnoreJRERequirement // Users will use this only if they're already using streams.
+ static <
+ T extends @Nullable Object,
+ R extends @Nullable Object,
+ C extends @Nullable Object,
+ V extends @Nullable Object,
+ I extends Table<R, C, V>>
+ Collector<T, ?, I> toTable(
+ java.util.function.Function<? super T, ? extends R> rowFunction,
+ 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.<T, R, C, V, I>toTable(
+ rowFunction, columnFunction, valueFunction, tableSupplier);
+ }
+
+ /**
+ * Returns a {@link Collector} that accumulates elements into a {@code Table} created using the
+ * specified supplier, whose cells are generated by applying the provided mapping functions to the
+ * input elements. Cells are inserted into the generated {@code Table} in encounter order.
+ *
+ * <p>If multiple input elements map to the same row and column, the specified merging function is
+ * used to combine the values. Like {@link
+ * java.util.stream.Collectors#toMap(java.util.function.Function, java.util.function.Function,
+ * BinaryOperator, java.util.function.Supplier)}, this Collector throws a {@code
+ * NullPointerException} on null values returned from {@code valueFunction}, and treats nulls
+ * returned from {@code mergeFunction} as removals of that row/column pair.
+ */
+ @SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
+ @IgnoreJRERequirement // Users will use this only if they're already using streams.
+ static <
+ T extends @Nullable Object,
+ R extends @Nullable Object,
+ C extends @Nullable Object,
+ V extends @Nullable Object,
+ I extends Table<R, C, V>>
+ Collector<T, ?, I> toTable(
+ java.util.function.Function<? super T, ? extends R> rowFunction,
+ java.util.function.Function<? super T, ? extends C> columnFunction,
+ java.util.function.Function<? super T, ? extends V> valueFunction,
+ BinaryOperator<V> mergeFunction,
+ java.util.function.Supplier<I> tableSupplier) {
+ return TableCollectors.<T, R, C, V, I>toTable(
+ rowFunction, columnFunction, valueFunction, mergeFunction, tableSupplier);
+ }
+
+ /**
* Returns an immutable cell with the specified row key, column key, and value.
*
* <p>The returned cell is serializable.
@@ -602,7 +661,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> {