Apache Lucene open-source search software
LUCENE-3606: More cleanup and make IR methods that simply call other abstract methods final
Uwe Schindler8f86a10e8f9f
diff --git a/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.javaindex eabd0191cad..c2399ee73e5 100644--- a/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java+++ b/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java@@ -767,11 +767,11 @@ public class MemoryIndex {}@Override- public int docFreq(Term term) {- Info info = getInfo(term.field());+ public int docFreq(String field, BytesRef term) {+ Info info = getInfo(field);int freq = 0;- if (info != null) freq = info.getPositions(term.bytes()) != null ? 1 : 0;- if (DEBUG) System.err.println("MemoryIndexReader.docFreq: " + term + ", freq:" + freq);+ if (info != null) freq = info.getPositions(term) != null ? 1 : 0;+ if (DEBUG) System.err.println("MemoryIndexReader.docFreq: " + field + ":" + term + ", freq:" + freq);return freq;}diff --git a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java b/lucene/src/java/org/apache/lucene/index/DirectoryReader.javaindex e0b2b1b0b53..0febba2cdc4 100644--- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java+++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java@@ -482,15 +482,6 @@ class DirectoryReader extends IndexReader implements Cloneable {throw new UnsupportedOperationException("please use MultiNorms.norms, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level norms");}- @Override- public int docFreq(Term t) throws IOException {- ensureOpen();- int total = 0; // sum freqs in segments- for (int i = 0; i < subReaders.length; i++)- total += subReaders[i].docFreq(t);- return total;- }-@Overridepublic int docFreq(String field, BytesRef term) throws IOException {ensureOpen();@@ -506,11 +497,6 @@ class DirectoryReader extends IndexReader implements Cloneable {throw new UnsupportedOperationException("please use MultiFields.getFields, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level Fields");}- @Override- public long getUniqueTermCount() throws IOException {- return -1;- }-@Overridepublic Map<String,String> getCommitUserData() {ensureOpen();diff --git a/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java b/lucene/src/java/org/apache/lucene/index/FilterIndexReader.javaindex 19db47f8c32..0fe867d767b 100644--- a/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java+++ b/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java@@ -341,12 +341,6 @@ public class FilterIndexReader extends IndexReader {return in.norms(f);}- @Override- public int docFreq(Term t) throws IOException {- ensureOpen();- return in.docFreq(t);- }-@Overridepublic int docFreq(String field, BytesRef t) throws IOException {ensureOpen();diff --git a/lucene/src/java/org/apache/lucene/index/IndexReader.java b/lucene/src/java/org/apache/lucene/index/IndexReader.javaindex fe2538b5e83..592b1497cba 100644--- a/lucene/src/java/org/apache/lucene/index/IndexReader.java+++ b/lucene/src/java/org/apache/lucene/index/IndexReader.java@@ -170,7 +170,7 @@ public abstract class IndexReader implements Cloneable,Closeable {static int DEFAULT_TERMS_INDEX_DIVISOR = 1;/** Expert: returns the current refCount for this reader */- public int getRefCount() {+ public final int getRefCount() {return refCount.get();}@@ -189,7 +189,7 @@ public abstract class IndexReader implements Cloneable,Closeable {* @see #decRef* @see #tryIncRef*/- public void incRef() {+ public final void incRef() {ensureOpen();refCount.incrementAndGet();}@@ -217,7 +217,7 @@ public abstract class IndexReader implements Cloneable,Closeable {* @see #decRef* @see #incRef*/- public boolean tryIncRef() {+ public final boolean tryIncRef() {int count;while ((count = refCount.get()) > 0) {if (refCount.compareAndSet(count, count+1)) {@@ -255,7 +255,7 @@ public abstract class IndexReader implements Cloneable,Closeable {** @see #incRef*/- public void decRef() throws IOException {+ public final void decRef() throws IOException {ensureOpen();final int rc = refCount.getAndDecrement();if (rc == 1) {@@ -658,14 +658,14 @@ public abstract class IndexReader implements Cloneable,Closeable {* term vectors were not indexed. The returned Fields* instance acts like a single-document inverted index* (the docID will be 0). */- abstract public Fields getTermVectors(int docID)+ public abstract Fields getTermVectors(int docID)throws IOException;/** Retrieve term vector for this document and field, or* null if term vectors were not indexed. The returned* Fields instance acts like a single-document inverted* index (the docID will be 0). */- public Terms getTermVector(int docID, String field)+ public final Terms getTermVector(int docID, String field)throws IOException {Fields vectors = getTermVectors(docID);if (vectors == null) {@@ -699,7 +699,7 @@ public abstract class IndexReader implements Cloneable,Closeable {public abstract int maxDoc();/** Returns the number of deleted documents. */- public int numDeletedDocs() {+ public final int numDeletedDocs() {return maxDoc() - numDocs();}@@ -732,7 +732,7 @@ public abstract class IndexReader implements Cloneable,Closeable {// TODO: we need a separate StoredField, so that the// Document returned here contains that class not// IndexableField- public Document document(int docID) throws CorruptIndexException, IOException {+ public final Document document(int docID) throws CorruptIndexException, IOException {ensureOpen();if (docID < 0 || docID >= maxDoc()) {throw new IllegalArgumentException("docID must be >= 0 and < maxDoc=" + maxDoc() + " (got docID=" + docID + ")");@@ -791,7 +791,7 @@ public abstract class IndexReader implements Cloneable,Closeable {* through them yourself. */public abstract PerDocValues perDocValues() throws IOException;- public int docFreq(Term term) throws IOException {+ public final int docFreq(Term term) throws IOException {return docFreq(term.field(), term.bytes());}@@ -822,7 +822,7 @@ public abstract class IndexReader implements Cloneable,Closeable {* field does not exists. This method does not take into* account deleted documents that have not yet been merged* away. */- public long totalTermFreq(String field, BytesRef term) throws IOException {+ public final long totalTermFreq(String field, BytesRef term) throws IOException {final Fields fields = fields();if (fields == null) {return 0;@@ -840,7 +840,7 @@ public abstract class IndexReader implements Cloneable,Closeable {}/** This may return null if the field does not exist.*/- public Terms terms(String field) throws IOException {+ public final Terms terms(String field) throws IOException {final Fields fields = fields();if (fields == null) {return null;@@ -851,7 +851,7 @@ public abstract class IndexReader implements Cloneable,Closeable {/** Returns {@link DocsEnum} for the specified field &* term. This may return null, if either the field or* term does not exist. */- public DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, boolean needsFreqs) throws IOException {+ public final DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, boolean needsFreqs) throws IOException {assert field != null;assert term != null;final Fields fields = fields();@@ -871,7 +871,7 @@ public abstract class IndexReader implements Cloneable,Closeable {* field & term. This may return null, if either the* field or term does not exist, or, positions were not* indexed for this field. */- public DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term) throws IOException {+ public final DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term) throws IOException {assert field != null;assert term != null;final Fields fields = fields();@@ -892,7 +892,7 @@ public abstract class IndexReader implements Cloneable,Closeable {* {@link TermState}. This may return null, if either the field or the term* does not exists or the {@link TermState} is invalid for the underlying* implementation.*/- public DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, TermState state, boolean needsFreqs) throws IOException {+ public final DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, TermState state, boolean needsFreqs) throws IOException {assert state != null;assert field != null;final Fields fields = fields();@@ -912,7 +912,7 @@ public abstract class IndexReader implements Cloneable,Closeable {* {@link TermState}. This may return null, if either the field or the term* does not exists, the {@link TermState} is invalid for the underlying* implementation, or positions were not indexed for this field. */- public DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term, TermState state) throws IOException {+ public final DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term, TermState state) throws IOException {assert state != null;assert field != null;final Fields fields = fields();@@ -1109,12 +1109,6 @@ public abstract class IndexReader implements Cloneable,Closeable {* top-level context holds a <code>null</code> {@link CompositeReaderContext#leaves}* reference. Only the top-level context maintains the convenience leaf-view* for performance reasons.- * <p>- * NOTE: You should not try using sub-readers returned by this method to make- * any changes (deleteDocument, etc.). While this might succeed for- * one composite reader (like MultiReader), it will most likely lead to index- * corruption for other readers (like DirectoryReader obtained through- * {@link #open}. Use the top-level context's reader directly.** @lucene.experimental*/@@ -1135,7 +1129,10 @@ public abstract class IndexReader implements Cloneable,Closeable {* Instead, you should call {@link* #getSequentialSubReaders} and ask each sub reader for* its unique term count. */- public long getUniqueTermCount() throws IOException {+ public final long getUniqueTermCount() throws IOException {+ if (!getTopReaderContext().isAtomic) {+ return -1;+ }final Fields fields = fields();if (fields == null) {return 0;diff --git a/lucene/src/java/org/apache/lucene/index/MultiReader.java b/lucene/src/java/org/apache/lucene/index/MultiReader.javaindex 4c807b78346..fdc364dfe4f 100644--- a/lucene/src/java/org/apache/lucene/index/MultiReader.java+++ b/lucene/src/java/org/apache/lucene/index/MultiReader.java@@ -82,11 +82,6 @@ public class MultiReader extends IndexReader implements Cloneable {return ReaderUtil.buildReaderContext(this);}- @Override- public long getUniqueTermCount() throws IOException {- throw new UnsupportedOperationException("");- }-@Overridepublic Fields fields() throws IOException {throw new UnsupportedOperationException("please use MultiFields.getFields, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level Fields");@@ -256,15 +251,6 @@ public class MultiReader extends IndexReader implements Cloneable {public synchronized byte[] norms(String field) throws IOException {throw new UnsupportedOperationException("please use MultiNorms.norms, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level norms");}-- @Override- public int docFreq(Term t) throws IOException {- ensureOpen();- int total = 0; // sum freqs in segments- for (int i = 0; i < subReaders.length; i++)- total += subReaders[i].docFreq(t);- return total;- }@Overridepublic int docFreq(String field, BytesRef t) throws IOException {diff --git a/lucene/src/java/org/apache/lucene/index/ParallelReader.java b/lucene/src/java/org/apache/lucene/index/ParallelReader.javaindex b7ef3f31c64..8ce4258c3a8 100644--- a/lucene/src/java/org/apache/lucene/index/ParallelReader.java+++ b/lucene/src/java/org/apache/lucene/index/ParallelReader.java@@ -384,13 +384,6 @@ public class ParallelReader extends IndexReader {return bytes;}- @Override- public int docFreq(Term term) throws IOException {- ensureOpen();- IndexReader reader = fieldToReader.get(term.field());- return reader==null ? 0 : reader.docFreq(term);- }-@Overridepublic int docFreq(String field, BytesRef term) throws IOException {ensureOpen();