KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > databinding > datagrid > api > filter > FilterOperationHint


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.databinding.datagrid.api.filter;
19
20 /**
21  * <p>
22  * This class provides a hint for the operation performed by a
23  * {@link org.apache.beehive.netui.databinding.datagrid.api.filter.Filter} instance. The
24  * filter operations supported for a specific query language are not encoded in the
25  * FilterOperation class and are provided on an per-instance basis. The hint provides
26  * a way of representing a generic type of operation. The operations here are common
27  * across query languages and are not meant to be an exhaustive list.
28  * </p>
29  * <p>
30  * Setting a FilterOperationHint on a Filter object, allows query infrastructure to
31  * generically interact with Filter instances regardless of the type of query mechanism.
32  * </p>
33  */

34 public class FilterOperationHint
35     implements java.io.Serializable JavaDoc {
36
37     /**
38      * Int value representing no operation.
39      */

40     public static final int INT_NONE = 0;
41
42     /**
43      * Int value representing equal.
44      */

45     public static final int INT_EQUAL = 1;
46
47     /**
48      * Int value representing not equal.
49      */

50     public static final int INT_NOT_EQUAL = 2;
51
52     /**
53      * Int value representing greater than.
54      */

55     public static final int INT_GREATER_THAN = 3;
56
57     /**
58      * Int value representing less than.
59      */

60     public static final int INT_LESS_THAN = 4;
61
62     /**
63      * Int value representing greater than or equal.
64      */

65     public static final int INT_GREATER_THAN_OR_EQUAL = 5;
66
67     /**
68      * Int value representing less than or equal.
69      */

70     public static final int INT_LESS_THAN_OR_EQUAL = 6;
71
72     /**
73      * Int value representing is one of.
74      */

75     public static final int INT_IS_ONE_OF = 7;
76
77     /**
78      * Int value representing starts with.
79      */

80     public static final int INT_STARTS_WITH = 8;
81
82     /**
83      * Int value representing contains.
84      */

85     public static final int INT_CONTAINS = 9;
86
87     /**
88      * Int value representing is empty.
89      */

90     public static final int INT_IS_EMPTY = 10;
91
92     /**
93      * Int value representing is not empty.
94      */

95     public static final int INT_IS_NOT_EMPTY = 11;
96
97     /**
98      * Operation representing no filter.
99      */

100     public static final FilterOperationHint NONE = new FilterOperationHint(INT_NONE);
101
102     /**
103      * Operation representing equal.
104      */

105     public static final FilterOperationHint EQUAL = new FilterOperationHint(INT_EQUAL);
106
107     /**
108      * Operation representing not equal.
109      */

110     public static final FilterOperationHint NOT_EQUAL = new FilterOperationHint(INT_NOT_EQUAL);
111
112     /**
113      * Operation representing greater than.
114      */

115     public static final FilterOperationHint GREATER_THAN = new FilterOperationHint(INT_GREATER_THAN);
116
117     /**
118      * Operation representing less than.
119      */

120     public static final FilterOperationHint LESS_THAN = new FilterOperationHint(INT_LESS_THAN);
121
122     /**
123      * Operation representing greater than or equal.
124      */

125     public static final FilterOperationHint GREATER_THAN_OR_EQUAL = new FilterOperationHint(INT_GREATER_THAN_OR_EQUAL);
126
127     /**
128      * Operation representing less than or equal.
129      */

130     public static final FilterOperationHint LESS_THAN_OR_EQUAL = new FilterOperationHint(INT_LESS_THAN_OR_EQUAL);
131
132     /**
133      * Operation representing is one of. The implementations of an 'is one of' operation is left
134      * to the interpreter of a Filter instance.
135      */

136     public static final FilterOperationHint IS_ONE_OF = new FilterOperationHint(INT_IS_ONE_OF);
137
138     /**
139      * Operation representing starts with.
140      */

141     public static final FilterOperationHint STARTS_WITH = new FilterOperationHint(INT_STARTS_WITH);
142
143     /**
144      * Operation representing 'contains'. The implementation of a contains operation is left
145      * to the interpreter of a Filter instance.
146      */

147     public static final FilterOperationHint CONTAINS = new FilterOperationHint(INT_CONTAINS);
148
149     /**
150      * Operation representing 'is empty'.
151      */

152     public static final FilterOperationHint IS_EMPTY = new FilterOperationHint(INT_IS_EMPTY);
153
154     /**
155      * Operation representing 'is not empty'.
156      */

157     public static final FilterOperationHint IS_NOT_EMPTY = new FilterOperationHint(INT_IS_NOT_EMPTY);
158
159     /**
160      * Integer representation of the filter operation.
161      */

162     private int _val;
163
164     /**
165      * Private constructor.
166      * @param val the filter value
167      */

168     private FilterOperationHint(int val) {
169         _val = val;
170     }
171
172     /**
173      * Convert this filter operation hint to a readable String. Note, this does not return the
174      * operator -- only text for the operation hint itself.
175      * @return the readable operation name
176      */

177     public final String JavaDoc toString() {
178         switch(_val) {
179             case INT_NONE:
180                 return "NONE";
181             case INT_EQUAL:
182                 return "EQUAL";
183             case INT_NOT_EQUAL:
184                 return "NOT_EQUAL";
185             case INT_GREATER_THAN:
186                 return "GREATER_THAN";
187             case INT_LESS_THAN:
188                 return "LESS_THAN";
189             case INT_GREATER_THAN_OR_EQUAL:
190                 return "GREATER_THAN_OR_EQUAL";
191             case INT_LESS_THAN_OR_EQUAL:
192                 return "LESS_THAN_OR_EQUAL";
193             case INT_IS_ONE_OF:
194                 return "IS_ONE_OF";
195             case INT_STARTS_WITH:
196                 return "STARTS_WITH";
197             case INT_CONTAINS:
198                 return "CONTAINS";
199             case INT_IS_EMPTY:
200                 return "IS_EMPTY";
201             case INT_IS_NOT_EMPTY:
202                 return "IS_NOT_EMPTY";
203         }
204
205         String JavaDoc message = "Encountered an unknown filter operation with value \"" + _val + "\"";
206         assert false : message;
207
208         throw new IllegalStateException JavaDoc(message);
209     }
210
211     /**
212      * Equals method.
213      * @param value value to check
214      * @return <code>true</code> if this hint matches the <code>value</code>. <code>false</code> otherwise.
215      */

216     public boolean equals(Object JavaDoc value) {
217         if(value == this)
218             return true;
219
220         if(value == null || !(value instanceof FilterOperationHint))
221             return false;
222
223         return ((FilterOperationHint)value)._val == _val;
224     }
225
226     /**
227      * Hash code.
228      * @return the hash code
229      */

230     public int hashCode() {
231         return _val;
232     }
233
234     /**
235      * The hint's int value.
236      *
237      * @return the hint's value
238      */

239     public int getValue() {
240         return _val;
241     }
242 }
243
Popular Tags