本文整理了Java中com.google.common.collect.Multimap.keys()
方法的一些代码示例,展示了Multimap.keys()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multimap.keys()
方法的具体详情如下:
包路径:com.google.common.collect.Multimap
类名称:Multimap
方法名:keys
[英]Returns a view collection containing the key from each key-value pair in this multimap, without collapsing duplicates. This collection has the same size as this multimap, and keys().count(k) == get(k).size() for all k.
Changes to the returned multiset will update the underlying multimap, and vice versa. However, adding to the returned collection is not possible.
[中]返回一个视图集合,其中包含此多重映射中每个键值对的键,而不折叠重复项。此集合的大小与此多重映射和键()相同。计数(k)=获取(k)。尺寸()适合所有k。
对返回的multiset的更改将更新基础multimap,反之亦然。但是,无法添加到返回的集合中。
代码示例来源:origin: google/guava
@Override
Multiset<K> createKeys() {
return fromMultimap.keys();
}
代码示例来源:origin: google/guava
@Override
public Multiset<K> keys() {
Multiset<K> result = keys;
if (result == null) {
keys = result = Multisets.unmodifiableMultiset(delegate.keys());
}
return result;
}
代码示例来源:origin: google/guava
@Override
Multiset<K> createKeys() {
return Multisets.filter(unfiltered.keys(), keyPredicate);
}
}
代码示例来源:origin: google/guava
@Override
public Multiset<K> keys() {
return delegate().keys();
}
代码示例来源:origin: google/guava
@Override
protected void verify(List<String> elements) {
assertEquals(elements, Lists.newArrayList(multimap.keys()));
}
}.test();
代码示例来源:origin: google/guava
@Override
protected void verify(List<String> elements) {
assertEquals(elements, Lists.newArrayList(multimap.keys()));
}
}.test();
代码示例来源:origin: google/guava
@Override
public Multiset<K> keys() {
synchronized (mutex) {
if (keys == null) {
keys = multiset(delegate().keys(), mutex);
}
return keys;
}
}
代码示例来源:origin: google/guava
@Override
protected Iterator<String> newTargetIterator() {
multimap = LinkedHashMultimap.create();
multimap.putAll("foo", asList(2, 3));
multimap.putAll("bar", asList(4, 5));
multimap.putAll("foo", asList(6));
return multimap.keys().iterator();
}
代码示例来源:origin: google/guava
@Override
protected Iterator<String> newTargetIterator() {
multimap = create();
multimap.putAll("foo", asList(2, 3));
multimap.putAll("bar", asList(4, 5));
multimap.putAll("foo", asList(6));
return multimap.keys().iterator();
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_REMOVE)
public void testKeysRemove() {
int original = multimap().keys().remove(k0(), 1);
assertEquals(Math.max(original - 1, 0), multimap().get(k0()).size());
}
代码示例来源:origin: google/guava
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testKeysEntrySetIteratorRemove() {
Multiset<K> keys = multimap().keys();
Iterator<Multiset.Entry<K>> itr = keys.entrySet().iterator();
assertEquals(Multisets.immutableEntry(k0(), 1), itr.next());
itr.remove();
assertTrue(multimap().isEmpty());
}
代码示例来源:origin: google/guava
@MapFeature.Require(SUPPORTS_REMOVE)
public void testClearThroughKeys() {
multimap().keys().clear();
assertCleared();
}
代码示例来源:origin: google/guava
@MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
public void testKeysCountAbsentNullKey() {
assertEquals(0, multimap().keys().count(null));
}
代码示例来源:origin: google/guava
public void testLinkedKeys() {
Multimap<String, Integer> map = create();
map.put("bar", 1);
map.put("foo", 2);
map.put("bar", 3);
map.put("bar", 4);
assertEquals("[bar=1, foo=2, bar=3, bar=4]", map.entries().toString());
assertThat(map.keys()).containsExactly("bar", "foo", "bar", "bar").inOrder();
map.keys().remove("bar"); // bar is no longer the first key!
assertEquals("{foo=[2], bar=[3, 4]}", map.toString());
}
代码示例来源: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 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
@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 testKeysToString_ordering() {
Multimap<String, Integer> multimap = initializeMultimap5();
assertEquals("[foo x 2, bar x 2, cow]", multimap.keys().toString());
}
代码示例来源:origin: google/guava
@CollectionSize.Require(SEVERAL)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testKeysEntrySetRemove() {
resetContainer(
Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
assertTrue(multimap().keys().entrySet().remove(Multisets.immutableEntry(k0(), 2)));
assertEquals(1, multimap().size());
assertTrue(multimap().containsEntry(k1(), v0()));
}
}
代码示例来源: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));
}
内容来源于网络,如有侵权,请联系作者删除!