From dbff1fc9b519f503129537d59ff553fed1e7944e Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 27 Jul 2009 11:12:36 +0000 Subject: [PATCH] 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 --- .../org/apache/lucene/misc/ChainedFilter.java | 15 ++++--- .../lucene/search/ConstantScoreQuery.java | 4 +- .../org/apache/lucene/search/DocIdSet.java | 13 +++++- .../lucene/search/EmptyDocIdSetIterator.java | 42 ------------------- .../apache/lucene/search/FilteredQuery.java | 4 +- 5 files changed, 23 insertions(+), 55 deletions(-) delete mode 100644 src/java/org/apache/lucene/search/EmptyDocIdSetIterator.java diff --git a/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java b/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java index a36bdfcdb4c..2f0773c210b 100644 --- a/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java +++ b/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java @@ -54,13 +54,12 @@ package org.apache.lucene.misc; * . */ -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(); } } diff --git a/src/java/org/apache/lucene/search/ConstantScoreQuery.java b/src/java/org/apache/lucene/search/ConstantScoreQuery.java index 25a36965641..61910667b9e 100644 --- a/src/java/org/apache/lucene/search/ConstantScoreQuery.java +++ b/src/java/org/apache/lucene/search/ConstantScoreQuery.java @@ -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; } diff --git a/src/java/org/apache/lucene/search/DocIdSet.java b/src/java/org/apache/lucene/search/DocIdSet.java index c8ffa14739f..9d7cbefc5ab 100644 --- a/src/java/org/apache/lucene/search/DocIdSet.java +++ b/src/java/org/apache/lucene/search/DocIdSet.java @@ -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 diff --git a/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.java b/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.java deleted file mode 100644 index 5bd15f0228a..00000000000 --- a/src/java/org/apache/lucene/search/EmptyDocIdSetIterator.java +++ /dev/null @@ -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; } - -} diff --git a/src/java/org/apache/lucene/search/FilteredQuery.java b/src/java/org/apache/lucene/search/FilteredQuery.java index 81339c9bbb0..8130b6574d2 100644 --- a/src/java/org/apache/lucene/search/FilteredQuery.java +++ b/src/java/org/apache/lucene/search/FilteredQuery.java @@ -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;