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:
Michael McCandless 2009-07-27 11:12:36 +00:00
parent 094c674c4d
commit dbff1fc9b5
5 changed files with 23 additions and 55 deletions

View File

@ -54,13 +54,12 @@ package org.apache.lucene.misc;
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Filter;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator; 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.OpenBitSet;
import org.apache.lucene.util.OpenBitSetDISI; import org.apache.lucene.util.OpenBitSetDISI;
import org.apache.lucene.util.SortedVIntList; import org.apache.lucene.util.SortedVIntList;
@ -150,11 +149,11 @@ public class ChainedFilter extends Filter
throws IOException { throws IOException {
DocIdSet docIdSet = filter.getDocIdSet(reader); DocIdSet docIdSet = filter.getDocIdSet(reader);
if (docIdSet == null) { if (docIdSet == null) {
return EmptyDocIdSetIterator.getInstance(); return DocIdSet.EMPTY_DOCIDSET.iterator();
} else { } else {
DocIdSetIterator iter = docIdSet.iterator(); DocIdSetIterator iter = docIdSet.iterator();
if (iter == null) { if (iter == null) {
return EmptyDocIdSetIterator.getInstance(); return DocIdSet.EMPTY_DOCIDSET.iterator();
} else { } else {
return iter; return iter;
} }
@ -275,11 +274,11 @@ public class ChainedFilter extends Filter
} else { } else {
DocIdSetIterator disi; DocIdSetIterator disi;
if (dis == null) { if (dis == null) {
disi = EmptyDocIdSetIterator.getInstance(); disi = DocIdSet.EMPTY_DOCIDSET.iterator();
} else { } else {
disi = dis.iterator(); disi = dis.iterator();
if (disi == null) { if (disi == null) {
disi = EmptyDocIdSetIterator.getInstance(); disi = DocIdSet.EMPTY_DOCIDSET.iterator();
} }
} }

View File

@ -115,11 +115,11 @@ public class ConstantScoreQuery extends Query {
theScore = w.getValue(); theScore = w.getValue();
DocIdSet docIdSet = filter.getDocIdSet(reader); DocIdSet docIdSet = filter.getDocIdSet(reader);
if (docIdSet == null) { if (docIdSet == null) {
docIdSetIterator = EmptyDocIdSetIterator.getInstance(); docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
} else { } else {
DocIdSetIterator iter = docIdSet.iterator(); DocIdSetIterator iter = docIdSet.iterator();
if (iter == null) { if (iter == null) {
docIdSetIterator = EmptyDocIdSetIterator.getInstance(); docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
} else { } else {
docIdSetIterator = iter; docIdSetIterator = iter;
} }

View File

@ -28,7 +28,18 @@ public abstract class DocIdSet {
/** An empty {@code DocIdSet} instance for easy use (this is currently /** An empty {@code DocIdSet} instance for easy use (this is currently
* implemented using a {@link SortedVIntList}). */ * 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. /** Provides a {@link DocIdSetIterator} to access the set.
* This may (but is not required to) return null if there * This may (but is not required to) return null if there

View File

@ -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; }
}

View File

@ -83,9 +83,9 @@ extends Query {
} }
Filter f = FilteredQuery.this.filter; Filter f = FilteredQuery.this.filter;
DocIdSet docIdSet = f.getDocIdSet(ir); 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) { if (docIdSetIterator == null) {
docIdSetIterator = EmptyDocIdSetIterator.getInstance(); docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
} }
if (docIdSetIterator.advance(i) == i) { if (docIdSetIterator.advance(i) == i) {
return inner; return inner;