本文整理了Java中org.apache.commons.collections.Bag.contains()
方法的一些代码示例,展示了Bag.contains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bag.contains()
方法的具体详情如下:
包路径:org.apache.commons.collections.Bag
类名称:Bag
方法名:contains
英 Returns true
if the bag contains all elements in the given collection, respecting cardinality. That is, if the given collection coll
contains n
copies of a given object, calling #getCount(Object) on that object must be >= n
for all n
in coll
.
The Collection#containsAll(Collection) method specifies that cardinality should not be respected; this method should return true if the bag contains at least one of every object contained in the given collection.
[中](违例)如果包包含给定集合中的所有元素,则返回true
,并考虑基数。也就是说,如果给定集合coll
包含给定对象的n
个副本,则对coll
中的所有n
调用该对象上的#getCount(对象)必须为>= n
。
Collection#containsAll(Collection)方法指定不应尊重基数;如果包包含给定集合中包含的每个对象中至少一个,则此方法应返回true。
代码示例来源:origin: commons-collections/commons-collections
public void testContains() {
Bag bag = makeBag();
assertEquals("Bag does not have at least 1 'A'", false, bag.contains("A"));
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
bag.add("A"); // bag 1A
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
bag.add("A"); // bag 2A
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
assertEquals("Bag does not have at least 1 'B'", false, bag.contains("B"));
bag.add("B"); // bag 2A,1B
assertEquals("Bag has at least 1 'A'", true, bag.contains("A"));
assertEquals("Bag has at least 1 'B'", true, bag.contains("B"));
}
代码示例来源:origin: commons-collections/commons-collections
public void testIllegalAdd() {
Bag bag = makeTestBag();
Integer i = new Integer(3);
try {
bag.add(i);
fail("Integer should fail type check.");
} catch (IllegalArgumentException e) {
// expected
}
assertTrue("Collection shouldn't contain illegal element",
!bag.contains(i));
}
代码示例来源:origin: commons-collections/commons-collections
public void testIllegalAdd() {
Bag bag = makeTestBag();
Integer i = new Integer(3);
try {
bag.add(i);
fail("Integer should fail string predicate.");
} catch (IllegalArgumentException e) {
// expected
}
assertTrue("Collection shouldn't contain illegal element",
!bag.contains(i));
}
代码示例来源:origin: commons-collections/commons-collections
public void testBagAdd() {
Bag bag = makeBag();
bag.add("A");
assertTrue("Should contain 'A'", bag.contains("A"));
assertEquals("Should have count of 1", 1, bag.getCount("A"));
bag.add("A");
assertTrue("Should contain 'A'", bag.contains("A"));
assertEquals("Should have count of 2", 2, bag.getCount("A"));
bag.add("B");
assertTrue(bag.contains("A"));
assertTrue(bag.contains("B"));
}
代码示例来源:origin: commons-collections/commons-collections
public void testTransformedBag() {
Bag bag = TransformedBag.decorate(new HashBag(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, bag.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
bag.add(els[i]);
assertEquals(i + 1, bag.size());
assertEquals(true, bag.contains(new Integer((String) els[i])));
assertEquals(false, bag.contains(els[i]));
}
assertEquals(false, bag.remove(els[0]));
assertEquals(true, bag.remove(new Integer((String) els[0])));
}
代码示例来源:origin: commons-collections/commons-collections
public void testTransformedBag() {
Bag bag = TransformedSortedBag.decorate(new TreeBag(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, bag.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
bag.add(els[i]);
assertEquals(i + 1, bag.size());
assertEquals(true, bag.contains(new Integer((String) els[i])));
}
assertEquals(true, bag.remove(new Integer((String) els[0])));
}
代码示例来源:origin: commons-collections/commons-collections
public void testIterator() {
Bag bag = makeBag();
bag.add("A");
bag.add("A");
bag.add("B");
assertEquals("Bag should have 3 items", 3, bag.size());
Iterator i = bag.iterator();
boolean foundA = false;
while (i.hasNext()) {
String element = (String) i.next();
// ignore the first A, remove the second via Iterator.remove()
if (element.equals("A")) {
if (foundA == false) {
foundA = true;
} else {
i.remove();
}
}
}
assertTrue("Bag should still contain 'A'", bag.contains("A"));
assertEquals("Bag should have 2 items", 2, bag.size());
assertEquals("Bag should have 1 'A'", 1, bag.getCount("A"));
}
代码示例来源:origin: commons-collections/commons-collections
public void testlegalAddRemove() {
Bag bag = makeTestBag();
assertEquals(0, bag.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "1"};
for (int i = 0; i < els.length; i++) {
bag.add(els[i]);
assertEquals(i + 1, bag.size());
assertEquals(true, bag.contains(els[i]));
}
Set set = ((PredicatedBag) bag).uniqueSet();
assertTrue("Unique set contains the first element",set.contains(els[0]));
assertEquals(true, bag.remove(els[0]));
set = ((PredicatedBag) bag).uniqueSet();
assertTrue("Unique set now does not contain the first element",
!set.contains(els[0]));
}
代码示例来源:origin: commons-collections/commons-collections
public void testlegalAddRemove() {
Bag bag = makeTestBag();
assertEquals(0, bag.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "1"};
for (int i = 0; i < els.length; i++) {
bag.add(els[i]);
assertEquals(i + 1, bag.size());
assertEquals(true, bag.contains(els[i]));
}
Set set = ((PredicatedBag) bag).uniqueSet();
assertTrue("Unique set contains the first element",set.contains(els[0]));
assertEquals(true, bag.remove(els[0]));
set = ((PredicatedBag) bag).uniqueSet();
assertTrue("Unique set now does not contain the first element",
!set.contains(els[0]));
}
代码示例来源:origin: dstl/baleen
/**
* @param word
* @return true if this bag contains the given word
*/
public boolean contains(String word) {
return words.contains(word);
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-entity-linking
/**
* @param word
* @return true if this bag contains the given word
*/
public boolean contains(String word) {
return words.contains(word);
}
代码示例来源:origin: hopshadoop/hopsworks
/**
* Check if certificates have been materialized in the *local* filesystem in the directory specified
*
* @param username Username of the user
* @param projectName Name of the project
* @param directory Directory to check if the certificates have been materialized
* @return True if the material exists in the cache, otherwise false
*/
public boolean existsInLocalStore(String username, String projectName, String directory) {
directory = directory != null ? directory : transientDir;
MaterialKey key = new MaterialKey(username, projectName);
try {
localReadLock.lock();
Bag materializedPaths = materializedCerts.get(key);
if (materializedPaths == null) {
return false;
}
return materializedPaths.contains(directory);
} finally {
localReadLock.unlock();
}
}
内容来源于网络,如有侵权,请联系作者删除!