一种队列。可以使插入其中的object自动按照某种规律排序。该类是一个抽象类。只需要实现方法就可以定时排序规则。例如lucene里的HitQueue.java 就是将从多个索引里传出来的结果都插入其中。并且按照文档score排序。实现如下
final class HitQueue extends PriorityQueue {
private boolean prePopulate;
HitQueue(int size, boolean prePopulate) {
this.prePopulate = prePopulate;
initialize(size);
}
// Returns null if prePopulate is false.
protected Object getSentinelObject() {
// 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,
// TopScoreDocCollector will always add the object to the queue.
return !prePopulate ? null : new ScoreDoc(Integer.MAX_VALUE, Float.NEGATIVE_INFINITY);
}
protected final boolean lessThan(Object a, Object b) {
ScoreDoc hitA = (ScoreDoc)a;
ScoreDoc hitB = (ScoreDoc)b;
if (hitA.score == hitB.score)
return hitA.doc > hitB.doc;
else
return hitA.score < hitB.score;
}
}
问一下,人人上的李岩是你吗?