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

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

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

Multimap.containsEntry介绍

[英]Returns true if this multimap contains at least one key-value pair with the key key and the value value.
[中]如果此多重映射至少包含一个具有键和值的键值对,则返回true。

代码示例

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

@Override
public boolean containsEntry(Object key, Object value) {
 synchronized (mutex) {
  return delegate().containsEntry(key, value);
 }
}

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

@Override
public boolean contains(@Nullable Object o) {
 if (o instanceof Map.Entry) {
  Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
  return multimap().containsEntry(entry.getKey(), entry.getValue());
 }
 return false;
}

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

public void testContainsEntryAgreesWithGet() {
 for (K k : sampleKeys()) {
  for (V v : sampleValues()) {
   assertEquals(multimap().get(k).contains(v), multimap().containsEntry(k, v));
  }
 }
}

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

@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
public void testAddNullValue() {
 Collection<V> result = multimap().asMap().get(k0());
 assertTrue(result.add(null));
 assertTrue(multimap().containsEntry(k0(), null));
}

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

@MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
 public void testContainsEntryNullDisallowedBecauseValueQueriesDisallowed() {
  try {
   multimap().containsEntry(k3(), null);
   fail("Expected NullPointerException");
  } catch (NullPointerException expected) {
   // success
  }
 }
}

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

@MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
public void testContainsEntryNullDisallowedBecauseKeyQueriesDisallowed() {
 try {
  multimap().containsEntry(null, v3());
  fail("Expected NullPointerException");
 } catch (NullPointerException expected) {
  // success
 }
}

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

public void testFilterKeys() {
 Multimap<String, Integer> unfiltered = HashMultimap.create();
 unfiltered.put("foo", 55556);
 unfiltered.put("badkey", 1);
 Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
 assertEquals(1, filtered.size());
 assertTrue(filtered.containsEntry("foo", 55556));
}

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

public void testFilterFiltered() {
 Multimap<String, Integer> unfiltered = HashMultimap.create();
 unfiltered.put("foo", 55556);
 unfiltered.put("badkey", 1);
 unfiltered.put("foo", 1);
 Multimap<String, Integer> keyFiltered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
 Multimap<String, Integer> filtered = Multimaps.filterValues(keyFiltered, VALUE_PREDICATE);
 assertEquals(1, filtered.size());
 assertTrue(filtered.containsEntry("foo", 1));
 assertTrue(filtered.keySet().retainAll(Arrays.asList("cat", "dog")));
 assertEquals(0, filtered.size());
}

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

@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES})
public void testContainsEntryNullYes() {
 initMultimapWithNullKeyAndValue();
 assertTrue(multimap().containsEntry(null, null));
}

代码示例来源: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)
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()));
}

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

public void testUnmodifiableMultimapIsView() {
 Multimap<String, Integer> mod = HashMultimap.create();
 Multimap<String, Integer> unmod = Multimaps.unmodifiableMultimap(mod);
 assertEquals(mod, unmod);
 mod.put("foo", 1);
 assertTrue(unmod.containsEntry("foo", 1));
 assertEquals(mod, unmod);
}

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

@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
public void testPutAllWithNullValue() {
 Multimap<K, V> source = getSubjectGenerator().create(Helpers.mapEntry(k0(), null));
 assertTrue(multimap().putAll(source));
 assertTrue(multimap().containsEntry(k0(), null));
}

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

@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testRetainAllPropagatesToMultimap() {
 multimap().entries().retainAll(Collections.singleton(Helpers.mapEntry(k0(), v0())));
 assertEquals(getSubjectGenerator().create(Helpers.mapEntry(k0(), v0())), multimap());
 assertEquals(1, multimap().size());
 assertTrue(multimap().containsEntry(k0(), v0()));
}

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

@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS})
public void testPutAllWithNullKey() {
 Multimap<K, V> source = getSubjectGenerator().create(Helpers.mapEntry(null, v0()));
 assertTrue(multimap().putAll(source));
 assertTrue(multimap().containsEntry(null, v0()));
}

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

@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testRemovePresent() {
 assertTrue(multimap().remove(k0(), v0()));
 assertFalse(multimap().containsEntry(k0(), v0()));
 expectMissing(e0());
 assertEquals(getNumElements() - 1, multimap().size());
 assertGet(k0(), ImmutableList.<V>of());
}

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

@MapFeature.Require(SUPPORTS_PUT)
public void testPutAll() {
 Multimap<K, V> source =
   getSubjectGenerator().create(Helpers.mapEntry(k0(), v3()), Helpers.mapEntry(k3(), v3()));
 assertTrue(multimap().putAll(source));
 assertTrue(multimap().containsEntry(k0(), v3()));
 assertTrue(multimap().containsEntry(k3(), v3()));
}

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

@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testRemovePropagatesToMultimap() {
 assertTrue(multimap().entries().remove(Helpers.mapEntry(k0(), v0())));
 expectMissing(Helpers.mapEntry(k0(), v0()));
 assertEquals(getNumElements() - 1, multimap().size());
 assertFalse(multimap().containsEntry(k0(), v0()));
}

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

@CollectionSize.Require(SEVERAL)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testPropagatesRemoveToMultimap() {
 resetContainer(
   Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v3()), Helpers.mapEntry(k0(), v2()));
 Collection<V> result = multimap().asMap().get(k0());
 assertTrue(result.remove(v0()));
 assertFalse(multimap().containsEntry(k0(), v0()));
 assertEquals(2, multimap().size());
}

代码示例来源: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()));
 }
}

相关文章