當前位置: 首頁>>代碼示例>>Java>>正文


Java NavigableSet.iterator方法代碼示例

本文整理匯總了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);
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Cookbook,代碼行數:18,代碼來源:Chapter07Concurrency02.java

示例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());
}
 
開發者ID:microbean,項目名稱:microbean-helm,代碼行數:19,代碼來源:TestStreamOrientedChartLoader.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:TreeSetTest.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TreeSubSetTest.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TreeSubSetTest.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ConcurrentSkipListSubSetTest.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ConcurrentSkipListSubSetTest.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ConcurrentSkipListSetTest.java

示例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.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:EmptyNavigableSet.java

示例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) {}
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:TreeSetTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:TreeSubSetTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:TreeSubSetTest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:TreeSubSetTest.java

示例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) {}
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:ConcurrentSkipListSetTest.java


注:本文中的java.util.NavigableSet.iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。