add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / config / AllowLeadingWildcardAttributeImpl.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.AllowLeadingWildcardProcessor;
25 import org.apache.lucene.util.AttributeImpl;
26
27 /**
28  * This attribute is used by {@link AllowLeadingWildcardProcessor} processor and
29  * must be defined in the {@link QueryConfigHandler}. It basically tells the
30  * processor if it should allow leading wildcard. <br/>
31  * 
32  * @see org.apache.lucene.queryParser.standard.config.AllowLeadingWildcardAttribute
33  * 
34  * @deprecated
35  */
36 @Deprecated
37 public class AllowLeadingWildcardAttributeImpl extends AttributeImpl 
38                                 implements AllowLeadingWildcardAttribute, ConfigAttribute {
39
40   private static final long serialVersionUID = -2804763012723049527L;
41   
42   private AbstractQueryConfig config;
43
44   { enableBackwards = false; }
45   
46   public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
47     config.set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, allowLeadingWildcard);
48   }
49
50   public boolean isAllowLeadingWildcard() {
51     return config.get(ConfigurationKeys.ALLOW_LEADING_WILDCARD, false);
52   }
53
54   @Override
55   public void clear() {
56     throw new UnsupportedOperationException();
57   }
58
59   @Override
60   public void copyTo(AttributeImpl target) {
61     throw new UnsupportedOperationException();
62   }
63
64   @Override
65   public boolean equals(Object other) {
66
67     if (other instanceof AllowLeadingWildcardAttributeImpl
68         && ((AllowLeadingWildcardAttributeImpl) other).isAllowLeadingWildcard() == isAllowLeadingWildcard()) {
69
70       return true;
71
72     }
73
74     return false;
75
76   }
77
78   @Override
79   public int hashCode() {
80     return isAllowLeadingWildcard() ? -1 : Integer.MAX_VALUE;
81   }
82
83   @Override
84   public String toString() {
85     return "<allowLeadingWildcard allowLeadingWildcard="
86         + isAllowLeadingWildcard() + "/>";
87   }
88
89   public void setQueryConfigHandler(AbstractQueryConfig config) {
90     this.config = config;
91     
92     if (!config.has(ConfigurationKeys.ALLOW_LEADING_WILDCARD)) {
93      config.set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, false); // default in 2.9 
94     }
95     
96   }
97
98 }