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

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

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

Multiset.size介绍

[英]Returns the total number of all occurrences of all elements in this multiset.

Note: this method does not return the number of distinct elements in the multiset, which is given by entrySet().size().
[中]返回此多重集中所有元素的所有引用总数。
注意:此方法不返回由entrySet()给出的multiset中不同元素的数量。大小()。

代码示例

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

@Override
public int size() {
 return IntMath.saturatedAdd(multiset1.size(), multiset2.size());
}

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

public void testCreate() {
 Multiset<String> multiset = HashMultiset.create();
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
}

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

public void testCreateWithSize() {
 Multiset<String> multiset = HashMultiset.create(50);
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
}

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

public void testCreateFromIterable() {
 Multiset<String> multiset = HashMultiset.create(Arrays.asList("foo", "bar", "foo"));
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
}

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

static <E> Spliterator<E> spliteratorImpl(Multiset<E> multiset) {
 Spliterator<Entry<E>> entrySpliterator = multiset.entrySet().spliterator();
 return CollectSpliterators.flatMap(
   entrySpliterator,
   entry -> Collections.nCopies(entry.getCount(), entry.getElement()).spliterator(),
   Spliterator.SIZED
     | (entrySpliterator.characteristics()
       & (Spliterator.ORDERED | Spliterator.NONNULL | Spliterator.IMMUTABLE)),
   multiset.size());
}

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

@CollectionSize.Require(SEVERAL)
 public void testSizeMultipleValues() {
  resetContainer(mapEntry(k0(), v0()), mapEntry(k0(), v1()), mapEntry(k0(), v2()));

  assertEquals(3, multimap().size());
  assertEquals(3, multimap().entries().size());
  assertEquals(3, multimap().keys().size());

  assertEquals(1, multimap().keySet().size());
  assertEquals(1, multimap().asMap().size());
 }
}

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

@GwtIncompatible // SerializableTester
public void testSerializationContainingSelf() {
 Multiset<Multiset<?>> multiset = HashMultiset.create();
 multiset.add(multiset, 2);
 Multiset<Multiset<?>> copy = SerializableTester.reserialize(multiset);
 assertEquals(2, copy.size());
 assertSame(copy, copy.iterator().next());
}

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

@CollectionFeature.Require(SUPPORTS_ADD)
public void testAddTooMany() {
 getMultiset().add(e3(), Integer.MAX_VALUE);
 try {
  getMultiset().add(e3());
  fail();
 } catch (IllegalArgumentException expected) {
 }
 assertEquals(Integer.MAX_VALUE, getMultiset().count(e3()));
 assertEquals(Integer.MAX_VALUE, getMultiset().size());
}

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

@GwtIncompatible // SerializableTester
public void testSerializationIndirectSelfReference() {
 Multiset<MultisetHolder> multiset = HashMultiset.create();
 MultisetHolder holder = new MultisetHolder(multiset);
 multiset.add(holder, 2);
 Multiset<MultisetHolder> copy = SerializableTester.reserialize(multiset);
 assertEquals(2, copy.size());
 assertSame(copy, copy.iterator().next().member);
}

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

public void testCreateWithComparator() {
 Multiset<String> multiset = TreeMultiset.create(Collections.reverseOrder());
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[foo x 2, bar]", multiset.toString());
}

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

public void testCreate() {
 Multiset<String> multiset = LinkedHashMultiset.create();
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[foo x 2, bar]", multiset.toString());
}

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

public void testCreateWithSize() {
 Multiset<String> multiset = LinkedHashMultiset.create(50);
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[foo x 2, bar]", multiset.toString());
}

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

public void testCreateFromIterable() {
 Multiset<String> multiset = LinkedHashMultiset.create(Arrays.asList("foo", "bar", "foo"));
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[foo x 2, bar]", multiset.toString());
}

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

public void testCreateFromIterable() {
 Multiset<String> multiset = TreeMultiset.create(Arrays.asList("foo", "bar", "foo"));
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[bar, foo x 2]", multiset.toString());
}

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

private void assertSetCount(E element, int count) {
 setCountCheckReturnValue(element, count);
 assertEquals(
   "multiset.count() should return the value passed to setCount()",
   count,
   getMultiset().count(element));
 int size = 0;
 for (Multiset.Entry<E> entry : getMultiset().entrySet()) {
  size += entry.getCount();
 }
 assertEquals(
   "multiset.size() should be the sum of the counts of all entries",
   size,
   getMultiset().size());
}

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

@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetRemoveDuplicatePropagatesToMultiset() {
 initThreeCopies();
 int size = getNumElements();
 int expectedSize = size - getMultiset().count(e0());
 Set<E> elementSet = getMultiset().elementSet();
 assertTrue(elementSet.remove(e0()));
 assertEmpty(getMultiset());
 assertEquals(expectedSize, getMultiset().size());
}

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

@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetRemovePropagatesToMultiset() {
 Set<E> elementSet = getMultiset().elementSet();
 int size = getNumElements();
 int expectedSize = size - getMultiset().count(e0());
 assertTrue(elementSet.remove(e0()));
 assertFalse(getMultiset().contains(e0()));
 assertEquals(expectedSize, getMultiset().size());
}

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

public void testEnqueueAndDispatch_multipleListeners() {
 Object listener1 = new Object();
 ListenerCallQueue<Object> queue = new ListenerCallQueue<>();
 queue.addListener(listener1, directExecutor());
 Multiset<Object> counters = ConcurrentHashMultiset.create();
 queue.enqueue(incrementingEvent(counters, listener1, 1));
 queue.enqueue(incrementingEvent(counters, listener1, 2));
 Object listener2 = new Object();
 queue.addListener(listener2, directExecutor());
 queue.enqueue(incrementingEvent(counters, multiset(listener1, 3, listener2, 1)));
 queue.enqueue(incrementingEvent(counters, multiset(listener1, 4, listener2, 2)));
 assertEquals(0, counters.size());
 queue.dispatch();
 assertEquals(multiset(listener1, 4, listener2, 2), counters);
}

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

public void testEnqueueAndDispatch() {
 Object listener = new Object();
 ListenerCallQueue<Object> queue = new ListenerCallQueue<>();
 queue.addListener(listener, directExecutor());
 Multiset<Object> counters = ConcurrentHashMultiset.create();
 queue.enqueue(incrementingEvent(counters, listener, 1));
 queue.enqueue(incrementingEvent(counters, listener, 2));
 queue.enqueue(incrementingEvent(counters, listener, 3));
 queue.enqueue(incrementingEvent(counters, listener, 4));
 assertEquals(0, counters.size());
 queue.dispatch();
 assertEquals(multiset(listener, 4), counters);
}

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

@CollectionSize.Require(SEVERAL)
public void testKeys() {
 resetContainer(
   Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
 Multiset<K> keys = multimap().keys();
 assertEquals(2, keys.count(k0()));
 assertEquals(1, keys.count(k1()));
 assertEquals(3, keys.size());
 assertContainsAllOf(keys, k0(), k1());
 assertContainsAllOf(
   keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1));
}

相关文章