add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / config / DefaultOperatorAttributeImpl.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.queryParser.core.config.AbstractQueryConfig;
21 import org.apache.lucene.queryParser.core.config.ConfigAttribute;
22 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
23 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
24 import org.apache.lucene.queryParser.standard.processors.GroupQueryNodeProcessor;
25 import org.apache.lucene.util.AttributeImpl;
26
27 /**
28  * This attribute is used by {@link GroupQueryNodeProcessor} processor and must
29  * be defined in the {@link QueryConfigHandler}. This attribute tells the
30  * processor which is the default boolean operator when no operator is defined
31  * between terms. <br/>
32  * 
33  * @see org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute
34  * 
35  * @deprecated
36  * 
37  */
38 @Deprecated
39 public class DefaultOperatorAttributeImpl extends AttributeImpl
40                                 implements DefaultOperatorAttribute, ConfigAttribute {
41
42   private static final long serialVersionUID = -6804760312723049526L;
43   
44   private AbstractQueryConfig config;
45
46   { enableBackwards = false; }
47   
48   public DefaultOperatorAttributeImpl() {
49     // empty constructor
50   }
51
52   public void setOperator(Operator operator) {
53
54     if (operator == null) {
55       throw new IllegalArgumentException("default operator cannot be null!");
56     }
57
58     org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator newOperator;
59     
60     if (operator == Operator.AND) {
61       newOperator = org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.AND;
62     } else {
63       newOperator = org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.OR;
64     }
65     
66     config.set(ConfigurationKeys.DEFAULT_OPERATOR, newOperator);
67
68   }
69
70   public Operator getOperator() {
71     org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator newOperator = config.get(ConfigurationKeys.DEFAULT_OPERATOR, org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.OR);
72     Operator oldOperator;
73     
74     if (newOperator == org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.AND) {
75       oldOperator = Operator.AND;
76     } else {
77       oldOperator = Operator.OR;
78     }
79     
80     return oldOperator;
81   }
82
83   @Override
84   public void clear() {
85     throw new UnsupportedOperationException();
86   }
87
88   @Override
89   public void copyTo(AttributeImpl target) {
90     throw new UnsupportedOperationException();
91   }
92
93   @Override
94   public boolean equals(Object other) {
95
96     if (other instanceof DefaultOperatorAttributeImpl) {
97         DefaultOperatorAttributeImpl defaultOperatorAttr = (DefaultOperatorAttributeImpl) other;
98
99       if (defaultOperatorAttr.getOperator() == this.getOperator()) {
100         return true;
101
102       }
103
104     }
105
106     return false;
107
108   }
109
110   @Override
111   public int hashCode() {
112     return getOperator().hashCode() * 31;
113   }
114
115   @Override
116   public String toString() {
117     return "<defaultOperatorAttribute operator=" + getOperator().name() + "/>";
118   }
119   
120   public void setQueryConfigHandler(AbstractQueryConfig config) {
121     this.config = config;
122     
123     if (!config.has(ConfigurationKeys.DEFAULT_OPERATOR)) {
124       setOperator(Operator.OR); 
125      }
126     
127   }
128
129 }