本文整理了Java中com.google.common.collect.Multimap.size()
方法的一些代码示例,展示了Multimap.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multimap.size()
方法的具体详情如下:
包路径:com.google.common.collect.Multimap
类名称:Multimap
方法名:size
[英]Returns the number of key-value pairs in this multimap.
Note: this method does not return the number of distinct keys in the multimap, which is given by keySet().size() or asMap().size(). See the opening section of the Multimap class documentation for clarification.
[中]返回此多重映射中的键值对数。
注意:此方法不返回多重映射中不同键的数目,该数目由keySet()给出。大小()或asMap()。大小()。有关说明,请参见Multimap类文档的开头部分。
代码示例来源:origin: google/guava
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
public void testReplaceValuesWithEmpty() {
int size = multimap().size();
List<V> oldValues = new ArrayList<>(multimap().get(k0()));
@SuppressWarnings("unchecked")
List<V> values = Collections.emptyList();
assertEquals(oldValues, new ArrayList<V>(multimap().replaceValues(k0(), values)));
assertGet(k0());
assertEquals(size - oldValues.size(), multimap().size());
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testKeySetIteratorRemove() {
int key0Count = multimap().get(k0()).size();
Iterator<K> keyItr = multimap().keySet().iterator();
while (keyItr.hasNext()) {
if (keyItr.next().equals(k0())) {
keyItr.remove();
}
}
assertEquals(getNumElements() - key0Count, multimap().size());
assertGet(k0());
}
}
代码示例来源:origin: google/guava
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
public void testReplaceValuesWithDuplicates() {
int size = multimap().size();
List<V> oldValues = new ArrayList<>(multimap().get(k0()));
List<V> values = Arrays.asList(v0(), v3(), v0());
assertEquals(oldValues, new ArrayList<V>(multimap().replaceValues(k0(), values)));
assertEquals(size - oldValues.size() + multimap().get(k0()).size(), multimap().size());
assertTrue(multimap().get(k0()).containsAll(values));
}
代码示例来源:origin: google/guava
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
public void testPutAllNullValueNullLast_unsupported() {
int size = getNumElements();
try {
multimap().putAll(k3(), Lists.newArrayList(v3(), null));
fail();
} catch (NullPointerException expected) {
}
Collection<V> values = multimap().get(k3());
if (values.size() == 0) {
expectUnchanged();
// Be extra thorough in case internal state was corrupted by the expected null.
assertEquals(Lists.newArrayList(), Lists.newArrayList(values));
assertEquals(size, multimap().size());
} else {
assertEquals(Lists.newArrayList(v3()), Lists.newArrayList(values));
assertEquals(size + 1, multimap().size());
}
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_REMOVE)
public void testKeySetRemovePropagatesToMultimap() {
int key0Count = multimap().get(k0()).size();
assertEquals(key0Count > 0, multimap().keySet().remove(k0()));
assertEquals(getNumElements() - key0Count, multimap().size());
assertGet(k0());
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
public void testReplaceNonEmptyValues() {
List<K> keys = Helpers.copyToList(multimap().keySet());
@SuppressWarnings("unchecked")
List<V> values = Arrays.asList(v0(), v2(), v3());
for (K k : keys) {
resetContainer();
int size = multimap().size();
Collection<V> oldKeyValues = Helpers.copyToList(multimap().get(k));
multimap().replaceValues(k, values);
assertGet(k, values);
assertEquals(size + values.size() - oldKeyValues.size(), multimap().size());
}
}
代码示例来源:origin: google/guava
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
public void testPutAllNullValueNullFirst_unsupported() {
int size = getNumElements();
try {
multimap().putAll(k3(), Lists.newArrayList(null, v3()));
fail();
} catch (NullPointerException expected) {
}
/*
* In principle, a Multimap implementation could add e3 first before failing on the null. But
* that seems unlikely enough to be worth complicating the test over, especially if there's any
* chance that a permissive test could mask a bug.
*/
expectUnchanged();
// Be extra thorough in case internal state was corrupted by the expected null.
assertEquals(Lists.newArrayList(), Lists.newArrayList(multimap().get(k3())));
assertEquals(size, multimap().size());
}
代码示例来源:origin: google/guava
public void testBuilderPutAllIterable() {
ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder();
builder.putAll("foo", Arrays.asList(1, 2, 3));
builder.putAll("bar", Arrays.asList(4, 5));
builder.putAll("foo", Arrays.asList(6, 7));
Multimap<String, Integer> multimap = builder.build();
assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo"));
assertEquals(ImmutableSet.of(4, 5), multimap.get("bar"));
assertEquals(7, multimap.size());
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_PUT)
public void testPropagatesAddAllToMultimap() {
Collection<V> result = multimap().get(k0());
assertTrue(result.addAll(Collections.singletonList(v3())));
assertTrue(multimap().containsKey(k0()));
assertEquals(getNumElements() + 1, multimap().size());
assertTrue(multimap().containsEntry(k0(), v3()));
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutPresentKeyPropagatesToGet() {
List<K> keys = Helpers.copyToList(multimap().keySet());
for (K key : keys) {
resetContainer();
int size = getNumElements();
Collection<V> collection = multimap().get(key);
Collection<V> expectedCollection = Helpers.copyToList(collection);
multimap().put(key, v3());
expectedCollection.add(v3());
assertEqualIgnoringOrder(expectedCollection, collection);
assertEquals(size + 1, multimap().size());
}
}
代码示例来源:origin: google/guava
public void testBuilderPutAllIterable() {
ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
builder.putAll("foo", Arrays.asList(1, 2, 3));
builder.putAll("bar", Arrays.asList(4, 5));
builder.putAll("foo", Arrays.asList(6, 7));
Multimap<String, Integer> multimap = builder.build();
assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
assertEquals(7, multimap.size());
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_PUT)
public void testPutTwoElements() {
int size = getNumElements();
List<V> values = Helpers.copyToList(multimap().get(k0()));
assertTrue(multimap().put(k0(), v1()));
assertTrue(multimap().put(k0(), v2()));
values.add(v1());
values.add(v2());
assertGet(k0(), values);
assertEquals(size + 2, multimap().size());
}
代码示例来源:origin: google/guava
@GwtIncompatible // SerializableTester
public void testSerialization() {
Multimap<String, Integer> multimap = createMultimap();
SerializableTester.reserializeAndAssert(multimap);
assertEquals(multimap.size(), SerializableTester.reserialize(multimap).size());
SerializableTester.reserializeAndAssert(multimap.get("foo"));
LenientSerializableTester.reserializeAndAssertLenient(multimap.keySet());
LenientSerializableTester.reserializeAndAssertLenient(multimap.keys());
SerializableTester.reserializeAndAssert(multimap.asMap());
Collection<Integer> valuesCopy = SerializableTester.reserialize(multimap.values());
assertEquals(HashMultiset.create(multimap.values()), HashMultiset.create(valuesCopy));
}
代码示例来源:origin: google/guava
public void testBuilderPutAllMultimapWithDuplicates() {
Multimap<String, Integer> toPut = LinkedListMultimap.create();
toPut.put("foo", 1);
toPut.put("bar", 4);
toPut.put("foo", 2);
toPut.put("foo", 1);
toPut.put("bar", 5);
Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
moreToPut.put("foo", 6);
moreToPut.put("bar", 4);
moreToPut.put("foo", 7);
moreToPut.put("foo", 2);
ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
builder.putAll(toPut);
builder.putAll(moreToPut);
Multimap<String, Integer> multimap = builder.build();
assertEquals(Arrays.asList(1, 2, 1, 6, 7, 2), multimap.get("foo"));
assertEquals(Arrays.asList(4, 5, 4), multimap.get("bar"));
assertEquals(9, multimap.size());
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_PUT)
public void testPutNotPresentKeyPropagatesToGet() {
int size = getNumElements();
Collection<V> collection = multimap().get(k3());
assertEmpty(collection);
multimap().put(k3(), v3());
assertContains(collection, v3());
assertEquals(size + 1, multimap().size());
}
代码示例来源:origin: google/guava
public void testBuilderPutAllMultimap() {
Multimap<String, Integer> toPut = LinkedListMultimap.create();
toPut.put("foo", 1);
toPut.put("bar", 4);
toPut.put("foo", 2);
toPut.put("foo", 3);
Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
moreToPut.put("foo", 6);
moreToPut.put("bar", 5);
moreToPut.put("foo", 7);
ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder();
builder.putAll(toPut);
builder.putAll(moreToPut);
Multimap<String, Integer> multimap = builder.build();
assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo"));
assertEquals(ImmutableSet.of(4, 5), multimap.get("bar"));
assertEquals(7, multimap.size());
}
代码示例来源:origin: google/guava
@GwtIncompatible // SerializableTester
public void testSerialization() {
Multimap<String, Integer> multimap = createMultimap();
SerializableTester.reserializeAndAssert(multimap);
assertEquals(multimap.size(), SerializableTester.reserialize(multimap).size());
SerializableTester.reserializeAndAssert(multimap.get("foo"));
LenientSerializableTester.reserializeAndAssertLenient(multimap.keySet());
LenientSerializableTester.reserializeAndAssertLenient(multimap.keys());
SerializableTester.reserializeAndAssert(multimap.asMap());
Collection<Integer> valuesCopy = SerializableTester.reserialize(multimap.values());
assertEquals(HashMultiset.create(multimap.values()), HashMultiset.create(valuesCopy));
}
代码示例来源:origin: google/guava
public void testBuilderPutAllMultimap() {
Multimap<String, Integer> toPut = LinkedListMultimap.create();
toPut.put("foo", 1);
toPut.put("bar", 4);
toPut.put("foo", 2);
toPut.put("foo", 3);
Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
moreToPut.put("foo", 6);
moreToPut.put("bar", 5);
moreToPut.put("foo", 7);
ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
builder.putAll(toPut);
builder.putAll(moreToPut);
Multimap<String, Integer> multimap = builder.build();
assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
assertEquals(7, multimap.size());
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
for (TripPattern pattern : graph.index.patternsForStop.get(stop)) {
closest.putMin(new T2(pattern, stopDist.qmode), stopDist);
if (result.size() > MAX_PATTERNS) {
LOG.warn("Excessively long list of patterns. {} patterns, max allowed is {}.", closest.size(), MAX_PATTERNS);
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_PUT)
public void testPropagatesAddToMultimap() {
Collection<V> result = multimap().get(k0());
assertTrue(result.add(v3()));
assertTrue(multimap().containsKey(k0()));
assertEquals(getNumElements() + 1, multimap().size());
assertTrue(multimap().containsEntry(k0(), v3()));
}
内容来源于网络,如有侵权,请联系作者删除!