java.lang.Object org.apache.lucene.util.PriorityQueue
Direct Known Subclasses:
FieldValueHitQueue, IntegerQueue, ScoreTermQueue, TermInfoQueue, CellQueue, FragmentQueue, SegmentMergeQueue, SpanQueue, FreqQ, FieldSortedHitQueue, PhraseQueue, OneComparatorFieldValueHitQueue, TermsDfQueue, CellQueue, MultiComparatorsFieldValueHitQueue, SuggestWordQueue, FieldDocSortedHitQueue, HitQueue, TermPositionsQueue
NOTE: This class preallocates a full array of
length maxSize+1
, in #initialize .
Field Summary  

protected T[]  heap 
Method from org.apache.lucene.util.PriorityQueue Summary: 

add, clear, getSentinelObject, initialize, insertWithOverflow, lessThan, pop, size, top, updateTop 
Methods from java.lang.Object: 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Method from org.apache.lucene.util.PriorityQueue Detail: 

public final T add(T element){ size++; heap[size] = element; upHeap(); return heap[1]; }

public final void clear(){ for (int i = 0; i < = size; i++) { heap[i] = null; } size = 0; }

protected T getSentinelObject(){ return null; }
Those sentinel values should always compare worse than any nonsentinel value (i.e., #lessThan should always favor the nonsentinel values). By default, this method returns false, which means the queue will not be filled with sentinel values. Otherwise, the value returned will be used to prepopulate the queue. Adds sentinel values to the queue. If this method is extended to return a nonnull value, then the following usage pattern is recommended: // extends getSentinelObject() to return a nonnull value. PriorityQueueNOTE: if this method returns a nonnull value, it will be called by #initialize(int) #size() times, relying on a new object to be returned and will not check if it's null again. Therefore you should ensure any call to this method creates a new instance and behaves consistently, e.g., it cannot return null if it previously returned nonnull. 
protected final void initialize(int maxSize){ size = 0; int heapSize; if (0 == maxSize) // We allocate 1 extra to avoid if statement in top() heapSize = 2; else heapSize = maxSize + 1; heap = (T[]) new Object[heapSize]; // T is unbounded type, so this unchecked cast works always this.maxSize = maxSize; // If sentinel objects are supported, populate the queue with them T sentinel = getSentinelObject(); if (sentinel != null) { heap[1] = sentinel; for (int i = 2; i < heap.length; i++) { heap[i] = getSentinelObject(); } size = maxSize; } }

public T insertWithOverflow(T element){ if (size < maxSize) { add(element); return null; } else if (size > 0 && !lessThan(element, heap[1])) { T ret = heap[1]; heap[1] = element; updateTop(); return ret; } else { return element; } }

abstract protected boolean lessThan(T a, T b)

public final T pop(){ if (size > 0) { T result = heap[1]; // save first value heap[1] = heap[size]; // move last to first heap[size] = null; // permit GC of objects size; downHeap(); // adjust heap return result; } else return null; }

public final int size(){ return size; }

public final T top(){ // We don't need to check size here: if maxSize is 0, // then heap is length 2 array with both entries null. // If size is 0 then heap[1] is already null. return heap[1]; }

public final T updateTop(){ downHeap(); return heap[1]; }
pq.top().change(); pq.updateTop();instead of o = pq.pop(); o.change(); pq.push(o); 