#22344 - changed enum to enumerator

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150001 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2003-08-12 09:22:23 +00:00
parent 91533fb826
commit a89de10f25
8 changed files with 72 additions and 68 deletions

View File

@ -296,6 +296,10 @@ Implementation-Vendor: Lucene
<classpath refid="test.classpath"/>
</javac>
<copy todir="${junit.classes}">
<fileset dir="${junit.src}" excludes="**/*.java"/>
</copy>
<junit printsummary="yes" haltonfailure="no" >
<classpath refid="junit.classpath"/>
<formatter type="plain" />

View File

@ -235,7 +235,7 @@ final class SegmentReader extends IndexReader {
}
return fieldSet;
}
/**
* @see IndexReader#getFieldNames(boolean)
*/
@ -285,7 +285,7 @@ final class SegmentReader extends IndexReader {
private final void openNorms() throws IOException {
for (int i = 0; i < fieldInfos.size(); i++) {
FieldInfo fi = fieldInfos.fieldInfo(i);
if (fi.isIndexed)
if (fi.isIndexed)
norms.put(fi.name,
new Norm(directory.openFile(segment + ".f" + fi.number)));
}
@ -293,9 +293,9 @@ final class SegmentReader extends IndexReader {
private final void closeNorms() throws IOException {
synchronized (norms) {
Enumeration enum = norms.elements();
while (enum.hasMoreElements()) {
Norm norm = (Norm)enum.nextElement();
Enumeration enumerator = norms.elements();
while (enumerator.hasMoreElements()) {
Norm norm = (Norm)enumerator.nextElement();
norm.in.close();
}
}

View File

@ -67,7 +67,7 @@ final class TermInfosReader {
private String segment;
private FieldInfos fieldInfos;
private SegmentTermEnum enum;
private SegmentTermEnum enumerator;
private int size;
TermInfosReader(Directory dir, String seg, FieldInfos fis)
@ -76,15 +76,15 @@ final class TermInfosReader {
segment = seg;
fieldInfos = fis;
enum = new SegmentTermEnum(directory.openFile(segment + ".tis"),
enumerator = new SegmentTermEnum(directory.openFile(segment + ".tis"),
fieldInfos, false);
size = enum.size;
size = enumerator.size;
readIndex();
}
final void close() throws IOException {
if (enum != null)
enum.close();
if (enumerator != null)
enumerator.close();
}
/** Returns the number of term/value pairs in the set. */
@ -136,7 +136,7 @@ final class TermInfosReader {
}
private final void seekEnum(int indexOffset) throws IOException {
enum.seek(indexPointers[indexOffset],
enumerator.seek(indexPointers[indexOffset],
(indexOffset * TermInfosWriter.INDEX_INTERVAL) - 1,
indexTerms[indexOffset], indexInfos[indexOffset]);
}
@ -144,27 +144,27 @@ final class TermInfosReader {
/** Returns the TermInfo for a Term in the set, or null. */
final synchronized TermInfo get(Term term) throws IOException {
if (size == 0) return null;
// optimize sequential access: first try scanning cached enum w/o seeking
if (enum.term() != null // term is at or past current
&& ((enum.prev != null && term.compareTo(enum.prev) > 0)
|| term.compareTo(enum.term()) >= 0)) {
int enumOffset = (enum.position/TermInfosWriter.INDEX_INTERVAL)+1;
// optimize sequential access: first try scanning cached enumerator w/o seeking
if (enumerator.term() != null // term is at or past current
&& ((enumerator.prev != null && term.compareTo(enumerator.prev) > 0)
|| term.compareTo(enumerator.term()) >= 0)) {
int enumOffset = (enumerator.position/TermInfosWriter.INDEX_INTERVAL)+1;
if (indexTerms.length == enumOffset // but before end of block
|| term.compareTo(indexTerms[enumOffset]) < 0)
return scanEnum(term); // no need to seek
}
// random-access: must seek
seekEnum(getIndexOffset(term));
return scanEnum(term);
}
/** Scans within block for matching term. */
private final TermInfo scanEnum(Term term) throws IOException {
while (term.compareTo(enum.term()) > 0 && enum.next()) {}
if (enum.term() != null && term.compareTo(enum.term()) == 0)
return enum.termInfo();
while (term.compareTo(enumerator.term()) > 0 && enumerator.next()) {}
if (enumerator.term() != null && term.compareTo(enumerator.term()) == 0)
return enumerator.termInfo();
else
return null;
}
@ -173,8 +173,8 @@ final class TermInfosReader {
final synchronized Term get(int position) throws IOException {
if (size == 0) return null;
if (enum != null && enum.term() != null && position >= enum.position &&
position < (enum.position + TermInfosWriter.INDEX_INTERVAL))
if (enumerator != null && enumerator.term() != null && position >= enumerator.position &&
position < (enumerator.position + TermInfosWriter.INDEX_INTERVAL))
return scanEnum(position); // can avoid seek
seekEnum(position / TermInfosWriter.INDEX_INTERVAL); // must seek
@ -182,11 +182,11 @@ final class TermInfosReader {
}
private final Term scanEnum(int position) throws IOException {
while(enum.position < position)
if (!enum.next())
while(enumerator.position < position)
if (!enumerator.next())
return null;
return enum.term();
return enumerator.term();
}
/** Returns the position of a Term in the set or -1. */
@ -196,25 +196,25 @@ final class TermInfosReader {
int indexOffset = getIndexOffset(term);
seekEnum(indexOffset);
while(term.compareTo(enum.term()) > 0 && enum.next()) {}
while(term.compareTo(enumerator.term()) > 0 && enumerator.next()) {}
if (term.compareTo(enum.term()) == 0)
return enum.position;
if (term.compareTo(enumerator.term()) == 0)
return enumerator.position;
else
return -1;
}
/** Returns an enumeration of all the Terms and TermInfos in the set. */
final synchronized SegmentTermEnum terms() throws IOException {
if (enum.position != -1) // if not at start
if (enumerator.position != -1) // if not at start
seekEnum(0); // reset to start
return (SegmentTermEnum)enum.clone();
return (SegmentTermEnum)enumerator.clone();
}
/** Returns an enumeration of terms starting at or after the named term. */
final synchronized SegmentTermEnum terms(Term term) throws IOException {
get(term); // seek enum to term
return (SegmentTermEnum)enum.clone();
get(term); // seek enumerator to term
return (SegmentTermEnum)enumerator.clone();
}

View File

@ -128,27 +128,27 @@ public class DateFilter extends Filter {
search results, and false for those that should not. */
public BitSet bits(IndexReader reader) throws IOException {
BitSet bits = new BitSet(reader.maxDoc());
TermEnum enum = reader.terms(new Term(field, start));
TermEnum enumerator = reader.terms(new Term(field, start));
TermDocs termDocs = reader.termDocs();
if (enum.term() == null)
if (enumerator.term() == null)
return bits;
try {
Term stop = new Term(field, end);
while (enum.term().compareTo(stop) <= 0) {
termDocs.seek(enum.term());
while (enumerator.term().compareTo(stop) <= 0) {
termDocs.seek(enumerator.term());
try {
while (termDocs.next())
bits.set(termDocs.doc());
} finally {
termDocs.close();
}
if (!enum.next()) {
if (!enumerator.next()) {
break;
}
}
} finally {
enum.close();
enumerator.close();
}
return bits;
}

View File

@ -74,37 +74,37 @@ import org.apache.lucene.index.Term;
*/
public abstract class MultiTermQuery extends Query {
private Term term;
/** Constructs a query for terms matching <code>term</code>. */
public MultiTermQuery(Term term) {
this.term = term;
}
/** Returns the pattern term. */
public Term getTerm() { return term; }
/** Construct the enumeration to be used, expanding the pattern term. */
protected abstract FilteredTermEnum getEnum(IndexReader reader)
throws IOException;
public Query rewrite(IndexReader reader) throws IOException {
FilteredTermEnum enum = getEnum(reader);
FilteredTermEnum enumerator = getEnum(reader);
BooleanQuery query = new BooleanQuery();
try {
do {
Term t = enum.term();
Term t = enumerator.term();
if (t != null) {
TermQuery tq = new TermQuery(t); // found a match
tq.setBoost(getBoost() * enum.difference()); // set the boost
tq.setBoost(getBoost() * enumerator.difference()); // set the boost
query.add(tq, false, false); // add to query
}
} while (enum.next());
} while (enumerator.next());
} finally {
enum.close();
enumerator.close();
}
return query;
}
public Query combine(Query[] queries) {
return Query.mergeBooleanQueries(queries);
}

View File

@ -71,12 +71,12 @@ public class PrefixQuery extends Query {
public Query rewrite(IndexReader reader) throws IOException {
BooleanQuery query = new BooleanQuery();
TermEnum enum = reader.terms(prefix);
TermEnum enumerator = reader.terms(prefix);
try {
String prefixText = prefix.text();
String prefixField = prefix.field();
do {
Term term = enum.term();
Term term = enumerator.term();
if (term != null &&
term.text().startsWith(prefixText) &&
term.field() == prefixField) {
@ -87,9 +87,9 @@ public class PrefixQuery extends Query {
} else {
break;
}
} while (enum.next());
} while (enumerator.next());
} finally {
enum.close();
enumerator.close();
}
return query;
}

View File

@ -66,11 +66,11 @@ public class RangeQuery extends Query
private Term lowerTerm;
private Term upperTerm;
private boolean inclusive;
/** Constructs a query selecting all terms greater than
/** Constructs a query selecting all terms greater than
* <code>lowerTerm</code> but less than <code>upperTerm</code>.
* There must be at least one term and either term may be null--
* in which case there is no bound on that side, but if there are
* in which case there is no bound on that side, but if there are
* two term, both terms <b>must</b> be for the same field.
*/
public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive)
@ -92,7 +92,7 @@ public class RangeQuery extends Query
BooleanQuery query = new BooleanQuery();
// if we have a lowerTerm, start there. otherwise, start at beginning
if (lowerTerm == null) lowerTerm = new Term(getField(), "");
TermEnum enum = reader.terms(lowerTerm);
TermEnum enumerator = reader.terms(lowerTerm);
try {
String lowerText = null;
String field;
@ -110,7 +110,7 @@ public class RangeQuery extends Query
}
String testField = getField();
do {
Term term = enum.term();
Term term = enumerator.term();
if (term != null && term.field() == testField) {
if (!checkLower || term.text().compareTo(lowerText) > 0) {
checkLower = false;
@ -124,18 +124,18 @@ public class RangeQuery extends Query
tq.setBoost(getBoost()); // set the boost
query.add(tq, false, false); // add to query
}
}
}
else {
break;
}
}
while (enum.next());
while (enumerator.next());
} finally {
enum.close();
enumerator.close();
}
return query;
}
public Query combine(Query[] queries) {
return Query.mergeBooleanQueries(queries);
}
@ -144,7 +144,7 @@ public class RangeQuery extends Query
{
return (lowerTerm != null ? lowerTerm.field() : upperTerm.field());
}
/** Prints a user-readable version of this query. */
public String toString(String field)
{

View File

@ -152,15 +152,15 @@ class TermInfosTest {
start = new Date();
SegmentTermEnum enum = (SegmentTermEnum)reader.terms();
SegmentTermEnum enumerator = reader.terms();
for (int i = 0; i < keys.size(); i++) {
enum.next();
enumerator.next();
Term key = (Term)keys.elementAt(i);
if (!key.equals(enum.term()))
throw new Exception("wrong term: " + enum.term()
if (!key.equals(enumerator.term()))
throw new Exception("wrong term: " + enumerator.term()
+ ", expected: " + key
+ " at " + i);
TermInfo ti = enum.termInfo();
TermInfo ti = enumerator.termInfo();
if (ti.docFreq != docFreqs[i])
throw
new Exception("wrong value: " + Long.toString(ti.docFreq, 16)