com.google.common.collect.Multiset.addAll()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中com.google.common.collect.Multiset.addAll()方法的一些代码示例,展示了Multiset.addAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multiset.addAll()方法的具体详情如下:
包路径:com.google.common.collect.Multiset
类名称:Multiset
方法名:addAll

Multiset.addAll介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

  1. @Override
  2. public void aggregate(LanguageDistributionCounter counter) {
  3. multiset.addAll(counter.multiset);
  4. }

代码示例来源:origin: google/guava

  1. /**
  2. * Returns a {@code Collector} that accumulates elements into a multiset created via the specified
  3. * {@code Supplier}, whose elements are the result of applying {@code elementFunction} to the
  4. * inputs, with counts equal to the result of applying {@code countFunction} to the inputs.
  5. * Elements are added in encounter order.
  6. *
  7. * <p>If the mapped elements contain duplicates (according to {@link Object#equals}), the element
  8. * will be added more than once, with the count summed over all appearances of the element.
  9. *
  10. * <p>Note that {@code stream.collect(toMultiset(function, e -> 1, supplier))} is equivalent to
  11. * {@code stream.map(function).collect(Collectors.toCollection(supplier))}.
  12. *
  13. * @since 22.0
  14. */
  15. public static <T, E, M extends Multiset<E>> Collector<T, ?, M> toMultiset(
  16. java.util.function.Function<? super T, E> elementFunction,
  17. java.util.function.ToIntFunction<? super T> countFunction,
  18. java.util.function.Supplier<M> multisetSupplier) {
  19. checkNotNull(elementFunction);
  20. checkNotNull(countFunction);
  21. checkNotNull(multisetSupplier);
  22. return Collector.of(
  23. multisetSupplier,
  24. (ms, t) -> ms.add(elementFunction.apply(t), countFunction.applyAsInt(t)),
  25. (ms1, ms2) -> {
  26. ms1.addAll(ms2);
  27. return ms1;
  28. });
  29. }

代码示例来源:origin: SonarSource/sonarqube

  1. void add(Counter counter) {
  2. unresolved += counter.unresolved;
  3. open += counter.open;
  4. reopened += counter.reopened;
  5. confirmed += counter.confirmed;
  6. falsePositives += counter.falsePositives;
  7. wontFix += counter.wontFix;
  8. severityBag.addAll(counter.severityBag);
  9. typeBag.addAll(counter.typeBag);
  10. }

代码示例来源:origin: goldmansachs/gs-collections

  1. @Benchmark
  2. public void guava()
  3. {
  4. Multiset<Integer> result = HashMultiset.create();
  5. for (int i = 0; i < 1000; i++)
  6. {
  7. result.addAll(this.integersGuava);
  8. }
  9. }

代码示例来源:origin: google/guava

  1. /**
  2. * Returns a {@code Collector} that accumulates elements into an {@code ImmutableMultiset} whose
  3. * elements are the result of applying {@code elementFunction} to the inputs, with counts equal to
  4. * the result of applying {@code countFunction} to the inputs.
  5. *
  6. * <p>If the mapped elements contain duplicates (according to {@link Object#equals}), the first
  7. * occurrence in encounter order appears in the resulting multiset, with count equal to the sum of
  8. * the outputs of {@code countFunction.applyAsInt(t)} for each {@code t} mapped to that element.
  9. *
  10. * @since 22.0
  11. */
  12. public static <T, E> Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset(
  13. Function<? super T, ? extends E> elementFunction, ToIntFunction<? super T> countFunction) {
  14. checkNotNull(elementFunction);
  15. checkNotNull(countFunction);
  16. return Collector.of(
  17. LinkedHashMultiset::create,
  18. (multiset, t) ->
  19. multiset.add(checkNotNull(elementFunction.apply(t)), countFunction.applyAsInt(t)),
  20. (multiset1, multiset2) -> {
  21. multiset1.addAll(multiset2);
  22. return multiset1;
  23. },
  24. (Multiset<E> multiset) -> copyFromEntries(multiset.entrySet()));
  25. }

代码示例来源:origin: google/guava

  1. /**
  2. * Returns a {@code Collector} that accumulates elements into an {@code ImmutableSortedMultiset}
  3. * whose elements are the result of applying {@code elementFunction} to the inputs, with counts
  4. * equal to the result of applying {@code countFunction} to the inputs.
  5. *
  6. * <p>If the mapped elements contain duplicates (according to {@code comparator}), the first
  7. * occurrence in encounter order appears in the resulting multiset, with count equal to the sum of
  8. * the outputs of {@code countFunction.applyAsInt(t)} for each {@code t} mapped to that element.
  9. *
  10. * @since 22.0
  11. */
  12. public static <T, E> Collector<T, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset(
  13. Comparator<? super E> comparator,
  14. Function<? super T, ? extends E> elementFunction,
  15. ToIntFunction<? super T> countFunction) {
  16. checkNotNull(comparator);
  17. checkNotNull(elementFunction);
  18. checkNotNull(countFunction);
  19. return Collector.of(
  20. () -> TreeMultiset.create(comparator),
  21. (multiset, t) ->
  22. multiset.add(checkNotNull(elementFunction.apply(t)), countFunction.applyAsInt(t)),
  23. (multiset1, multiset2) -> {
  24. multiset1.addAll(multiset2);
  25. return multiset1;
  26. },
  27. (Multiset<E> multiset) -> copyOfSortedEntries(comparator, multiset.entrySet()));
  28. }

代码示例来源:origin: google/guava

  1. @CollectionFeature.Require(SUPPORTS_ADD)
  2. public void testAddAll_emptySet() {
  3. assertFalse(getMultiset().addAll(Collections.<E>emptySet()));
  4. expectUnchanged();
  5. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Returns a {@code Collector} that accumulates elements into a multiset created via the specified
  3. * {@code Supplier}, whose elements are the result of applying {@code elementFunction} to the
  4. * inputs, with counts equal to the result of applying {@code countFunction} to the inputs.
  5. * Elements are added in encounter order.
  6. *
  7. * <p>If the mapped elements contain duplicates (according to {@link Object#equals}), the element
  8. * will be added more than once, with the count summed over all appearances of the element.
  9. *
  10. * <p>Note that {@code stream.collect(toMultiset(function, e -> 1, supplier))} is equivalent to
  11. * {@code stream.map(function).collect(Collectors.toCollection(supplier))}.
  12. *
  13. * @since 22.0
  14. */
  15. public static <T, E, M extends Multiset<E>> Collector<T, ?, M> toMultiset(
  16. java.util.function.Function<? super T, E> elementFunction,
  17. java.util.function.ToIntFunction<? super T> countFunction,
  18. java.util.function.Supplier<M> multisetSupplier) {
  19. checkNotNull(elementFunction);
  20. checkNotNull(countFunction);
  21. checkNotNull(multisetSupplier);
  22. return Collector.of(
  23. multisetSupplier,
  24. (ms, t) -> ms.add(elementFunction.apply(t), countFunction.applyAsInt(t)),
  25. (ms1, ms2) -> {
  26. ms1.addAll(ms2);
  27. return ms1;
  28. });
  29. }

代码示例来源:origin: google/guava

  1. @Override
  2. protected Multiset<String> create(String[] elements) {
  3. Multiset<String> multiset = LinkedHashMultiset.create();
  4. Collections.addAll(multiset, elements);
  5. multiset.addAll(ELEMENTS_TO_FILTER_OUT);
  6. return Multisets.filter(multiset, PREDICATE);
  7. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Returns a {@code Collector} that accumulates elements into an {@code ImmutableMultiset} whose
  3. * elements are the result of applying {@code elementFunction} to the inputs, with counts equal to
  4. * the result of applying {@code countFunction} to the inputs.
  5. *
  6. * <p>If the mapped elements contain duplicates (according to {@link Object#equals}), the first
  7. * occurrence in encounter order appears in the resulting multiset, with count equal to the sum of
  8. * the outputs of {@code countFunction.applyAsInt(t)} for each {@code t} mapped to that element.
  9. *
  10. * @since 22.0
  11. */
  12. public static <T, E> Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset(
  13. Function<? super T, ? extends E> elementFunction, ToIntFunction<? super T> countFunction) {
  14. checkNotNull(elementFunction);
  15. checkNotNull(countFunction);
  16. return Collector.of(
  17. LinkedHashMultiset::create,
  18. (multiset, t) ->
  19. multiset.add(checkNotNull(elementFunction.apply(t)), countFunction.applyAsInt(t)),
  20. (multiset1, multiset2) -> {
  21. multiset1.addAll(multiset2);
  22. return multiset1;
  23. },
  24. (Multiset<E> multiset) -> copyFromEntries(multiset.entrySet()));
  25. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Returns a {@code Collector} that accumulates elements into an {@code ImmutableSortedMultiset}
  3. * whose elements are the result of applying {@code elementFunction} to the inputs, with counts
  4. * equal to the result of applying {@code countFunction} to the inputs.
  5. *
  6. * <p>If the mapped elements contain duplicates (according to {@code comparator}), the first
  7. * occurrence in encounter order appears in the resulting multiset, with count equal to the sum of
  8. * the outputs of {@code countFunction.applyAsInt(t)} for each {@code t} mapped to that element.
  9. *
  10. * @since 22.0
  11. */
  12. public static <T, E> Collector<T, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset(
  13. Comparator<? super E> comparator,
  14. Function<? super T, ? extends E> elementFunction,
  15. ToIntFunction<? super T> countFunction) {
  16. checkNotNull(comparator);
  17. checkNotNull(elementFunction);
  18. checkNotNull(countFunction);
  19. return Collector.of(
  20. () -> TreeMultiset.create(comparator),
  21. (multiset, t) ->
  22. multiset.add(checkNotNull(elementFunction.apply(t)), countFunction.applyAsInt(t)),
  23. (multiset1, multiset2) -> {
  24. multiset1.addAll(multiset2);
  25. return multiset1;
  26. },
  27. (Multiset<E> multiset) -> copyOfSortedEntries(comparator, multiset.entrySet()));
  28. }

代码示例来源:origin: google/guava

  1. @CollectionFeature.Require(SUPPORTS_ADD)
  2. public void testAddAll_emptyMultiset() {
  3. assertFalse(getMultiset().addAll(getSubjectGenerator().create()));
  4. expectUnchanged();
  5. }

代码示例来源:origin: google/guava

  1. @CollectionFeature.Require(SUPPORTS_ADD)
  2. public void testAddAll_nonEmptyList() {
  3. assertTrue(getMultiset().addAll(Arrays.asList(e3(), e4(), e3())));
  4. expectAdded(e3(), e4(), e3());
  5. }

代码示例来源:origin: google/guava

  1. public void testFastAddAllMultiset() {
  2. final AtomicInteger addCalls = new AtomicInteger();
  3. Multiset<String> multiset =
  4. new NoRemoveMultiset<String>() {
  5. @Override
  6. public int add(String element, int occurrences) {
  7. addCalls.incrementAndGet();
  8. return super.add(element, occurrences);
  9. }
  10. };
  11. ImmutableMultiset<String> adds =
  12. new ImmutableMultiset.Builder<String>().addCopies("x", 10).build();
  13. multiset.addAll(adds);
  14. assertEquals(1, addCalls.get());
  15. }

代码示例来源:origin: google/guava

  1. @CollectionFeature.Require(SUPPORTS_ADD)
  2. public void testAddAll_nonEmptyMultiset() {
  3. assertTrue(getMultiset().addAll(getSubjectGenerator().create(e3(), e4(), e3())));
  4. expectAdded(e3(), e4(), e3());
  5. }
  6. }

代码示例来源:origin: linkedin/indextank-engine

  1. public static Map<String, Multiset<String>> mergeFacets(Map<String, Multiset<String>> facets1, Map<String, Multiset<String>> facets2) {
  2. Map<String, Multiset<String>> result = Maps.newHashMap();
  3. Set<String> facets1Cats = facets1.keySet();
  4. for (String category : facets1Cats) {
  5. Multiset<String> facet1 = HashMultiset.create(facets1.get(category));
  6. Multiset<String> facet2 = facets2.get(category);
  7. if (facet2 != null) {
  8. facet1.addAll(facet2);
  9. }
  10. result.put(category, facet1);
  11. }
  12. Set<String> facets2Cats = facets2.keySet();
  13. for (String category : facets2Cats) {
  14. if (!result.containsKey(category)) {
  15. result.put(category, HashMultiset.create(facets2.get(category)));
  16. }
  17. }
  18. return result;
  19. }
  20. }

代码示例来源:origin: OpenGamma/Strata

  1. @Override
  2. public Set<String> tokens(Iterable<?> iterable) {
  3. Multiset<String> tokens = HashMultiset.create();
  4. int index = 0;
  5. for (Object item : iterable) {
  6. tokens.add(String.valueOf(index++));
  7. tokens.addAll(fieldValues(item));
  8. }
  9. return tokens.stream()
  10. .filter(token -> tokens.count(token) == 1)
  11. .collect(toImmutableSet());
  12. }

代码示例来源:origin: com.google.guava/guava-testlib

  1. @CollectionFeature.Require(SUPPORTS_ADD)
  2. public void testAddAll_emptyMultiset() {
  3. assertFalse(getMultiset().addAll(getSubjectGenerator().create()));
  4. expectUnchanged();
  5. }

代码示例来源:origin: com.google.guava/guava-testlib

  1. @CollectionFeature.Require(SUPPORTS_ADD)
  2. public void testAddAll_nonEmptyList() {
  3. assertTrue(getMultiset().addAll(Arrays.asList(e3(), e4(), e3())));
  4. expectAdded(e3(), e4(), e3());
  5. }

代码示例来源:origin: com.google.guava/guava-testlib

  1. @CollectionFeature.Require(SUPPORTS_ADD)
  2. public void testAddAll_nonEmptyMultiset() {
  3. assertTrue(getMultiset().addAll(getSubjectGenerator().create(e3(), e4(), e3())));
  4. expectAdded(e3(), e4(), e3());
  5. }
  6. }

相关文章