本文整理了Java中com.google.common.collect.Multiset.contains()
方法的一些代码示例,展示了Multiset.contains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multiset.contains()
方法的具体详情如下:
包路径:com.google.common.collect.Multiset
类名称:Multiset
方法名:contains
[英]Determines whether this multiset contains the specified element.
This method refines Collection#contains to further specify that it may not throw an exception in response to element being null or of the wrong type.
[中]确定此多重集是否包含指定的元素。
此方法细化了集合#contains,以进一步指定它可能不会在元素为null或类型错误时引发异常。
代码示例来源:origin: google/guava
@Override
public boolean contains(@Nullable Object element) {
return multiset1.contains(element) || multiset2.contains(element);
}
代码示例来源:origin: google/guava
@Override
public boolean contains(@Nullable Object element) {
return multiset1.contains(element) || multiset2.contains(element);
}
代码示例来源:origin: google/guava
@Override
@GuardedBy("ServiceManagerState.this.monitor")
public boolean isSatisfied() {
// All services have started or some service has terminated/failed.
return states.count(RUNNING) == numberOfServices
|| states.contains(STOPPING)
|| states.contains(TERMINATED)
|| states.contains(FAILED);
}
}
代码示例来源:origin: google/guava
@Override
public boolean contains(@Nullable Object object) {
return delegate.contains(object);
}
代码示例来源:origin: google/guava
@Override
public boolean contains(Object o) {
return multiset().contains(o);
}
代码示例来源:origin: google/guava
protected void assertGet(K key, Collection<V> values) {
assertEqualIgnoringOrder(values, multimap().get(key));
if (!values.isEmpty()) {
assertEqualIgnoringOrder(values, multimap().asMap().get(key));
assertFalse(multimap().isEmpty());
} else {
assertNull(multimap().asMap().get(key));
}
assertEquals(values.size(), multimap().get(key).size());
assertEquals(values.size() > 0, multimap().containsKey(key));
assertEquals(values.size() > 0, multimap().keySet().contains(key));
assertEquals(values.size() > 0, multimap().keys().contains(key));
}
代码示例来源:origin: google/guava
protected void assertGet(K key, Collection<V> values) {
assertEqualInOrder(values, multimap().get(key));
if (!values.isEmpty()) {
assertEqualInOrder(values, multimap().asMap().get(key));
assertFalse(multimap().isEmpty());
} else {
assertNull(multimap().asMap().get(key));
}
assertEquals(values.size(), multimap().get(key).size());
assertEquals(values.size() > 0, multimap().containsKey(key));
assertEquals(values.size() > 0, multimap().keySet().contains(key));
assertEquals(values.size() > 0, multimap().keys().contains(key));
}
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_removeAllPresent() {
assertTrue(
"multiset.entrySet.removeAll(presentEntry) returned false",
getMultiset()
.entrySet()
.removeAll(Collections.singleton(Multisets.immutableEntry(e0(), 1))));
assertFalse("multiset contains element after removing its entry", getMultiset().contains(e0()));
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_removeAllAbsent() {
assertFalse(
"multiset.entrySet.remove(missingEntry) returned true",
getMultiset()
.entrySet()
.removeAll(Collections.singleton(Multisets.immutableEntry(e0(), 2))));
assertTrue(
"multiset didn't contain element after removing a missing entry",
getMultiset().contains(e0()));
}
代码示例来源:origin: google/guava
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_retainAllAbsent() {
assertTrue(
"multiset.entrySet.retainAll(missingEntry) returned true",
getMultiset()
.entrySet()
.retainAll(Collections.singleton(Multisets.immutableEntry(e0(), 2))));
assertFalse(
"multiset contains element after retaining a different entry",
getMultiset().contains(e0()));
}
代码示例来源:origin: google/guava
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_retainAllPresent() {
assertFalse(
"multiset.entrySet.retainAll(presentEntry) returned false",
getMultiset()
.entrySet()
.retainAll(Collections.singleton(Multisets.immutableEntry(e0(), 1))));
assertTrue(
"multiset doesn't contains element after retaining its entry",
getMultiset().contains(e0()));
}
代码示例来源:origin: google/guava
public void testDifferenceWithMoreElementsInSecondMultiset() {
Multiset<String> ms1 = HashMultiset.create(Arrays.asList("a", "b", "a"));
Multiset<String> ms2 = HashMultiset.create(Arrays.asList("a", "b", "b", "b"));
Multiset<String> diff = Multisets.difference(ms1, ms2);
assertThat(diff).contains("a");
assertEquals(0, diff.count("b"));
assertEquals(1, diff.count("a"));
assertFalse(diff.contains("b"));
assertTrue(diff.contains("a"));
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_removeAbsent() {
assertFalse(
"multiset.entrySet.remove(missingEntry) returned true",
getMultiset().entrySet().remove(Multisets.immutableEntry(e0(), 2)));
assertTrue(
"multiset didn't contain element after removing a missing entry",
getMultiset().contains(e0()));
}
代码示例来源:origin: google/guava
public void testCopyOfDuplicateInconsistentWithEquals() {
IntegerDiv10 three = new IntegerDiv10(3);
IntegerDiv10 eleven = new IntegerDiv10(11);
IntegerDiv10 twelve = new IntegerDiv10(12);
IntegerDiv10 twenty = new IntegerDiv10(20);
List<IntegerDiv10> original = ImmutableList.of(three, eleven, twelve, twenty);
Multiset<IntegerDiv10> copy = ImmutableSortedMultiset.copyOf(original);
assertTrue(copy.contains(eleven));
assertTrue(copy.contains(twelve));
}
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_removePresent() {
assertTrue(
"multiset.entrySet.remove(presentEntry) returned false",
getMultiset().entrySet().remove(Multisets.immutableEntry(e0(), 1)));
assertFalse("multiset contains element after removing its entry", getMultiset().contains(e0()));
}
代码示例来源:origin: google/guava
public void testRemoveUnsupported() {
Multiset<String> multiset = new NoRemoveMultiset<>();
multiset.add("a");
try {
multiset.remove("a");
fail();
} catch (UnsupportedOperationException expected) {
}
assertTrue(multiset.contains("a"));
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
public void testRemove_nullPresent() {
initCollectionWithNullElement();
assertEquals(1, getMultiset().remove(null, 2));
assertFalse(
"multiset contains present after multiset.remove(present, 2)",
getMultiset().contains(null));
assertEquals(0, getMultiset().count(null));
}
代码示例来源: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
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_occurrences_present() {
assertEquals(
"multiset.remove(present, 2) didn't return the old count",
1,
getMultiset().remove(e0(), 2));
assertFalse(
"multiset contains present after multiset.remove(present, 2)",
getMultiset().contains(e0()));
assertEquals(0, getMultiset().count(e0()));
}
代码示例来源:origin: google/guava
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_some_occurrences_present() {
initThreeCopies();
assertEquals(
"multiset.remove(present, 2) didn't return the old count",
3,
getMultiset().remove(e0(), 2));
assertTrue(
"multiset contains present after multiset.remove(present, 2)",
getMultiset().contains(e0()));
assertEquals(1, getMultiset().count(e0()));
}
内容来源于网络,如有侵权,请联系作者删除!