~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/NumericConfig.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.queryParser.standard.config;
2
 
 
3
 
/**
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
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
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.
18
 
 */
19
 
 
20
 
import java.text.NumberFormat;
21
 
 
22
 
import org.apache.lucene.document.NumericField;
23
 
import org.apache.lucene.search.NumericRangeQuery;
24
 
 
25
 
/**
26
 
 * This class holds the configuration used to parse numeric queries and create
27
 
 * {@link NumericRangeQuery}s.
28
 
 * 
29
 
 * @see NumericRangeQuery
30
 
 * @see NumberFormat
31
 
 */
32
 
public class NumericConfig {
33
 
  
34
 
  private int precisionStep;
35
 
  
36
 
  private NumberFormat format;
37
 
  
38
 
  private NumericField.DataType type;
39
 
  
40
 
  /**
41
 
   * Constructs a {@link NumericConfig} object.
42
 
   * 
43
 
   * @param precisionStep
44
 
   *          the precision used to index the numeric values
45
 
   * @param format
46
 
   *          the {@link NumberFormat} used to parse a {@link String} to
47
 
   *          {@link Number}
48
 
   * @param type
49
 
   *          the numeric type used to index the numeric values
50
 
   * 
51
 
   * @see NumericConfig#setPrecisionStep(int)
52
 
   * @see NumericConfig#setNumberFormat(NumberFormat)
53
 
   * @see #setType(org.apache.lucene.document.NumericField.DataType)
54
 
   */
55
 
  public NumericConfig(int precisionStep, NumberFormat format,
56
 
      NumericField.DataType type) {
57
 
    setPrecisionStep(precisionStep);
58
 
    setNumberFormat(format);
59
 
    setType(type);
60
 
    
61
 
  }
62
 
  
63
 
  /**
64
 
   * Returns the precision used to index the numeric values
65
 
   * 
66
 
   * @return the precision used to index the numeric values
67
 
   * 
68
 
   * @see NumericRangeQuery#getPrecisionStep()
69
 
   */
70
 
  public int getPrecisionStep() {
71
 
    return precisionStep;
72
 
  }
73
 
  
74
 
  /**
75
 
   * Sets the precision used to index the numeric values
76
 
   * 
77
 
   * @param precisionStep
78
 
   *          the precision used to index the numeric values
79
 
   * 
80
 
   * @see NumericRangeQuery#getPrecisionStep()
81
 
   */
82
 
  public void setPrecisionStep(int precisionStep) {
83
 
    this.precisionStep = precisionStep;
84
 
  }
85
 
  
86
 
  /**
87
 
   * Returns the {@link NumberFormat} used to parse a {@link String} to
88
 
   * {@link Number}
89
 
   * 
90
 
   * @return the {@link NumberFormat} used to parse a {@link String} to
91
 
   *         {@link Number}
92
 
   */
93
 
  public NumberFormat getNumberFormat() {
94
 
    return format;
95
 
  }
96
 
  
97
 
  /**
98
 
   * Returns the numeric type used to index the numeric values
99
 
   * 
100
 
   * @return the numeric type used to index the numeric values
101
 
   */
102
 
  public NumericField.DataType getType() {
103
 
    return type;
104
 
  }
105
 
  
106
 
  /**
107
 
   * Sets the numeric type used to index the numeric values
108
 
   * 
109
 
   * @param type the numeric type used to index the numeric values
110
 
   */
111
 
  public void setType(NumericField.DataType type) {
112
 
    
113
 
    if (type == null) {
114
 
      throw new IllegalArgumentException("type cannot be null!");
115
 
    }
116
 
    
117
 
    this.type = type;
118
 
    
119
 
  }
120
 
  
121
 
  /**
122
 
   * Sets the {@link NumberFormat} used to parse a {@link String} to
123
 
   * {@link Number}
124
 
   * 
125
 
   * @param format
126
 
   *          the {@link NumberFormat} used to parse a {@link String} to
127
 
   *          {@link Number}, cannot be <code>null</code>
128
 
   */
129
 
  public void setNumberFormat(NumberFormat format) {
130
 
    
131
 
    if (format == null) {
132
 
      throw new IllegalArgumentException("format cannot be null!");
133
 
    }
134
 
    
135
 
    this.format = format;
136
 
    
137
 
  }
138
 
  
139
 
  @Override
140
 
  public boolean equals(Object obj) {
141
 
    
142
 
    if (obj == this) return true;
143
 
    
144
 
    if (obj instanceof NumericConfig) {
145
 
      NumericConfig other = (NumericConfig) obj;
146
 
      
147
 
      if (this.precisionStep == other.precisionStep
148
 
          && this.type == other.type
149
 
          && (this.format == other.format || (this.format.equals(other.format)))) {
150
 
        return true;
151
 
      }
152
 
      
153
 
    }
154
 
    
155
 
    return false;
156
 
    
157
 
  }
158
 
  
159
 
}