mirror of https://github.com/apache/lucene.git
LUCENE-1754: just use EMPTY_DOCIDSET.iterator() instead of new EmptyDocIdSetIterator
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@798102 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
094c674c4d
commit
dbff1fc9b5
|
@ -54,13 +54,12 @@ package org.apache.lucene.misc;
|
|||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.Filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.DocIdSet;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.EmptyDocIdSetIterator;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.util.OpenBitSet;
|
||||
import org.apache.lucene.util.OpenBitSetDISI;
|
||||
import org.apache.lucene.util.SortedVIntList;
|
||||
|
@ -150,11 +149,11 @@ public class ChainedFilter extends Filter
|
|||
throws IOException {
|
||||
DocIdSet docIdSet = filter.getDocIdSet(reader);
|
||||
if (docIdSet == null) {
|
||||
return EmptyDocIdSetIterator.getInstance();
|
||||
return DocIdSet.EMPTY_DOCIDSET.iterator();
|
||||
} else {
|
||||
DocIdSetIterator iter = docIdSet.iterator();
|
||||
if (iter == null) {
|
||||
return EmptyDocIdSetIterator.getInstance();
|
||||
return DocIdSet.EMPTY_DOCIDSET.iterator();
|
||||
} else {
|
||||
return iter;
|
||||
}
|
||||
|
@ -275,11 +274,11 @@ public class ChainedFilter extends Filter
|
|||
} else {
|
||||
DocIdSetIterator disi;
|
||||
if (dis == null) {
|
||||
disi = EmptyDocIdSetIterator.getInstance();
|
||||
disi = DocIdSet.EMPTY_DOCIDSET.iterator();
|
||||
} else {
|
||||
disi = dis.iterator();
|
||||
if (disi == null) {
|
||||
disi = EmptyDocIdSetIterator.getInstance();
|
||||
disi = DocIdSet.EMPTY_DOCIDSET.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,11 +115,11 @@ public class ConstantScoreQuery extends Query {
|
|||
theScore = w.getValue();
|
||||
DocIdSet docIdSet = filter.getDocIdSet(reader);
|
||||
if (docIdSet == null) {
|
||||
docIdSetIterator = EmptyDocIdSetIterator.getInstance();
|
||||
docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
|
||||
} else {
|
||||
DocIdSetIterator iter = docIdSet.iterator();
|
||||
if (iter == null) {
|
||||
docIdSetIterator = EmptyDocIdSetIterator.getInstance();
|
||||
docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
|
||||
} else {
|
||||
docIdSetIterator = iter;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,18 @@ public abstract class DocIdSet {
|
|||
|
||||
/** An empty {@code DocIdSet} instance for easy use (this is currently
|
||||
* implemented using a {@link SortedVIntList}). */
|
||||
public static final DocIdSet EMPTY_DOCIDSET = new SortedVIntList(new int[0]);
|
||||
public static final DocIdSet EMPTY_DOCIDSET = new SortedVIntList(new int[0]) {
|
||||
|
||||
private final DocIdSetIterator iterator = new DocIdSetIterator() {
|
||||
public int advance(int target) throws IOException { return NO_MORE_DOCS; }
|
||||
public int docID() { return NO_MORE_DOCS; }
|
||||
public int nextDoc() throws IOException { return NO_MORE_DOCS; }
|
||||
};
|
||||
|
||||
public DocIdSetIterator iterator() {
|
||||
return iterator;
|
||||
}
|
||||
};
|
||||
|
||||
/** Provides a {@link DocIdSetIterator} to access the set.
|
||||
* This may (but is not required to) return null if there
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package org.apache.lucene.search;
|
||||
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An empty implementation for {@link DocIdSetIterator}. This can be used by
|
||||
* classes which receive a null {@link DocIdSet} from
|
||||
* {@link Filter#getDocIdSet(org.apache.lucene.index.IndexReader)}.
|
||||
*/
|
||||
public final class EmptyDocIdSetIterator extends DocIdSetIterator {
|
||||
|
||||
private static final DocIdSetIterator instance = new EmptyDocIdSetIterator();
|
||||
|
||||
public static DocIdSetIterator getInstance() { return instance; }
|
||||
|
||||
// to prevent instantiation
|
||||
private EmptyDocIdSetIterator() { }
|
||||
|
||||
public int advance(int target) throws IOException { return NO_MORE_DOCS; }
|
||||
|
||||
public int docID() { return NO_MORE_DOCS; }
|
||||
|
||||
public int nextDoc() throws IOException { return NO_MORE_DOCS; }
|
||||
|
||||
}
|
|
@ -83,9 +83,9 @@ extends Query {
|
|||
}
|
||||
Filter f = FilteredQuery.this.filter;
|
||||
DocIdSet docIdSet = f.getDocIdSet(ir);
|
||||
DocIdSetIterator docIdSetIterator = docIdSet == null ? EmptyDocIdSetIterator.getInstance() : docIdSet.iterator();
|
||||
DocIdSetIterator docIdSetIterator = docIdSet == null ? DocIdSet.EMPTY_DOCIDSET.iterator() : docIdSet.iterator();
|
||||
if (docIdSetIterator == null) {
|
||||
docIdSetIterator = EmptyDocIdSetIterator.getInstance();
|
||||
docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
|
||||
}
|
||||
if (docIdSetIterator.advance(i) == i) {
|
||||
return inner;
|
||||
|
|
Loading…
Reference in New Issue