diff options
Diffstat (limited to 'android/guava/src/com/google/common/collect/ImmutableMultiset.java')
-rw-r--r-- | android/guava/src/com/google/common/collect/ImmutableMultiset.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/android/guava/src/com/google/common/collect/ImmutableMultiset.java b/android/guava/src/com/google/common/collect/ImmutableMultiset.java index ecb8ae45b..b5e2e347e 100644 --- a/android/guava/src/com/google/common/collect/ImmutableMultiset.java +++ b/android/guava/src/com/google/common/collect/ImmutableMultiset.java @@ -33,6 +33,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.Set; +import java.util.function.Function; +import java.util.function.ToIntFunction; +import java.util.stream.Collector; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -56,6 +59,34 @@ import org.checkerframework.checker.nullness.qual.Nullable; @ElementTypesAreNonnullByDefault public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializationDependencies<E> implements Multiset<E> { + + /** + * Returns a {@code Collector} that accumulates the input elements into a new {@code + * ImmutableMultiset}. Elements iterate in order by the <i>first</i> appearance of that element in + * encounter order. + */ + @SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"}) + @IgnoreJRERequirement // Users will use this only if they're already using streams. + static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() { + return CollectCollectors.toImmutableMultiset(Function.identity(), e -> 1); + } + + /** + * Returns a {@code Collector} that accumulates elements into an {@code ImmutableMultiset} whose + * elements are the result of applying {@code elementFunction} to the inputs, with counts equal to + * the result of applying {@code countFunction} to the inputs. + * + * <p>If the mapped elements contain duplicates (according to {@link Object#equals}), the first + * occurrence in encounter order appears in the resulting multiset, with count equal to the sum of + * the outputs of {@code countFunction.applyAsInt(t)} for each {@code t} mapped to that element. + */ + @SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"}) + @IgnoreJRERequirement // Users will use this only if they're already using streams. + static <T extends @Nullable Object, E> Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset( + Function<? super T, ? extends E> elementFunction, ToIntFunction<? super T> countFunction) { + return CollectCollectors.toImmutableMultiset(elementFunction, countFunction); + } + /** * Returns the empty immutable multiset. * @@ -636,4 +667,6 @@ public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializa return new RegularImmutableMultiset<E>(contents); } } + + private static final long serialVersionUID = 0xdecaf; } |