本文整理汇总了Java中java.util.NavigableSet.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java NavigableSet.iterator方法的具体用法?Java NavigableSet.iterator怎么用?Java NavigableSet.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.NavigableSet
的用法示例。
在下文中一共展示了NavigableSet.iterator方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: demoNavigableSetIterRemove
import java.util.NavigableSet; //导入方法依赖的package包/类
private static void demoNavigableSetIterRemove(NavigableSet<Integer> set) {
System.out.println("set: " + set);
try {
Iterator iter = set.iterator();
while (iter.hasNext()) {
Integer e = (Integer) iter.next();
System.out.println(e);
if (e == 2) {
System.out.println("Calling iter.remove()...");
iter.remove();
}
}
} catch (Exception ex) {
System.out.println(ex.getClass().getName());
}
System.out.println("set: " + set);
}
示例2: testToSubchartsBananasAndInvalid
import java.util.NavigableSet; //导入方法依赖的package包/类
@Test
public void testToSubchartsBananasAndInvalid() throws IOException {
final String input = "wordpress/charts/mariadb/charts/frobnicator/charts/joe/barney/charts/wilma/README.md";
final NavigableSet<String> output = StreamOrientedChartLoader.toSubcharts(input);
assertNotNull(output);
assertEquals(4, output.size());
final Iterator<String> iterator = output.iterator();
assertNotNull(iterator);
assertTrue(iterator.hasNext());
assertEquals("wordpress/charts/mariadb", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("wordpress/charts/mariadb/charts/frobnicator", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("wordpress/charts/mariadb/charts/frobnicator/charts/joe", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("wordpress/charts/mariadb/charts/frobnicator/charts/joe/barney/charts/wilma", iterator.next());
assertFalse(iterator.hasNext());
}
示例3: mutateSet
import java.util.NavigableSet; //导入方法依赖的package包/类
void mutateSet(NavigableSet<Integer> set, int min, int max) {
int size = set.size();
int rangeSize = max - min + 1;
// Remove a bunch of entries directly
for (int i = 0, n = rangeSize / 2; i < n; i++) {
remove(set, min - 5 + rnd.nextInt(rangeSize + 10));
}
// Remove a bunch of entries with iterator
for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
if (rnd.nextBoolean()) {
bs.clear(it.next());
it.remove();
}
}
// Add entries till we're back to original size
while (set.size() < size) {
int element = min + rnd.nextInt(rangeSize);
assertTrue(element >= min && element <= max);
put(set, element);
}
}
示例4: testIteratorRemove
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* iterator.remove removes current element
*/
public void testIteratorRemove() {
final NavigableSet q = set0();
q.add(new Integer(2));
q.add(new Integer(1));
q.add(new Integer(3));
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertEquals(2, it.next());
assertEquals(3, it.next());
assertFalse(it.hasNext());
}
示例5: testDescendingIteratorRemove
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* iterator.remove removes current element
*/
public void testDescendingIteratorRemove() {
final NavigableSet q = dset0();
q.add(new Integer(2));
q.add(new Integer(1));
q.add(new Integer(3));
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertEquals(2, it.next());
assertEquals(3, it.next());
assertFalse(it.hasNext());
}
示例6: testIteratorRemove
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* iterator.remove removes current element
*/
public void testIteratorRemove() {
final NavigableSet q = set0();
q.add(new Integer(2));
q.add(new Integer(1));
q.add(new Integer(3));
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertEquals(it.next(), new Integer(2));
assertEquals(it.next(), new Integer(3));
assertFalse(it.hasNext());
}
示例7: testDescendingIteratorRemove
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* iterator.remove removes current element
*/
public void testDescendingIteratorRemove() {
final NavigableSet q = dset0();
q.add(new Integer(2));
q.add(new Integer(1));
q.add(new Integer(3));
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertEquals(it.next(), new Integer(2));
assertEquals(it.next(), new Integer(3));
assertFalse(it.hasNext());
}
示例8: mutateSet
import java.util.NavigableSet; //导入方法依赖的package包/类
void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) {
int size = set.size();
int rangeSize = max - min + 1;
// Remove a bunch of entries directly
for (int i = 0, n = rangeSize / 2; i < n; i++) {
remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
}
// Remove a bunch of entries with iterator
for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
if (rnd.nextBoolean()) {
bs.clear(it.next());
it.remove();
}
}
// Add entries till we're back to original size
while (set.size() < size) {
int element = min + rnd.nextInt(rangeSize);
assertTrue(element >= min && element <= max);
put(set, element, bs);
}
}
示例9: testEmptyIterator
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* Tests that the iterator is empty.
*/
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
Iterator emptyIterator = navigableSet.iterator();
assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
"The iterator is not empty.");
}
示例10: mutateSubSet
import java.util.NavigableSet; //导入方法依赖的package包/类
void mutateSubSet(NavigableSet<Integer> set, int min, int max) {
int size = set.size();
int rangeSize = max - min + 1;
// Remove a bunch of entries directly
for (int i = 0, n = rangeSize / 2; i < n; i++) {
remove(set, min - 5 + rnd.nextInt(rangeSize + 10));
}
// Remove a bunch of entries with iterator
for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
if (rnd.nextBoolean()) {
bs.clear(it.next());
it.remove();
}
}
// Add entries till we're back to original size
while (set.size() < size) {
int element = min - 5 + rnd.nextInt(rangeSize + 10);
if (element >= min && element <= max) {
put(set, element);
} else {
try {
set.add(element);
shouldThrow();
} catch (IllegalArgumentException success) {}
}
}
}
示例11: testIterator
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* iterator iterates through all elements
*/
public void testIterator() {
NavigableSet q = populatedSet(SIZE);
Iterator it = q.iterator();
int i;
for (i = 0; it.hasNext(); i++)
assertTrue(q.contains(it.next()));
assertEquals(i, SIZE);
assertIteratorExhausted(it);
}
示例12: testDescendingIterator
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* iterator iterates through all elements
*/
public void testDescendingIterator() {
NavigableSet q = populatedSet(SIZE);
int i = 0;
Iterator it = q.iterator();
while (it.hasNext()) {
assertTrue(q.contains(it.next()));
++i;
}
assertEquals(i, SIZE);
}
示例13: testDescendingEmptyIterator
import java.util.NavigableSet; //导入方法依赖的package包/类
/**
* iterator of empty set has no elements
*/
public void testDescendingEmptyIterator() {
NavigableSet q = dset0();
int i = 0;
Iterator it = q.iterator();
while (it.hasNext()) {
assertTrue(q.contains(it.next()));
++i;
}
assertEquals(0, i);
}
示例14: mutateSubSet
import java.util.NavigableSet; //导入方法依赖的package包/类
void mutateSubSet(NavigableSet<Integer> set, int min, int max,
BitSet bs) {
int size = set.size();
int rangeSize = max - min + 1;
// Remove a bunch of entries directly
for (int i = 0, n = rangeSize / 2; i < n; i++) {
remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
}
// Remove a bunch of entries with iterator
for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
if (rnd.nextBoolean()) {
bs.clear(it.next());
it.remove();
}
}
// Add entries till we're back to original size
while (set.size() < size) {
int element = min - 5 + rnd.nextInt(rangeSize + 10);
if (element >= min && element <= max) {
put(set, element, bs);
} else {
try {
set.add(element);
shouldThrow();
} catch (IllegalArgumentException success) {}
}
}
}