1 package org.apache.lucene.queryParser.standard.config;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.text.NumberFormat;
22 import org.apache.lucene.document.NumericField;
23 import org.apache.lucene.search.NumericRangeQuery;
26 * This class holds the configuration used to parse numeric queries and create
27 * {@link NumericRangeQuery}s.
29 * @see NumericRangeQuery
32 public class NumericConfig {
34 private int precisionStep;
36 private NumberFormat format;
38 private NumericField.DataType type;
41 * Constructs a {@link NumericConfig} object.
43 * @param precisionStep
44 * the precision used to index the numeric values
46 * the {@link NumberFormat} used to parse a {@link String} to
49 * the numeric type used to index the numeric values
51 * @see NumericConfig#setPrecisionStep(int)
52 * @see NumericConfig#setNumberFormat(NumberFormat)
53 * @see #setType(org.apache.lucene.document.NumericField.DataType)
55 public NumericConfig(int precisionStep, NumberFormat format,
56 NumericField.DataType type) {
57 setPrecisionStep(precisionStep);
58 setNumberFormat(format);
64 * Returns the precision used to index the numeric values
66 * @return the precision used to index the numeric values
68 * @see NumericRangeQuery#getPrecisionStep()
70 public int getPrecisionStep() {
75 * Sets the precision used to index the numeric values
77 * @param precisionStep
78 * the precision used to index the numeric values
80 * @see NumericRangeQuery#getPrecisionStep()
82 public void setPrecisionStep(int precisionStep) {
83 this.precisionStep = precisionStep;
87 * Returns the {@link NumberFormat} used to parse a {@link String} to
90 * @return the {@link NumberFormat} used to parse a {@link String} to
93 public NumberFormat getNumberFormat() {
98 * Returns the numeric type used to index the numeric values
100 * @return the numeric type used to index the numeric values
102 public NumericField.DataType getType() {
107 * Sets the numeric type used to index the numeric values
109 * @param type the numeric type used to index the numeric values
111 public void setType(NumericField.DataType type) {
114 throw new IllegalArgumentException("type cannot be null!");
122 * Sets the {@link NumberFormat} used to parse a {@link String} to
126 * the {@link NumberFormat} used to parse a {@link String} to
127 * {@link Number}, cannot be <code>null</code>
129 public void setNumberFormat(NumberFormat format) {
131 if (format == null) {
132 throw new IllegalArgumentException("format cannot be null!");
135 this.format = format;
140 public boolean equals(Object obj) {
142 if (obj == this) return true;
144 if (obj instanceof NumericConfig) {
145 NumericConfig other = (NumericConfig) obj;
147 if (this.precisionStep == other.precisionStep
148 && this.type == other.type
149 && (this.format == other.format || (this.format.equals(other.format)))) {