LUCENE-1968: Remove deprecated PriorityQueue methods.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@824013 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Busch 2009-10-11 03:54:25 +00:00
parent 877c9ff521
commit 3619c380d6
22 changed files with 67 additions and 153 deletions

View File

@ -39,6 +39,8 @@ API Changes
* LUCENE-1961: Remove remaining deprecations from document package. * LUCENE-1961: Remove remaining deprecations from document package.
(Michael Busch) (Michael Busch)
* LUCENE-1968: Remove deprecated methods in PriorityQueue. (Michael Busch)
Bug fixes Bug fixes
* LUCENE-1951: When the text provided to WildcardQuery has no wildcard * LUCENE-1951: When the text provided to WildcardQuery has no wildcard

View File

@ -84,7 +84,7 @@ public class QualityQueriesFinder {
} }
private String [] bestTerms(String field,int numTerms) throws IOException { private String [] bestTerms(String field,int numTerms) throws IOException {
PriorityQueue pq = new TermsDfQueue(numTerms); PriorityQueue<TermDf> pq = new TermsDfQueue(numTerms);
IndexReader ir = IndexReader.open(dir, true); IndexReader ir = IndexReader.open(dir, true);
try { try {
int threshold = ir.maxDoc() / 10; // ignore words too common. int threshold = ir.maxDoc() / 10; // ignore words too common.
@ -96,7 +96,7 @@ public class QualityQueriesFinder {
int df = terms.docFreq(); int df = terms.docFreq();
if (df<threshold) { if (df<threshold) {
String ttxt = terms.term().text(); String ttxt = terms.term().text();
pq.insert(new TermDf(ttxt,df)); pq.insertWithOverflow(new TermDf(ttxt,df));
} }
} }
} finally { } finally {
@ -121,13 +121,11 @@ public class QualityQueriesFinder {
} }
} }
private static class TermsDfQueue extends PriorityQueue { private static class TermsDfQueue extends PriorityQueue<TermDf> {
TermsDfQueue (int maxSize) { TermsDfQueue (int maxSize) {
initialize(maxSize); initialize(maxSize);
} }
protected boolean lessThan(Object a, Object b) { protected boolean lessThan(TermDf tf1, TermDf tf2) {
TermDf tf1 = (TermDf) a;
TermDf tf2 = (TermDf) b;
return tf1.df < tf2.df; return tf1.df < tf2.df;
} }
} }

View File

@ -55,13 +55,13 @@ public class HighFreqTerms {
if (field != null) { if (field != null) {
while (terms.next()) { while (terms.next()) {
if (terms.term().field().equals(field)) { if (terms.term().field().equals(field)) {
tiq.insert(new TermInfo(terms.term(), terms.docFreq())); tiq.insertWithOverflow(new TermInfo(terms.term(), terms.docFreq()));
} }
} }
} }
else { else {
while (terms.next()) { while (terms.next()) {
tiq.insert(new TermInfo(terms.term(), terms.docFreq())); tiq.insertWithOverflow(new TermInfo(terms.term(), terms.docFreq()));
} }
} }
while (tiq.size() != 0) { while (tiq.size() != 0) {
@ -88,13 +88,11 @@ final class TermInfo {
Term term; Term term;
} }
final class TermInfoQueue extends PriorityQueue { final class TermInfoQueue extends PriorityQueue<TermInfo> {
TermInfoQueue(int size) { TermInfoQueue(int size) {
initialize(size); initialize(size);
} }
protected final boolean lessThan(Object a, Object b) { protected final boolean lessThan(TermInfo termInfoA, TermInfo termInfoB) {
TermInfo termInfoA = (TermInfo) a;
TermInfo termInfoB = (TermInfo) b;
return termInfoA.docFreq < termInfoB.docFreq; return termInfoA.docFreq < termInfoB.docFreq;
} }
} }

View File

@ -215,7 +215,7 @@ public class FuzzyLikeThisQuery extends Query
float score=fe.difference(); float score=fe.difference();
if(variantsQ.size() < MAX_VARIANTS_PER_TERM || score > minScore){ if(variantsQ.size() < MAX_VARIANTS_PER_TERM || score > minScore){
ScoreTerm st=new ScoreTerm(possibleMatch,score,startTerm); ScoreTerm st=new ScoreTerm(possibleMatch,score,startTerm);
variantsQ.insert(st); variantsQ.insertWithOverflow(st);
minScore = ((ScoreTerm)variantsQ.top()).score; // maintain minScore minScore = ((ScoreTerm)variantsQ.top()).score; // maintain minScore
} }
} }
@ -237,7 +237,7 @@ public class FuzzyLikeThisQuery extends Query
{ {
ScoreTerm st = (ScoreTerm) variantsQ.pop(); ScoreTerm st = (ScoreTerm) variantsQ.pop();
st.score=(st.score*st.score)*sim.idf(df,corpusNumDocs); st.score=(st.score*st.score)*sim.idf(df,corpusNumDocs);
q.insert(st); q.insertWithOverflow(st);
} }
} }
} }
@ -326,7 +326,7 @@ public class FuzzyLikeThisQuery extends Query
} }
} }
private static class ScoreTermQueue extends PriorityQueue { private static class ScoreTermQueue extends PriorityQueue<ScoreTerm> {
public ScoreTermQueue(int size){ public ScoreTermQueue(int size){
initialize(size); initialize(size);
} }
@ -334,9 +334,7 @@ public class FuzzyLikeThisQuery extends Query
/* (non-Javadoc) /* (non-Javadoc)
* @see org.apache.lucene.util.PriorityQueue#lessThan(java.lang.Object, java.lang.Object) * @see org.apache.lucene.util.PriorityQueue#lessThan(java.lang.Object, java.lang.Object)
*/ */
protected boolean lessThan(Object a, Object b) { protected boolean lessThan(ScoreTerm termA, ScoreTerm termB) {
ScoreTerm termA = (ScoreTerm)a;
ScoreTerm termB = (ScoreTerm)b;
if (termA.score== termB.score) if (termA.score== termB.score)
return termA.term.compareTo(termB.term) > 0; return termA.term.compareTo(termB.term) > 0;
else else

View File

@ -668,7 +668,7 @@ public final class MoreLikeThis {
float score = tf * idf; float score = tf * idf;
// only really need 1st 3 entries, other ones are for troubleshooting // only really need 1st 3 entries, other ones are for troubleshooting
res.insert(new Object[]{word, // the word res.insertWithOverflow(new Object[]{word, // the word
topField, // the top field topField, // the top field
Float.valueOf(score), // overall score Float.valueOf(score), // overall score
Float.valueOf(idf), // idf Float.valueOf(idf), // idf
@ -953,14 +953,12 @@ public final class MoreLikeThis {
/** /**
* PriorityQueue that orders words by score. * PriorityQueue that orders words by score.
*/ */
private static class FreqQ extends PriorityQueue { private static class FreqQ extends PriorityQueue<Object[]> {
FreqQ (int s) { FreqQ (int s) {
initialize(s); initialize(s);
} }
protected boolean lessThan(Object a, Object b) { protected boolean lessThan(Object[] aa, Object[] bb) {
Object[] aa = (Object[]) a;
Object[] bb = (Object[]) b;
Float fa = (Float) aa[2]; Float fa = (Float) aa[2];
Float fb = (Float) bb[2]; Float fb = (Float) bb[2];
return fa.floatValue() > fb.floatValue(); return fa.floatValue() > fb.floatValue();

View File

@ -246,7 +246,7 @@ public class SpellChecker {
continue; continue;
} }
} }
sugQueue.insert(sugWord); sugQueue.insertWithOverflow(sugWord);
if (sugQueue.size() == numSug) { if (sugQueue.size() == numSug) {
// if queue full, maintain the minScore score // if queue full, maintain the minScore score
min = ((SuggestWord) sugQueue.top()).score; min = ((SuggestWord) sugQueue.top()).score;

View File

@ -25,15 +25,13 @@ import org.apache.lucene.util.PriorityQueue;
* Sorts SuggestWord instances * Sorts SuggestWord instances
* *
*/ */
final class SuggestWordQueue extends PriorityQueue { final class SuggestWordQueue extends PriorityQueue<SuggestWord> {
SuggestWordQueue (int size) { SuggestWordQueue (int size) {
initialize(size); initialize(size);
} }
protected final boolean lessThan (Object a, Object b) { protected final boolean lessThan (SuggestWord wa, SuggestWord wb) {
SuggestWord wa = (SuggestWord) a;
SuggestWord wb = (SuggestWord) b;
int val = wa.compareTo(wb); int val = wa.compareTo(wb);
return val < 0; return val < 0;
} }

View File

@ -980,7 +980,7 @@ class DirectoryReader extends IndexReader implements Cloneable {
SegmentMergeInfo smi = new SegmentMergeInfo(starts[i], termEnum, reader); SegmentMergeInfo smi = new SegmentMergeInfo(starts[i], termEnum, reader);
smi.ord = i; smi.ord = i;
if (t == null ? smi.next() : termEnum.term() != null) if (t == null ? smi.next() : termEnum.term() != null)
queue.put(smi); // initialize queue queue.add(smi); // initialize queue
else else
smi.close(); smi.close();
} }
@ -995,7 +995,7 @@ class DirectoryReader extends IndexReader implements Cloneable {
SegmentMergeInfo smi = matchingSegments[i]; SegmentMergeInfo smi = matchingSegments[i];
if (smi==null) break; if (smi==null) break;
if (smi.next()) if (smi.next())
queue.put(smi); queue.add(smi);
else else
smi.close(); // done with segment smi.close(); // done with segment
} }

View File

@ -32,7 +32,7 @@ import java.util.List;
*/ */
public class MultipleTermPositions implements TermPositions { public class MultipleTermPositions implements TermPositions {
private static final class TermPositionsQueue extends PriorityQueue { private static final class TermPositionsQueue extends PriorityQueue<TermPositions> {
TermPositionsQueue(List termPositions) throws IOException { TermPositionsQueue(List termPositions) throws IOException {
initialize(termPositions.size()); initialize(termPositions.size());
@ -40,7 +40,7 @@ public class MultipleTermPositions implements TermPositions {
while (i.hasNext()) { while (i.hasNext()) {
TermPositions tp = (TermPositions) i.next(); TermPositions tp = (TermPositions) i.next();
if (tp.next()) if (tp.next())
put(tp); add(tp);
} }
} }
@ -48,8 +48,8 @@ public class MultipleTermPositions implements TermPositions {
return (TermPositions) top(); return (TermPositions) top();
} }
public final boolean lessThan(Object a, Object b) { public final boolean lessThan(TermPositions a, TermPositions b) {
return ((TermPositions) a).doc() < ((TermPositions) b).doc(); return a.doc() < b.doc();
} }
} }
@ -126,7 +126,7 @@ public class MultipleTermPositions implements TermPositions {
_posList.add(tp.nextPosition()); _posList.add(tp.nextPosition());
if (tp.next()) if (tp.next())
_termPositionsQueue.adjustTop(); _termPositionsQueue.updateTop();
else { else {
_termPositionsQueue.pop(); _termPositionsQueue.pop();
tp.close(); tp.close();
@ -147,7 +147,7 @@ public class MultipleTermPositions implements TermPositions {
while (_termPositionsQueue.peek() != null && target > _termPositionsQueue.peek().doc()) { while (_termPositionsQueue.peek() != null && target > _termPositionsQueue.peek().doc()) {
TermPositions tp = (TermPositions) _termPositionsQueue.pop(); TermPositions tp = (TermPositions) _termPositionsQueue.pop();
if (tp.skipTo(target)) if (tp.skipTo(target))
_termPositionsQueue.put(tp); _termPositionsQueue.add(tp);
else else
tp.close(); tp.close();
} }

View File

@ -20,14 +20,12 @@ package org.apache.lucene.index;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.PriorityQueue;
final class SegmentMergeQueue extends PriorityQueue { final class SegmentMergeQueue extends PriorityQueue<SegmentMergeInfo> {
SegmentMergeQueue(int size) { SegmentMergeQueue(int size) {
initialize(size); initialize(size);
} }
protected final boolean lessThan(Object a, Object b) { protected final boolean lessThan(SegmentMergeInfo stiA, SegmentMergeInfo stiB) {
SegmentMergeInfo stiA = (SegmentMergeInfo)a;
SegmentMergeInfo stiB = (SegmentMergeInfo)b;
int comparison = stiA.term.compareTo(stiB.term); int comparison = stiA.term.compareTo(stiB.term);
if (comparison == 0) if (comparison == 0)
return stiA.base < stiB.base; return stiA.base < stiB.base;

View File

@ -32,7 +32,7 @@ final class ExactPhraseScorer extends PhraseScorer {
pq.clear(); pq.clear();
for (PhrasePositions pp = first; pp != null; pp = pp.next) { for (PhrasePositions pp = first; pp != null; pp = pp.next) {
pp.firstPosition(); pp.firstPosition();
pq.put(pp); // build pq from list pq.add(pp); // build pq from list
} }
pqToList(); // rebuild list from pq pqToList(); // rebuild list from pq

View File

@ -31,7 +31,7 @@ import java.util.Locale;
* @since lucene 1.4 * @since lucene 1.4
*/ */
class FieldDocSortedHitQueue class FieldDocSortedHitQueue
extends PriorityQueue { extends PriorityQueue<FieldDoc> {
// this cannot contain AUTO fields - any AUTO fields should // this cannot contain AUTO fields - any AUTO fields should
// have been resolved by the time this class is used. // have been resolved by the time this class is used.
@ -99,9 +99,7 @@ extends PriorityQueue {
* @param b ScoreDoc * @param b ScoreDoc
* @return <code>true</code> if document <code>a</code> should be sorted after document <code>b</code>. * @return <code>true</code> if document <code>a</code> should be sorted after document <code>b</code>.
*/ */
protected final boolean lessThan (final Object a, final Object b) { protected final boolean lessThan (final FieldDoc docA, final FieldDoc docB) {
final FieldDoc docA = (FieldDoc) a;
final FieldDoc docB = (FieldDoc) b;
final int n = fields.length; final int n = fields.length;
int c = 0; int c = 0;
for (int i=0; i<n && c==0; ++i) { for (int i=0; i<n && c==0; ++i) {

View File

@ -89,21 +89,6 @@ extends PriorityQueue {
maxscore = Math.max(maxscore, fdoc.score); maxscore = Math.max(maxscore, fdoc.score);
} }
// The signature of this method takes a FieldDoc in order to avoid
// the unneeded cast to retrieve the score.
// inherit javadoc
public boolean insert(FieldDoc fdoc) {
updateMaxScore(fdoc);
return super.insert(fdoc);
}
// This overrides PriorityQueue.insert() so that insert(FieldDoc) that
// keeps track of the score isn't accidentally bypassed.
// inherit javadoc
public boolean insert(Object fdoc) {
return insert((FieldDoc)fdoc);
}
// This overrides PriorityQueue.insertWithOverflow() so that // This overrides PriorityQueue.insertWithOverflow() so that
// updateMaxScore(FieldDoc) that keeps track of the score isn't accidentally // updateMaxScore(FieldDoc) that keeps track of the score isn't accidentally
// bypassed. // bypassed.

View File

@ -19,7 +19,7 @@ package org.apache.lucene.search;
import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.PriorityQueue;
final class HitQueue extends PriorityQueue { final class HitQueue extends PriorityQueue<ScoreDoc> {
private boolean prePopulate; private boolean prePopulate;
@ -68,16 +68,14 @@ final class HitQueue extends PriorityQueue {
} }
// Returns null if prePopulate is false. // Returns null if prePopulate is false.
protected Object getSentinelObject() { protected ScoreDoc getSentinelObject() {
// Always set the doc Id to MAX_VALUE so that it won't be favored by // Always set the doc Id to MAX_VALUE so that it won't be favored by
// lessThan. This generally should not happen since if score is not NEG_INF, // lessThan. This generally should not happen since if score is not NEG_INF,
// TopScoreDocCollector will always add the object to the queue. // TopScoreDocCollector will always add the object to the queue.
return !prePopulate ? null : new ScoreDoc(Integer.MAX_VALUE, Float.NEGATIVE_INFINITY); return !prePopulate ? null : new ScoreDoc(Integer.MAX_VALUE, Float.NEGATIVE_INFINITY);
} }
protected final boolean lessThan(Object a, Object b) { protected final boolean lessThan(ScoreDoc hitA, ScoreDoc hitB) {
ScoreDoc hitA = (ScoreDoc)a;
ScoreDoc hitB = (ScoreDoc)b;
if (hitA.score == hitB.score) if (hitA.score == hitB.score)
return hitA.doc > hitB.doc; return hitA.doc > hitB.doc;
else else

View File

@ -191,7 +191,7 @@ public class MultiSearcher extends Searcher {
for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq
ScoreDoc scoreDoc = scoreDocs[j]; ScoreDoc scoreDoc = scoreDocs[j];
scoreDoc.doc += starts[i]; // convert doc scoreDoc.doc += starts[i]; // convert doc
if(!hq.insert(scoreDoc)) if(scoreDoc == hq.insertWithOverflow(scoreDoc))
break; // no more scores > minScore break; // no more scores > minScore
} }
} }
@ -234,7 +234,7 @@ public class MultiSearcher extends Searcher {
for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq
ScoreDoc scoreDoc = scoreDocs[j]; ScoreDoc scoreDoc = scoreDocs[j];
scoreDoc.doc += starts[i]; // convert doc scoreDoc.doc += starts[i]; // convert doc
if (!hq.insert (scoreDoc)) if (scoreDoc == hq.insertWithOverflow((FieldDoc) scoreDoc))
break; // no more scores > minScore break; // no more scores > minScore
} }
} }

View File

@ -269,7 +269,7 @@ class MultiSearcherThread extends Thread {
scoreDoc.doc += starts[i]; // convert doc scoreDoc.doc += starts[i]; // convert doc
//it would be so nice if we had a thread-safe insert //it would be so nice if we had a thread-safe insert
synchronized (hq) { synchronized (hq) {
if (!hq.insert(scoreDoc)) if (scoreDoc == hq.insertWithOverflow(scoreDoc))
break; break;
} // no more scores > minScore } // no more scores > minScore
} }

View File

@ -19,14 +19,12 @@ package org.apache.lucene.search;
import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.PriorityQueue;
final class PhraseQueue extends PriorityQueue { final class PhraseQueue extends PriorityQueue<PhrasePositions> {
PhraseQueue(int size) { PhraseQueue(int size) {
initialize(size); initialize(size);
} }
protected final boolean lessThan(Object o1, Object o2) { protected final boolean lessThan(PhrasePositions pp1, PhrasePositions pp2) {
PhrasePositions pp1 = (PhrasePositions)o1;
PhrasePositions pp2 = (PhrasePositions)o2;
if (pp1.doc == pp2.doc) if (pp1.doc == pp2.doc)
if (pp1.position == pp2.position) if (pp1.position == pp2.position)
// same doc and pp.position, so decide by actual term positions. // same doc and pp.position, so decide by actual term positions.

View File

@ -83,7 +83,7 @@ final class SloppyPhraseScorer extends PhraseScorer {
if (pp.position > end) if (pp.position > end)
end = pp.position; end = pp.position;
pq.put(pp); // restore pq pq.add(pp); // restore pq
} }
return freq; return freq;
@ -101,10 +101,10 @@ final class SloppyPhraseScorer extends PhraseScorer {
} }
//insert back all but pp2 //insert back all but pp2
for (n--; n>=0; n--) { for (n--; n>=0; n--) {
pq.insert(tmpPos[n]); pq.insertWithOverflow(tmpPos[n]);
} }
//insert pp back //insert pp back
pq.put(pp); pq.add(pp);
return pp2; return pp2;
} }
@ -133,7 +133,7 @@ final class SloppyPhraseScorer extends PhraseScorer {
pp.firstPosition(); pp.firstPosition();
if (pp.position > end) if (pp.position > end)
end = pp.position; end = pp.position;
pq.put(pp); // build pq from list pq.add(pp); // build pq from list
} }
return end; return end;
} }
@ -182,7 +182,7 @@ final class SloppyPhraseScorer extends PhraseScorer {
for (PhrasePositions pp = first; pp != null; pp = pp.next) { for (PhrasePositions pp = first; pp != null; pp = pp.next) {
if (pp.position > end) if (pp.position > end)
end = pp.position; end = pp.position;
pq.put(pp); // build pq from list pq.add(pp); // build pq from list
} }
if (repeats!=null) { if (repeats!=null) {

View File

@ -51,14 +51,12 @@ public class NearSpansUnordered extends Spans {
private boolean more = true; // true iff not done private boolean more = true; // true iff not done
private boolean firstTime = true; // true before first next() private boolean firstTime = true; // true before first next()
private class CellQueue extends PriorityQueue { private class CellQueue extends PriorityQueue<SpansCell> {
public CellQueue(int size) { public CellQueue(int size) {
initialize(size); initialize(size);
} }
protected final boolean lessThan(Object o1, Object o2) { protected final boolean lessThan(SpansCell spans1, SpansCell spans2) {
SpansCell spans1 = (SpansCell)o1;
SpansCell spans2 = (SpansCell)o2;
if (spans1.doc() == spans2.doc()) { if (spans1.doc() == spans2.doc()) {
return NearSpansOrdered.docSpansOrdered(spans1, spans2); return NearSpansOrdered.docSpansOrdered(spans1, spans2);
} else { } else {
@ -147,7 +145,7 @@ public class NearSpansUnordered extends Spans {
firstTime = false; firstTime = false;
} else if (more) { } else if (more) {
if (min().next()) { // trigger further scanning if (min().next()) { // trigger further scanning
queue.adjustTop(); // maintain queue queue.updateTop(); // maintain queue
} else { } else {
more = false; more = false;
} }
@ -185,7 +183,7 @@ public class NearSpansUnordered extends Spans {
more = min().next(); more = min().next();
if (more) { if (more) {
queue.adjustTop(); // maintain queue queue.updateTop(); // maintain queue
} }
} }
return false; // no more matches return false; // no more matches
@ -204,7 +202,7 @@ public class NearSpansUnordered extends Spans {
} else { // normal case } else { // normal case
while (more && min().doc() < target) { // skip as needed while (more && min().doc() < target) { // skip as needed
if (min().skipTo(target)) { if (min().skipTo(target)) {
queue.adjustTop(); queue.updateTop();
} else { } else {
more = false; more = false;
} }
@ -290,7 +288,7 @@ public class NearSpansUnordered extends Spans {
private void listToQueue() { private void listToQueue() {
queue.clear(); // rebuild queue queue.clear(); // rebuild queue
for (SpansCell cell = first; cell != null; cell = cell.next) { for (SpansCell cell = first; cell != null; cell = cell.next) {
queue.put(cell); // add to queue from list queue.add(cell); // add to queue from list
} }
} }

View File

@ -181,7 +181,7 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
Spans spans = ((SpanQuery)i.next()).getSpans(reader); Spans spans = ((SpanQuery)i.next()).getSpans(reader);
if ( ((target == -1) && spans.next()) if ( ((target == -1) && spans.next())
|| ((target != -1) && spans.skipTo(target))) { || ((target != -1) && spans.skipTo(target))) {
queue.put(spans); queue.add(spans);
} }
} }
return queue.size() != 0; return queue.size() != 0;
@ -197,7 +197,7 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
} }
if (top().next()) { // move to next if (top().next()) { // move to next
queue.adjustTop(); queue.updateTop();
return true; return true;
} }
@ -215,7 +215,7 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
boolean skipCalled = false; boolean skipCalled = false;
while (queue.size() != 0 && top().doc() < target) { while (queue.size() != 0 && top().doc() < target) {
if (top().skipTo(target)) { if (top().skipTo(target)) {
queue.adjustTop(); queue.updateTop();
} else { } else {
queue.pop(); queue.pop();
} }
@ -232,7 +232,6 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
public int start() { return top().start(); } public int start() { return top().start(); }
public int end() { return top().end(); } public int end() { return top().end(); }
// TODO: Remove warning after API has been finalized
public Collection/*<byte[]>*/ getPayload() throws IOException { public Collection/*<byte[]>*/ getPayload() throws IOException {
ArrayList result = null; ArrayList result = null;
Spans theTop = top(); Spans theTop = top();
@ -242,7 +241,6 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
return result; return result;
} }
// TODO: Remove warning after API has been finalized
public boolean isPayloadAvailable() { public boolean isPayloadAvailable() {
Spans top = top(); Spans top = top();
return top != null && top.isPayloadAvailable(); return top != null && top.isPayloadAvailable();

View File

@ -101,20 +101,6 @@ public abstract class PriorityQueue<T> {
} }
} }
/**
* Adds an Object to a PriorityQueue in log(size) time. If one tries to add
* more objects than maxSize from initialize a RuntimeException
* (ArrayIndexOutOfBound) is thrown.
*
* @deprecated use {@link #add(T)} which returns the new top object,
* saving an additional call to {@link #top()}.
*/
public final void put(T element) {
size++;
heap[size] = element;
upHeap();
}
/** /**
* Adds an Object to a PriorityQueue in log(size) time. If one tries to add * Adds an Object to a PriorityQueue in log(size) time. If one tries to add
* more objects than maxSize from initialize an * more objects than maxSize from initialize an
@ -129,19 +115,6 @@ public abstract class PriorityQueue<T> {
return heap[1]; return heap[1];
} }
/**
* Adds element to the PriorityQueue in log(size) time if either the
* PriorityQueue is not full, or not lessThan(element, top()).
*
* @param element
* @return true if element is added, false otherwise.
* @deprecated use {@link #insertWithOverflow(T)} instead, which
* encourages objects reuse.
*/
public boolean insert(T element) {
return insertWithOverflow(element) != element;
}
/** /**
* insertWithOverflow() is the same as insert() except its * insertWithOverflow() is the same as insert() except its
* return value: it returns the object (if any) that was * return value: it returns the object (if any) that was
@ -154,12 +127,12 @@ public abstract class PriorityQueue<T> {
*/ */
public T insertWithOverflow(T element) { public T insertWithOverflow(T element) {
if (size < maxSize) { if (size < maxSize) {
put(element); add(element);
return null; return null;
} else if (size > 0 && !lessThan(element, heap[1])) { } else if (size > 0 && !lessThan(element, heap[1])) {
T ret = heap[1]; T ret = heap[1];
heap[1] = element; heap[1] = element;
adjustTop(); updateTop();
return ret; return ret;
} else { } else {
return element; return element;
@ -188,30 +161,6 @@ public abstract class PriorityQueue<T> {
return null; return null;
} }
/**
* Should be called when the Object at top changes values. Still log(n) worst
* case, but it's at least twice as fast to
*
* <pre>
* pq.top().change();
* pq.adjustTop();
* </pre>
*
* instead of
*
* <pre>
* o = pq.pop();
* o.change();
* pq.push(o);
* </pre>
*
* @deprecated use {@link #updateTop()} which returns the new top element and
* saves an additional call to {@link #top()}.
*/
public final void adjustTop() {
downHeap();
}
/** /**
* Should be called when the Object at top changes values. Still log(n) worst * Should be called when the Object at top changes values. Still log(n) worst
* case, but it's at least twice as fast to * case, but it's at least twice as fast to

View File

@ -47,7 +47,7 @@ public class TestPriorityQueue extends LuceneTestCase {
{ {
int next = gen.nextInt(); int next = gen.nextInt();
sum += next; sum += next;
pq.put(next); pq.add(next);
} }
// Date end = new Date(); // Date end = new Date();
@ -75,9 +75,9 @@ public class TestPriorityQueue extends LuceneTestCase {
public void testClear() { public void testClear() {
PriorityQueue<Integer> pq = new IntegerQueue(3); PriorityQueue<Integer> pq = new IntegerQueue(3);
pq.put(2); pq.add(2);
pq.put(3); pq.add(3);
pq.put(1); pq.add(1);
assertEquals(3, pq.size()); assertEquals(3, pq.size());
pq.clear(); pq.clear();
assertEquals(0, pq.size()); assertEquals(0, pq.size());
@ -85,12 +85,12 @@ public class TestPriorityQueue extends LuceneTestCase {
public void testFixedSize() { public void testFixedSize() {
PriorityQueue<Integer> pq = new IntegerQueue(3); PriorityQueue<Integer> pq = new IntegerQueue(3);
pq.insert(2); pq.insertWithOverflow(2);
pq.insert(3); pq.insertWithOverflow(3);
pq.insert(1); pq.insertWithOverflow(1);
pq.insert(5); pq.insertWithOverflow(5);
pq.insert(7); pq.insertWithOverflow(7);
pq.insert(1); pq.insertWithOverflow(1);
assertEquals(3, pq.size()); assertEquals(3, pq.size());
assertEquals((Integer) 3, pq.top()); assertEquals((Integer) 3, pq.top());
} }