pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / queries / src / java / org / apache / lucene / search / FilterClause.java
1 package org.apache.lucene.search;
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.search.BooleanClause.Occur;
21 import org.apache.lucene.search.Filter;
22
23 /**
24  * A Filter that wrapped with an indication of how that filter
25  * is used when composed with another filter.
26  * (Follows the boolean logic in BooleanClause for composition 
27  * of queries.)
28  */
29 public final class FilterClause {
30
31   private final Occur occur;
32   private final Filter filter;
33
34   /**
35    * Create a new FilterClause
36    * @param filter A Filter object containing a BitSet
37    * @param occur A parameter implementation indicating SHOULD, MUST or MUST NOT
38    */
39
40   public FilterClause(Filter filter, Occur occur) {
41     this.occur = occur;
42     this.filter = filter;
43   }
44
45   /**
46    * Returns this FilterClause's filter
47    * @return A Filter object
48    */
49   public Filter getFilter() {
50     return filter;
51   }
52
53   /**
54    * Returns this FilterClause's occur parameter
55    * @return An Occur object
56    */
57   public Occur getOccur() {
58     return occur;
59   }
60
61   @Override
62   public boolean equals(Object o) {
63     if (o == this)
64       return true;
65     if (o == null || !(o instanceof FilterClause))
66       return false;
67     final FilterClause other = (FilterClause)o;
68     return this.filter.equals(other.filter)
69       && this.occur == other.occur;
70   }
71
72   @Override
73   public int hashCode() {
74     return filter.hashCode() ^ occur.hashCode();
75   }
76
77   @Override
78   public String toString() {
79     return occur.toString() + filter.toString();
80   }
81
82 }