@Test public void testClear() { PriorityQueue<TestElement> queue = new DefaultPriorityQueue<TestElement>(TestElementComparator.INSTANCE, 0); assertEmptyQueue(queue); TestElement a = new TestElement(5); TestElement b = new TestElement(10); TestElement c = new TestElement(2); TestElement d = new TestElement(6); assertOffer(queue, a); assertOffer(queue, b); assertOffer(queue, c); assertOffer(queue, d); queue.clear(); assertEmptyQueue(queue); assertOffer(queue, a); assertSame(a, queue.peek()); assertOffer(queue, b); assertSame(a, queue.peek()); assertOffer(queue, c); assertSame(c, queue.peek()); assertOffer(queue, d); assertSame(c, queue.peek()); }
@Override public void clear() { for (int i = 0; i < size; ++i) { T node = queue[i]; if (node != null) { node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); queue[i] = null; } } size = 0; }
DefaultPriorityQueue extends AbstractQueue<T> implements PriorityQueue<T> { @Override public void clear() { for (int i = 0; i < size; ++i) { T node = queue[i]; if (node != null) { node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); queue[i] = null; } } size = 0; } }
DefaultPriorityQueue extends AbstractQueue<T> implements PriorityQueue<T> { @Override public void clear() { for (int i = 0; i < size; ++i) { T node = queue[i]; if (node != null) { node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); queue[i] = null; } } size = 0; } @SuppressWarnings("unchecked")  DefaultPriorityQueue(Comparator<T> comparator, int initialSize); }
DefaultPriorityQueue extends AbstractQueue<T> implements PriorityQueue<T> { @Override public void clear() { for (int i = 0; i < size; ++i) { T node = queue[i]; if (node != null) { node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); queue[i] = null; } } size = 0; } @SuppressWarnings("unchecked")  DefaultPriorityQueue(Comparator<T> comparator, int initialSize); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override boolean containsTyped(T node); @Override void clear(); @Override void clearIgnoringIndexes(); @Override boolean offer(T e); @Override T poll(); @Override T peek(); @SuppressWarnings("unchecked") @Override boolean remove(Object o); @Override boolean removeTyped(T node); @Override void priorityChanged(T node); @Override Object[] toArray(); @SuppressWarnings("unchecked") @Override X[] toArray(X[] a); @Override Iterator<T> iterator(); }
DefaultPriorityQueue extends AbstractQueue<T> implements PriorityQueue<T> { @Override public void clear() { for (int i = 0; i < size; ++i) { T node = queue[i]; if (node != null) { node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); queue[i] = null; } } size = 0; } @SuppressWarnings("unchecked")  DefaultPriorityQueue(Comparator<T> comparator, int initialSize); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override boolean containsTyped(T node); @Override void clear(); @Override void clearIgnoringIndexes(); @Override boolean offer(T e); @Override T poll(); @Override T peek(); @SuppressWarnings("unchecked") @Override boolean remove(Object o); @Override boolean removeTyped(T node); @Override void priorityChanged(T node); @Override Object[] toArray(); @SuppressWarnings("unchecked") @Override X[] toArray(X[] a); @Override Iterator<T> iterator();  }