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


Java PriorityQueue.clear方法代碼示例

本文整理匯總了Java中java.util.PriorityQueue.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java PriorityQueue.clear方法的具體用法?Java PriorityQueue.clear怎麽用?Java PriorityQueue.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.clear方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testClear

import java.util.PriorityQueue; //導入方法依賴的package包/類
/**
 * clear removes all elements
 */
public void testClear() {
    PriorityQueue q = populatedQueue(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.clear();
    assertTrue(q.isEmpty());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:PriorityQueueTest.java

示例2: realMain

import java.util.PriorityQueue; //導入方法依賴的package包/類
private static void realMain(String[] args) throws Throwable {
    final PriorityQueue<Integer> q = new PriorityQueue<>();
    Iterator<Integer> it;

    //----------------------------------------------------------------
    // Empty
    //----------------------------------------------------------------
    checkQ(q);
    check(q.isEmpty());
    check(! q.contains(1));
    it = q.iterator();
    removeIsCurrentlyIllegal(it);
    noMoreElements(it);
    q.clear();
    check(q.isEmpty());

    //----------------------------------------------------------------
    // Singleton
    //----------------------------------------------------------------
    q.add(1);
    checkQ(q, 1);
    check(! q.isEmpty());
    check(q.contains(1));
    it = q.iterator();
    removeIsCurrentlyIllegal(it);
    check(it.hasNext());
    equal(it.next(), 1);
    noMoreElements(it);
    remove(it, q);
    check(q.isEmpty());
    noMoreElements(it);
    checkQ(q);
    q.clear();

    //----------------------------------------------------------------
    // @see PriorityQueue.forgetMeNot
    //----------------------------------------------------------------
    final Integer[] a = {0, 4, 1, 6, 7, 2, 3}; // Carefully chosen!
    q.addAll(Arrays.asList(a));
    checkQ(q, a);
    it = q.iterator();
    checkQ(q, a);
    removeIsCurrentlyIllegal(it);
    checkQ(q, a);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    checkQ(q, a);
    check(it.hasNext());
    equal(it.next(), 0);
    equal(it.next(), 4);
    equal(it.next(), 1);
    equal(it.next(), 6);
    check(it.hasNext());
    checkQ(q, a);
    remove(it, q);
    checkQ(q, 0, 3, 1, 4, 7, 2);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    equal(it.next(), 7);
    remove(it, q);
    checkQ(q, 0, 2, 1, 4, 3);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    check(it.hasNext());
    equal(it.next(), 3);
    equal(it.next(), 2);
    check(! it.hasNext());
    remove(it, q);
    checkQ(q, 0, 3, 1, 4);
    check(! it.hasNext());
    noMoreElements(it);
    removeIsCurrentlyIllegal(it);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:74,代碼來源:ForgetMeNot.java


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