pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / config / RangeCollatorAttributeImpl.java
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.Collator;
21
22 import org.apache.lucene.queryParser.core.config.AbstractQueryConfig;
23 import org.apache.lucene.queryParser.core.config.ConfigAttribute;
24 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
25 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
26 import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor;
27 import org.apache.lucene.search.TermRangeQuery;
28 import org.apache.lucene.util.AttributeImpl;
29
30 /**
31  * This attribute is used by {@link ParametricRangeQueryNodeProcessor} processor
32  * and must be defined in the {@link QueryConfigHandler}. This attribute tells
33  * the processor which {@link Collator} should be used for a
34  * {@link TermRangeQuery} <br/>
35  * 
36  * @see org.apache.lucene.queryParser.standard.config.RangeCollatorAttribute
37  * 
38  * @deprecated
39  * 
40  */
41 @Deprecated
42 public class RangeCollatorAttributeImpl extends AttributeImpl
43                                 implements RangeCollatorAttribute, ConfigAttribute {
44
45   private static final long serialVersionUID = -6804360312723049526L;
46   
47   private AbstractQueryConfig config;
48
49   { enableBackwards = false; }
50   
51   public RangeCollatorAttributeImpl() {}
52
53   public void setDateResolution(Collator rangeCollator) {
54     config.set(ConfigurationKeys.RANGE_COLLATOR, rangeCollator);
55   }
56
57   public Collator getRangeCollator() {
58     return config.get(ConfigurationKeys.RANGE_COLLATOR);
59   }
60
61   @Override
62   public void clear() {
63     throw new UnsupportedOperationException();
64   }
65
66   @Override
67   public void copyTo(AttributeImpl target) {
68     throw new UnsupportedOperationException();
69   }
70
71   @Override
72   public boolean equals(Object other) {
73
74     if (other instanceof RangeCollatorAttributeImpl) {
75         RangeCollatorAttributeImpl rangeCollatorAttr = (RangeCollatorAttributeImpl) other;
76         
77         Collator thisCollator = getRangeCollator();
78         Collator otherCollator = rangeCollatorAttr.getRangeCollator();
79
80       if (otherCollator == thisCollator
81           || otherCollator.equals(thisCollator)) {
82
83         return true;
84
85       }
86
87     }
88
89     return false;
90
91   }
92
93   @Override
94   public int hashCode() {
95     Collator collator = getRangeCollator();
96     return (collator == null) ? 0 : collator.hashCode();
97   }
98
99   @Override
100   public String toString() {
101     return "<rangeCollatorAttribute rangeCollator='" + getRangeCollator()
102         + "'/>";
103   }
104   
105   public void setQueryConfigHandler(AbstractQueryConfig config) {
106     this.config = config;
107   }
108
109 }