本文整理了Java中org.apache.commons.collections.Bag.iterator()
方法的一些代码示例,展示了Bag.iterator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bag.iterator()
方法的具体详情如下:
包路径:org.apache.commons.collections.Bag
类名称:Bag
方法名:iterator
[英]Returns an Iterator over the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications.
[中]返回整个成员集的迭代器,包括由于基数而产生的副本。此迭代器故障快,不允许并发修改。
代码示例来源:origin: commons-collections/commons-collections
public void testIteratorFailNoMore() {
Bag bag = makeBag();
bag.add("A");
bag.add("A");
bag.add("B");
Iterator it = bag.iterator();
it.next();
it.next();
it.next();
try {
it.next();
fail("Should throw NoSuchElementException");
} catch (NoSuchElementException ex) {
// expected
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testIteratorFail() {
Bag bag = makeBag();
bag.add("A");
bag.add("A");
bag.add("B");
Iterator it = bag.iterator();
it.next();
bag.remove("A");
try {
it.next();
fail("Should throw ConcurrentModificationException");
} catch (ConcurrentModificationException e) {
// expected
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testIteratorRemoveProtectsInvariants() {
Bag bag = makeBag();
bag.add("A");
bag.add("A");
assertEquals(2, bag.size());
Iterator it = bag.iterator();
assertEquals("A", it.next());
assertEquals(true, it.hasNext());
it.remove();
assertEquals(1, bag.size());
assertEquals(true, it.hasNext());
assertEquals("A", it.next());
assertEquals(false, it.hasNext());
it.remove();
assertEquals(0, bag.size());
assertEquals(false, it.hasNext());
Iterator it2 = bag.iterator();
assertEquals(false, it2.hasNext());
}
代码示例来源:origin: commons-collections/commons-collections
public void testIteratorFailDoubleRemove() {
Bag bag = makeBag();
bag.add("A");
bag.add("A");
bag.add("B");
Iterator it = bag.iterator();
it.next();
it.next();
assertEquals(3, bag.size());
it.remove();
assertEquals(2, bag.size());
try {
it.remove();
fail("Should throw IllegalStateException");
} catch (IllegalStateException ex) {
// expected
}
assertEquals(2, bag.size());
it.next();
it.remove();
assertEquals(1, bag.size());
}
代码示例来源: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: org.apache.maven.shared/maven-shared-jar
it = timestamps.iterator();
String ts = "";
int tsmax = 0;
代码示例来源:origin: OpenSOC/opensoc-streaming
public boolean doIndex() throws Exception {
try {
synchronized (bulk_set) {
if (client == null)
throw new Exception("client is null");
BulkRequestBuilder bulkRequest = client.prepareBulk();
Iterator<JSONObject> iterator = bulk_set.iterator();
while (iterator.hasNext()) {
JSONObject setElement = iterator.next();
IndexRequestBuilder a = client.prepareIndex(_index_name,
_document_name);
a.setSource(setElement.toString());
bulkRequest.add(a);
}
_LOG.trace("[OpenSOC] Performing bulk load of size: "
+ bulkRequest.numberOfActions());
BulkResponse resp = bulkRequest.execute().actionGet();
_LOG.trace("[OpenSOC] Received bulk response: "
+ resp.toString());
bulk_set.clear();
}
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
代码示例来源:origin: OpenSOC/opensoc-streaming
Iterator<JSONObject> iterator = bulk_set.iterator();
内容来源于网络,如有侵权,请联系作者删除!