Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 828042) +++ CHANGES.txt (working copy) @@ -88,6 +88,11 @@ also implement java.io.Closeable (IndexReader, IndexWriter, Directory,...). (Uwe Schindler) +* LUCENE-1998: Change all Parameter instances to Java 5 enums. This + is no backwards-break, only a change of the super class. Parameter + was deprecated and will be removed in a later version. + (DM Smith, Uwe Schindler) + Bug fixes * LUCENE-1951: When the text provided to WildcardQuery has no wildcard Index: contrib/analyzers/common/src/java/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilter.java =================================================================== --- contrib/analyzers/common/src/java/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilter.java (revision 828042) +++ contrib/analyzers/common/src/java/org/apache/lucene/analysis/ngram/EdgeNGramTokenFilter.java (working copy) @@ -17,7 +17,6 @@ * limitations under the License. */ -import org.apache.lucene.analysis.Token; import org.apache.lucene.analysis.TokenFilter; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; @@ -36,28 +35,23 @@ public static final int DEFAULT_MAX_GRAM_SIZE = 1; public static final int DEFAULT_MIN_GRAM_SIZE = 1; - // Replace this with an enum when the Java 1.5 upgrade is made, the impl will be simplified /** Specifies which side of the input the n-gram should be generated from */ - public static class Side { - private String label; + public static enum Side { /** Get the n-gram from the front of the input */ - public static Side FRONT = new Side("front"); + FRONT { public String getLabel() { return "front"; } }, /** Get the n-gram from the end of the input */ - public static Side BACK = new Side("back"); + BACK { public String getLabel() { return "back"; } }; - // Private ctor - private Side(String label) { this.label = label; } + public abstract String getLabel(); - public String getLabel() { return label; } - // Get the appropriate Side from a string public static Side getSide(String sideName) { if (FRONT.getLabel().equals(sideName)) { return FRONT; } - else if (BACK.getLabel().equals(sideName)) { + if (BACK.getLabel().equals(sideName)) { return BACK; } return null; Index: contrib/analyzers/common/src/java/org/apache/lucene/analysis/ngram/EdgeNGramTokenizer.java =================================================================== --- contrib/analyzers/common/src/java/org/apache/lucene/analysis/ngram/EdgeNGramTokenizer.java (revision 828042) +++ contrib/analyzers/common/src/java/org/apache/lucene/analysis/ngram/EdgeNGramTokenizer.java (working copy) @@ -17,7 +17,6 @@ * limitations under the License. */ -import org.apache.lucene.analysis.Token; import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.analysis.tokenattributes.TermAttribute; @@ -41,29 +40,23 @@ private TermAttribute termAtt; private OffsetAttribute offsetAtt; - // Replace this with an enum when the Java 1.5 upgrade is made, the impl will be simplified /** Specifies which side of the input the n-gram should be generated from */ - public static class Side { - private String label; + public static enum Side { /** Get the n-gram from the front of the input */ - public static Side FRONT = new Side("front"); + FRONT { public String getLabel() { return "front"; } }, /** Get the n-gram from the end of the input */ - public static Side BACK = new Side("back"); + BACK { public String getLabel() { return "back"; } }; - // Private ctor - private Side(String label) { this.label = label; } + public abstract String getLabel(); - - public String getLabel() { return label; } - // Get the appropriate Side from a string public static Side getSide(String sideName) { if (FRONT.getLabel().equals(sideName)) { return FRONT; } - else if (BACK.getLabel().equals(sideName)) { + if (BACK.getLabel().equals(sideName)) { return BACK; } return null; Index: contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java =================================================================== --- contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java (revision 828042) +++ contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java (working copy) @@ -25,7 +25,6 @@ import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.Parameter; import org.apache.lucene.util.AttributeSource; /** @@ -104,13 +103,7 @@ int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength; Locale locale = Locale.getDefault(); - static final class Operator extends Parameter { - private Operator(String name) { - super(name); - } - static final Operator OR = new Operator("OR"); - static final Operator AND = new Operator("AND"); - } + static enum Operator { OR, AND } /** Constructs a query parser. * @param f the default field for query terms. Index: contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj =================================================================== --- contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj (revision 828042) +++ contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.jj (working copy) @@ -49,7 +49,6 @@ import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.Parameter; import org.apache.lucene.util.AttributeSource; /** @@ -128,13 +127,7 @@ int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength; Locale locale = Locale.getDefault(); - static final class Operator extends Parameter { - private Operator(String name) { - super(name); - } - static final Operator OR = new Operator("OR"); - static final Operator AND = new Operator("AND"); - } + static enum Operator { OR, AND } /** Constructs a query parser. * @param f the default field for query terms. Index: contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java =================================================================== --- contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java (revision 828042) +++ contrib/misc/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java (working copy) @@ -23,7 +23,6 @@ import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.Parameter; import org.apache.lucene.util.AttributeSource; /** Token Manager. */ Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ParametricQueryNode.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ParametricQueryNode.java (revision 828042) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ParametricQueryNode.java (working copy) @@ -30,25 +30,12 @@ private CompareOperator operator; public enum CompareOperator { - LE, LT, GE, GT, EQ, NE; - - public String toString() { - if (LE.equals(this)) { - return "<="; - } else if (LT.equals(this)) { - return "<"; - } else if (GE.equals(this)) { - return ">="; - } else if (GT.equals(this)) { - return ">"; - } else if (EQ.equals(this)) { - return "="; - } else if (NE.equals(this)) { - return "!="; - } else { - throw new IllegalArgumentException("Unknown operator"); - } - } + LE { public String toString() { return "<="; } }, + LT { public String toString() { return "<"; } }, + GE { public String toString() { return ">="; } }, + GT { public String toString() { return ">"; } }, + EQ { public String toString() { return "="; } }, + NE { public String toString() { return "!="; } }; } /** Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ProximityQueryNode.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ProximityQueryNode.java (revision 828042) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/core/nodes/ProximityQueryNode.java (working copy) @@ -36,33 +36,11 @@ private static final long serialVersionUID = 9018220596680832916L; public enum Type { - PARAGRAPH, SENTENCE, NUMBER; + PARAGRAPH { CharSequence toQueryString() { return "WITHIN PARAGRAPH"; } }, + SENTENCE { CharSequence toQueryString() { return "WITHIN SENTENCE"; } }, + NUMBER { CharSequence toQueryString() { return "WITHIN"; } }; - CharSequence toQueryString() { - switch (this) { - case PARAGRAPH: - return "WITHIN PARAGRAPH"; - case SENTENCE: - return "WITHIN SENTENCE"; - case NUMBER: - return "WITHIN"; - default: - return "WITHIN SENTENCE"; - } - } - - public String toString() { - switch (this) { - case PARAGRAPH: - return "PARAGRAPH"; - case SENTENCE: - return "SENTENCE"; - case NUMBER: - return "NUMBER"; - default: - return "NUMBER"; - } - } + abstract CharSequence toQueryString(); } // utility class Index: contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/QueryParserWrapper.java =================================================================== --- contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/QueryParserWrapper.java (revision 828042) +++ contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/QueryParserWrapper.java (working copy) @@ -52,7 +52,6 @@ import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.util.Parameter; /** * This class performs the query parsing using the new query parser @@ -71,18 +70,8 @@ * The default operator for parsing queries. Use * {@link QueryParserWrapper#setDefaultOperator} to change it. */ - static public final class Operator extends Parameter { - private static final long serialVersionUID = 3550299139196880290L; + static public enum Operator { OR, AND } - private Operator(String name) { - super(name); - } - - static public final Operator OR = new Operator("OR"); - - static public final Operator AND = new Operator("AND"); - } - // the nested class: /** Alternative form of QueryParser.Operator.AND */ public static final Operator AND_OPERATOR = Operator.AND; Index: src/java/org/apache/lucene/document/AbstractField.java =================================================================== --- src/java/org/apache/lucene/document/AbstractField.java (revision 828042) +++ src/java/org/apache/lucene/document/AbstractField.java (working copy) @@ -56,36 +56,11 @@ throw new NullPointerException("name cannot be null"); this.name = StringHelper.intern(name); // field names are interned - if (store == Field.Store.YES){ - this.isStored = true; - } - else if (store == Field.Store.NO){ - this.isStored = false; - } - else - throw new IllegalArgumentException("unknown store parameter " + store); + this.isStored = store.isStored(); + this.isIndexed = index.isIndexed(); + this.isTokenized = index.isAnalyzed(); + this.omitNorms = index.omitNorms(); - if (index == Field.Index.NO) { - this.isIndexed = false; - this.isTokenized = false; - } else if (index == Field.Index.ANALYZED) { - this.isIndexed = true; - this.isTokenized = true; - } else if (index == Field.Index.NOT_ANALYZED) { - this.isIndexed = true; - this.isTokenized = false; - } else if (index == Field.Index.NOT_ANALYZED_NO_NORMS) { - this.isIndexed = true; - this.isTokenized = false; - this.omitNorms = true; - } else if (index == Field.Index.ANALYZED_NO_NORMS) { - this.isIndexed = true; - this.isTokenized = true; - this.omitNorms = true; - } else { - throw new IllegalArgumentException("unknown index parameter " + index); - } - this.isBinary = false; setStoreTermVector(termVector); @@ -138,34 +113,9 @@ public String name() { return name; } protected void setStoreTermVector(Field.TermVector termVector) { - if (termVector == Field.TermVector.NO) { - this.storeTermVector = false; - this.storePositionWithTermVector = false; - this.storeOffsetWithTermVector = false; - } - else if (termVector == Field.TermVector.YES) { - this.storeTermVector = true; - this.storePositionWithTermVector = false; - this.storeOffsetWithTermVector = false; - } - else if (termVector == Field.TermVector.WITH_POSITIONS) { - this.storeTermVector = true; - this.storePositionWithTermVector = true; - this.storeOffsetWithTermVector = false; - } - else if (termVector == Field.TermVector.WITH_OFFSETS) { - this.storeTermVector = true; - this.storePositionWithTermVector = false; - this.storeOffsetWithTermVector = true; - } - else if (termVector == Field.TermVector.WITH_POSITIONS_OFFSETS) { - this.storeTermVector = true; - this.storePositionWithTermVector = true; - this.storeOffsetWithTermVector = true; - } - else { - throw new IllegalArgumentException("unknown termVector parameter " + termVector); - } + this.storeTermVector = termVector.isStored(); + this.storePositionWithTermVector = termVector.withPositions(); + this.storeOffsetWithTermVector = termVector.withOffsets(); } /** True iff the value of the field is to be stored in the index for return Index: src/java/org/apache/lucene/document/Field.java =================================================================== --- src/java/org/apache/lucene/document/Field.java (revision 828042) +++ src/java/org/apache/lucene/document/Field.java (working copy) @@ -19,7 +19,6 @@ import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.index.IndexWriter; // for javadoc -import org.apache.lucene.util.Parameter; import org.apache.lucene.util.StringHelper; import java.io.Reader; @@ -36,45 +35,56 @@ public final class Field extends AbstractField implements Fieldable, Serializable { /** Specifies whether and how a field should be stored. */ - public static final class Store extends Parameter implements Serializable { + public static enum Store { - private Store(String name) { - super(name); - } - /** Store the original field value in the index. This is useful for short texts * like a document's title which should be displayed with the results. The * value is stored in its original form, i.e. no analyzer is used before it is * stored. */ - public static final Store YES = new Store("YES"); + YES { + public boolean isStored() { return true; } + }, /** Do not store the field value in the index. */ - public static final Store NO = new Store("NO"); + NO + { + public boolean isStored() { return false; } + }; + + public abstract boolean isStored(); } /** Specifies whether and how a field should be indexed. */ - public static final class Index extends Parameter implements Serializable { + public static enum Index { - private Index(String name) { - super(name); - } - /** Do not index the field value. This field can thus not be searched, * but one can still access its contents provided it is * {@link Field.Store stored}. */ - public static final Index NO = new Index("NO"); + NO { + public boolean isIndexed() { return false; } + public boolean isAnalyzed() { return false; } + public boolean omitNorms() { return true; } + }, /** Index the tokens produced by running the field's * value through an Analyzer. This is useful for * common text. */ - public static final Index ANALYZED = new Index("ANALYZED"); + ANALYZED { + public boolean isIndexed() { return true; } + public boolean isAnalyzed() { return true; } + public boolean omitNorms() { return false; } + }, /** Index the field's value without using an Analyzer, so it can be searched. * As no analyzer is used the value will be stored as a single term. This is * useful for unique Ids like product numbers. */ - public static final Index NOT_ANALYZED = new Index("NOT_ANALYZED"); + NOT_ANALYZED { + public boolean isIndexed() { return true; } + public boolean isAnalyzed() { return false; } + public boolean omitNorms() { return false; } + }, /** Expert: Index the field's value without an Analyzer, * and also disable the storing of norms. Note that you @@ -90,44 +100,96 @@ * above described effect on a field, all instances of * that field must be indexed with NOT_ANALYZED_NO_NORMS * from the beginning. */ - public static final Index NOT_ANALYZED_NO_NORMS = new Index("NOT_ANALYZED_NO_NORMS"); + NOT_ANALYZED_NO_NORMS { + public boolean isIndexed() { return true; } + public boolean isAnalyzed() { return false; } + public boolean omitNorms() { return true; } + }, /** Expert: Index the tokens produced by running the * field's value through an Analyzer, and also * separately disable the storing of norms. See * {@link #NOT_ANALYZED_NO_NORMS} for what norms are * and why you may want to disable them. */ - public static final Index ANALYZED_NO_NORMS = new Index("ANALYZED_NO_NORMS"); + ANALYZED_NO_NORMS { + public boolean isIndexed() { return true; } + public boolean isAnalyzed() { return true; } + public boolean omitNorms() { return true; } + }; + + /** Get the best representation of the index given the flags. */ + public static Index toIndex(boolean indexed, boolean analyzed) { + return toIndex(indexed, analyzed, false); + } + + /** Expert: Get the best representation of the index given the flags. */ + public static Index toIndex(boolean indexed, boolean analyzed, boolean omitNorms) { + + // If it is not indexed nothing else matters + if (!indexed) { + return Index.NO; + } + + // typical, non-expert + if (!omitNorms) { + if (analyzed) { + return Index.ANALYZED; + } + return Index.NOT_ANALYZED; + } + + // Expert: Norms omitted + if (analyzed) { + return Index.ANALYZED_NO_NORMS; + } + return Index.NOT_ANALYZED_NO_NORMS; + } + + public abstract boolean isIndexed(); + public abstract boolean isAnalyzed(); + public abstract boolean omitNorms(); } /** Specifies whether and how a field should have term vectors. */ - public static final class TermVector extends Parameter implements Serializable { + public static enum TermVector { - private TermVector(String name) { - super(name); - } - /** Do not store term vectors. */ - public static final TermVector NO = new TermVector("NO"); + NO { + public boolean isStored() { return false; } + public boolean withPositions() { return false; } + public boolean withOffsets() { return false; } + }, /** Store the term vectors of each document. A term vector is a list * of the document's terms and their number of occurrences in that document. */ - public static final TermVector YES = new TermVector("YES"); + YES { + public boolean isStored() { return true; } + public boolean withPositions() { return false; } + public boolean withOffsets() { return false; } + }, /** * Store the term vector + token position information * * @see #YES */ - public static final TermVector WITH_POSITIONS = new TermVector("WITH_POSITIONS"); + WITH_POSITIONS { + public boolean isStored() { return true; } + public boolean withPositions() { return true; } + public boolean withOffsets() { return false; } + }, /** * Store the term vector + Token offset information * * @see #YES */ - public static final TermVector WITH_OFFSETS = new TermVector("WITH_OFFSETS"); + WITH_OFFSETS { + public boolean isStored() { return true; } + public boolean withPositions() { return false; } + public boolean withOffsets() { return true; } + }, /** * Store the term vector + Token position and offset information @@ -136,7 +198,36 @@ * @see #WITH_POSITIONS * @see #WITH_OFFSETS */ - public static final TermVector WITH_POSITIONS_OFFSETS = new TermVector("WITH_POSITIONS_OFFSETS"); + WITH_POSITIONS_OFFSETS { + public boolean isStored() { return true; } + public boolean withPositions() { return true; } + public boolean withOffsets() { return true; } + }; + + /** Get the best representation of a TermVector given the flags. */ + public static TermVector toTermVector(boolean stored, boolean withOffsets, boolean withPositions) { + + // If it is not stored, nothing else matters. + if (!stored) { + return TermVector.NO; + } + + if (withOffsets) { + if (withPositions) { + return Field.TermVector.WITH_POSITIONS_OFFSETS; + } + return Field.TermVector.WITH_OFFSETS; + } + + if (withPositions) { + return Field.TermVector.WITH_POSITIONS; + } + return Field.TermVector.YES; + } + + public abstract boolean isStored(); + public abstract boolean withPositions(); + public abstract boolean withOffsets(); } @@ -288,38 +379,15 @@ this.fieldsData = value; - if (store == Store.YES){ - this.isStored = true; - } - else if (store == Store.NO){ - this.isStored = false; - } - else - throw new IllegalArgumentException("unknown store parameter " + store); + this.isStored = store.isStored(); + this.isIndexed = index.isIndexed(); + this.isTokenized = index.isAnalyzed(); + this.omitNorms = index.omitNorms(); if (index == Index.NO) { - this.isIndexed = false; - this.isTokenized = false; this.omitTermFreqAndPositions = false; - this.omitNorms = true; - } else if (index == Index.ANALYZED) { - this.isIndexed = true; - this.isTokenized = true; - } else if (index == Index.NOT_ANALYZED) { - this.isIndexed = true; - this.isTokenized = false; - } else if (index == Index.NOT_ANALYZED_NO_NORMS) { - this.isIndexed = true; - this.isTokenized = false; - this.omitNorms = true; - } else if (index == Index.ANALYZED_NO_NORMS) { - this.isIndexed = true; - this.isTokenized = true; - this.omitNorms = true; - } else { - throw new IllegalArgumentException("unknown index parameter " + index); - } - + } + this.isBinary = false; setStoreTermVector(termVector); @@ -449,14 +517,10 @@ this.name = StringHelper.intern(name); // field names are interned fieldsData = value; - if (store == Store.YES) { - isStored = true; - } - else if (store == Store.NO) + if (store == Store.NO) throw new IllegalArgumentException("binary values can't be unstored"); - else - throw new IllegalArgumentException("unknown store parameter " + store); + isStored = store.isStored(); isIndexed = false; isTokenized = false; omitTermFreqAndPositions = false; Index: src/java/org/apache/lucene/document/FieldSelectorResult.java =================================================================== --- src/java/org/apache/lucene/document/FieldSelectorResult.java (revision 828042) +++ src/java/org/apache/lucene/document/FieldSelectorResult.java (working copy) @@ -1,6 +1,5 @@ package org.apache.lucene.document; -import java.io.Serializable; /** * Copyright 2004 The Apache Software Foundation * @@ -21,16 +20,16 @@ * Provides information about what should be done with this Field * **/ -//Replace with an enumerated type in 1.5 -public final class FieldSelectorResult implements Serializable { +public enum FieldSelectorResult { /** * Load this {@link Field} every time the {@link Document} is loaded, reading in the data as it is encountered. * {@link Document#getField(String)} and {@link Document#getFieldable(String)} should not return null. *
* {@link Document#add(Fieldable)} should be called by the Reader. - */ - public transient static final FieldSelectorResult LOAD = new FieldSelectorResult(0); + */ + LOAD, + /** * Lazily load this {@link Field}. This means the {@link Field} is valid, but it may not actually contain its data until * invoked. {@link Document#getField(String)} SHOULD NOT BE USED. {@link Document#getFieldable(String)} is safe to use and should @@ -38,14 +37,16 @@ * * {@link Document#add(Fieldable)} should be called by the Reader. */ - public transient static final FieldSelectorResult LAZY_LOAD = new FieldSelectorResult(1); + LAZY_LOAD, + /** * Do not load the {@link Field}. {@link Document#getField(String)} and {@link Document#getFieldable(String)} should return null. * {@link Document#add(Fieldable)} is not called. * * {@link Document#add(Fieldable)} should not be called by the Reader. */ - public transient static final FieldSelectorResult NO_LOAD = new FieldSelectorResult(2); + NO_LOAD, + /** * Load this field as in the {@link #LOAD} case, but immediately return from {@link Field} loading for the {@link Document}. Thus, the * Document may not have its complete set of Fields. {@link Document#getField(String)} and {@link Document#getFieldable(String)} should @@ -53,37 +54,14 @@ * * {@link Document#add(Fieldable)} should be called by the Reader. */ - public transient static final FieldSelectorResult LOAD_AND_BREAK = new FieldSelectorResult(3); + LOAD_AND_BREAK, - /** Expert: Load the size of this {@link Field} rather than its value. - * Size is measured as number of bytes required to store the field == bytes for a binary or any compressed value, and 2*chars for a String value. - * The size is stored as a binary value, represented as an int in a byte[], with the higher order byte first in [0] - */ - public transient static final FieldSelectorResult SIZE = new FieldSelectorResult(5); + /** Expert: Load the size of this {@link Field} rather than its value. + * Size is measured as number of bytes required to store the field == bytes for a binary or any compressed value, and 2*chars for a String value. + * The size is stored as a binary value, represented as an int in a byte[], with the higher order byte first in [0] + */ + SIZE, - /** Expert: Like {@link #SIZE} but immediately break from the field loading loop, i.e., stop loading further fields, after the size is loaded */ - public transient static final FieldSelectorResult SIZE_AND_BREAK = new FieldSelectorResult(6); - - - - private int id; - - private FieldSelectorResult(int id) { - this.id = id; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final FieldSelectorResult that = (FieldSelectorResult) o; - - if (id != that.id) return false; - - return true; - } - - public int hashCode() { - return id; - } + /** Expert: Like {@link #SIZE} but immediately break from the field loading loop, i.e., stop loading further fields, after the size is loaded */ + SIZE_AND_BREAK } Index: src/java/org/apache/lucene/index/FieldsReader.java =================================================================== --- src/java/org/apache/lucene/index/FieldsReader.java (revision 828042) +++ src/java/org/apache/lucene/index/FieldsReader.java (working copy) @@ -18,7 +18,12 @@ */ import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.document.*; +import org.apache.lucene.document.AbstractField; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldSelector; +import org.apache.lucene.document.FieldSelectorResult; +import org.apache.lucene.document.Fieldable; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.AlreadyClosedException; @@ -298,8 +303,8 @@ fieldsStream.seek(pointer + toRead); } else { Field.Store store = Field.Store.YES; - Field.Index index = getIndexType(fi, tokenize); - Field.TermVector termVector = getTermVectorType(fi); + Field.Index index = Field.Index.toIndex(fi.isIndexed, tokenize); + Field.TermVector termVector = Field.TermVector.toTermVector(fi.storeTermVector, fi.storeOffsetWithTermVector, fi.storePositionWithTermVector); AbstractField f; int length = fieldsStream.readVInt(); @@ -327,8 +332,8 @@ doc.add(new Field(fi.name, b, Field.Store.YES)); } else { Field.Store store = Field.Store.YES; - Field.Index index = getIndexType(fi, tokenize); - Field.TermVector termVector = getTermVectorType(fi); + Field.Index index = Field.Index.toIndex(fi.isIndexed, tokenize); + Field.TermVector termVector = Field.TermVector.toTermVector(fi.storeTermVector, fi.storeOffsetWithTermVector, fi.storePositionWithTermVector); AbstractField f; f = new Field(fi.name, // name @@ -357,37 +362,6 @@ return size; } - private Field.TermVector getTermVectorType(FieldInfo fi) { - Field.TermVector termVector = null; - if (fi.storeTermVector) { - if (fi.storeOffsetWithTermVector) { - if (fi.storePositionWithTermVector) { - termVector = Field.TermVector.WITH_POSITIONS_OFFSETS; - } else { - termVector = Field.TermVector.WITH_OFFSETS; - } - } else if (fi.storePositionWithTermVector) { - termVector = Field.TermVector.WITH_POSITIONS; - } else { - termVector = Field.TermVector.YES; - } - } else { - termVector = Field.TermVector.NO; - } - return termVector; - } - - private Field.Index getIndexType(FieldInfo fi, boolean tokenize) { - Field.Index index; - if (fi.isIndexed && tokenize) - index = Field.Index.ANALYZED; - else if (fi.isIndexed && !tokenize) - index = Field.Index.NOT_ANALYZED; - else - index = Field.Index.NO; - return index; - } - /** * A Lazy implementation of Fieldable that differs loading of fields until asked for, instead of when the Document is * loaded. Index: src/java/org/apache/lucene/queryParser/QueryParser.java =================================================================== --- src/java/org/apache/lucene/queryParser/QueryParser.java (revision 828042) +++ src/java/org/apache/lucene/queryParser/QueryParser.java (working copy) @@ -12,7 +12,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Vector; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.CachingTokenFilter; @@ -34,7 +33,6 @@ import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.Parameter; /** * This class is generated by JavaCC. The most important method is @@ -146,15 +144,8 @@ /** The default operator for parsing queries. * Use {@link QueryParser#setDefaultOperator} to change it. */ - static public final class Operator extends Parameter { - private Operator(String name) { - super(name); - } - static public final Operator OR = new Operator("OR"); - static public final Operator AND = new Operator("AND"); - } + static public enum Operator { OR, AND } - /** Constructs a query parser. * @param f the default field for query terms. * @param a used to find terms in the query text. Index: src/java/org/apache/lucene/queryParser/QueryParser.jj =================================================================== --- src/java/org/apache/lucene/queryParser/QueryParser.jj (revision 828042) +++ src/java/org/apache/lucene/queryParser/QueryParser.jj (working copy) @@ -36,7 +36,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Vector; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.CachingTokenFilter; @@ -58,7 +57,6 @@ import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.Parameter; /** * This class is generated by JavaCC. The most important method is @@ -170,15 +168,8 @@ /** The default operator for parsing queries. * Use {@link QueryParser#setDefaultOperator} to change it. */ - static public final class Operator extends Parameter { - private Operator(String name) { - super(name); - } - static public final Operator OR = new Operator("OR"); - static public final Operator AND = new Operator("AND"); - } + static public enum Operator { OR, AND } - /** Constructs a query parser. * @param f the default field for query terms. * @param a used to find terms in the query text. Index: src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java =================================================================== --- src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java (revision 828042) +++ src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java (working copy) @@ -32,7 +32,6 @@ import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; -import org.apache.lucene.util.Parameter; /** Token Manager. */ public class QueryParserTokenManager implements QueryParserConstants Index: src/java/org/apache/lucene/search/BooleanClause.java =================================================================== --- src/java/org/apache/lucene/search/BooleanClause.java (revision 828042) +++ src/java/org/apache/lucene/search/BooleanClause.java (working copy) @@ -1,7 +1,5 @@ package org.apache.lucene.search; -import org.apache.lucene.util.Parameter; - /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,33 +21,24 @@ public class BooleanClause implements java.io.Serializable { /** Specifies how clauses are to occur in matching documents. */ - public static final class Occur extends Parameter implements java.io.Serializable { - - private Occur(String name) { - // typesafe enum pattern, no public constructor - super(name); - } + public static enum Occur { - public String toString() { - if (this == MUST) return "+"; - if (this == MUST_NOT) return "-"; - return ""; - } - /** Use this operator for clauses that must appear in the matching documents. */ - public static final Occur MUST = new Occur("MUST"); + MUST { public String toString() { return "+"; } }, + /** Use this operator for clauses that should appear in the * matching documents. For a BooleanQuery with noMUST
* clauses one or more SHOULD clauses must match a document
* for the BooleanQuery to match.
* @see BooleanQuery#setMinimumNumberShouldMatch
*/
- public static final Occur SHOULD = new Occur("SHOULD");
+ SHOULD { public String toString() { return ""; } },
+
/** Use this operator for clauses that must not appear in the matching documents.
* Note that it is not possible to search for queries that only consist
* of a MUST_NOT clause. */
- public static final Occur MUST_NOT = new Occur("MUST_NOT");
-
+ MUST_NOT { public String toString() { return "-"; } };
+
}
/** The query whose matching documents are combined by the boolean query.
@@ -85,11 +74,11 @@
}
public boolean isProhibited() {
- return Occur.MUST_NOT.equals(occur);
+ return Occur.MUST_NOT == occur;
}
public boolean isRequired() {
- return Occur.MUST.equals(occur);
+ return Occur.MUST == occur;
}
@@ -100,12 +89,12 @@
return false;
BooleanClause other = (BooleanClause)o;
return this.query.equals(other.query)
- && this.occur.equals(other.occur);
+ && this.occur == other.occur;
}
/** Returns a hash code value for this object.*/
public int hashCode() {
- return query.hashCode() ^ (Occur.MUST.equals(occur)?1:0) ^ (Occur.MUST_NOT.equals(occur)?2:0);
+ return query.hashCode() ^ (Occur.MUST == occur?1:0) ^ (Occur.MUST_NOT == occur?2:0);
}
Index: src/java/org/apache/lucene/util/Parameter.java
===================================================================
--- src/java/org/apache/lucene/util/Parameter.java (revision 828042)
+++ src/java/org/apache/lucene/util/Parameter.java (working copy)
@@ -25,7 +25,9 @@
/**
* A serializable Enum class.
+ * @deprecated Use Java 5 enum
*/
+@SuppressWarnings("serial")
public abstract class Parameter implements Serializable
{
static MapWARNING: if you use this setting, and then - * upgrade to a newer release of Lucene, sizable changes - * may happen. If precise back compatibility is important - * then you should instead explicitly specify an actual - * version. - */ - public static final Version LUCENE_CURRENT = new Version("LUCENE_CURRENT", 0); - /** Match settings and bugs in Lucene's 2.0 release. */ - public static final Version LUCENE_20 = new Version("LUCENE_20", 2000); + LUCENE_20, /** Match settings and bugs in Lucene's 2.1 release. */ - public static final Version LUCENE_21 = new Version("LUCENE_21", 2100); + LUCENE_21, /** Match settings and bugs in Lucene's 2.2 release. */ - public static final Version LUCENE_22 = new Version("LUCENE_22", 2200); + LUCENE_22, /** Match settings and bugs in Lucene's 2.3 release. */ - public static final Version LUCENE_23 = new Version("LUCENE_23", 2300); + LUCENE_23, /** Match settings and bugs in Lucene's 2.4 release. */ - public static final Version LUCENE_24 = new Version("LUCENE_24", 2400); + LUCENE_24, /** Match settings and bugs in Lucene's 2.9 release. */ - public static final Version LUCENE_29 = new Version("LUCENE_29", 2900); + LUCENE_29, - private final int v; + /** Match settings and bugs in Lucene's 3.0 release. */ + LUCENE_30, + + /* Add new constants for later versions **here** to respect order! */ - public Version(String name, int v) { - super(name); - this.v = v; - } + /** Use this to get the latest & greatest settings, bug + * fixes, etc, for Lucene. + * + *
WARNING: if you use this setting, and then + * upgrade to a newer release of Lucene, sizable changes + * may happen. If precise back compatibility is important + * then you should instead explicitly specify an actual + * version. + */ + LUCENE_CURRENT; public boolean onOrAfter(Version other) { - return v == 0 || v >= other.v; + return compareTo(other) >= 0; } } \ No newline at end of file Index: src/test/org/apache/lucene/util/TestVersion.java =================================================================== --- src/test/org/apache/lucene/util/TestVersion.java (revision 0) +++ src/test/org/apache/lucene/util/TestVersion.java (revision 0) @@ -0,0 +1,33 @@ +/** + * 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. + */ + +package org.apache.lucene.util; + +import java.util.EnumSet; + +public class TestVersion extends LuceneTestCase { + + public void test() { + for (Version v : Version.values()) { + assertTrue("LUCENE_CURRENT must be always onOrAfter("+v+")", Version.LUCENE_CURRENT.onOrAfter(v)); + } + assertTrue(Version.LUCENE_30.onOrAfter(Version.LUCENE_29)); + assertTrue(Version.LUCENE_30.onOrAfter(Version.LUCENE_30)); + assertFalse(Version.LUCENE_29.onOrAfter(Version.LUCENE_30)); + } + +} Property changes on: src\test\org\apache\lucene\util\TestVersion.java ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native