本文整理汇总了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());
}
示例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);
}