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