From 4a9ef8447dd3579550bcfe47453f9235260e2de5 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Tue, 25 Aug 2009 23:12:22 +0000 Subject: [PATCH] LUCENE-1826: NumericTokenStream is not a Tokenizer subclass but source of tokens and should therefore also have AttributeSource/AttributeFactory ctors. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@807849 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/analysis/NumericTokenStream.java | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/lucene/analysis/NumericTokenStream.java b/src/java/org/apache/lucene/analysis/NumericTokenStream.java index 1ac922b2b54..2d1a54e1d0b 100644 --- a/src/java/org/apache/lucene/analysis/NumericTokenStream.java +++ b/src/java/org/apache/lucene/analysis/NumericTokenStream.java @@ -17,6 +17,7 @@ package org.apache.lucene.analysis; * limitations under the License. */ +import org.apache.lucene.util.AttributeSource; import org.apache.lucene.util.NumericUtils; import org.apache.lucene.document.NumericField; // for javadocs import org.apache.lucene.search.NumericRangeQuery; // for javadocs @@ -110,12 +111,37 @@ public final class NumericTokenStream extends TokenStream { * before using set a value using the various set???Value() methods. */ public NumericTokenStream(final int precisionStep) { + super(); + this.precisionStep = precisionStep; + if (precisionStep < 1) + throw new IllegalArgumentException("precisionStep must be >=1"); + } + + /** + * Expert: Creates a token stream for numeric values with the specified + * precisionStep using the given {@link AttributeSource}. + * The stream is not yet initialized, + * before using set a value using the various set???Value() methods. + */ + public NumericTokenStream(AttributeSource source, final int precisionStep) { + super(source); + this.precisionStep = precisionStep; + if (precisionStep < 1) + throw new IllegalArgumentException("precisionStep must be >=1"); + } + + /** + * Expert: Creates a token stream for numeric values with the specified + * precisionStep using the given + * {@link org.apache.lucene.util.AttributeSource.AttributeFactory}. + * The stream is not yet initialized, + * before using set a value using the various set???Value() methods. + */ + public NumericTokenStream(AttributeFactory factory, final int precisionStep) { + super(factory); this.precisionStep = precisionStep; if (precisionStep < 1) throw new IllegalArgumentException("precisionStep must be >=1"); - termAtt = (TermAttribute) addAttribute(TermAttribute.class); - typeAtt = (TypeAttribute) addAttribute(TypeAttribute.class); - posIncrAtt = (PositionIncrementAttribute) addAttribute(PositionIncrementAttribute.class); } /** @@ -216,9 +242,9 @@ public final class NumericTokenStream extends TokenStream { } // members - private final TermAttribute termAtt; - private final TypeAttribute typeAtt; - private final PositionIncrementAttribute posIncrAtt; + private final TermAttribute termAtt = (TermAttribute) addAttribute(TermAttribute.class); + private final TypeAttribute typeAtt = (TypeAttribute) addAttribute(TypeAttribute.class); + private final PositionIncrementAttribute posIncrAtt = (PositionIncrementAttribute) addAttribute(PositionIncrementAttribute.class); private int shift = 0, valSize = 0; // valSize==0 means not initialized private final int precisionStep;