KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > grid > util > NumberFilter


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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 package com.blandware.atleap.webapp.taglib.core.grid.util;
17
18
19 /**
20  * <p>Filter for numbers</p>
21  * <p><a HREF="NumberFilter.java.htm"><i>View Source</i></a></p>
22  *
23  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
24  * @version $Revision: 1.4 $ $Date: 2005/08/05 17:48:33 $
25  */

26 public class NumberFilter extends BaseFilter {
27
28
29     // ~ Instance variables
30

31     private String JavaDoc firstCondition = FilterConditions.NUMBER_EQUAL;
32     private Float JavaDoc firstValue = new Float JavaDoc(0);
33     private String JavaDoc secondCondition = FilterConditions.CONDITION_NOT_SET;
34     private Float JavaDoc secondValue = null;
35     private String JavaDoc logicCopula = FilterConditions.LOGIC_COPULA_AND;
36
37     /**
38      * Creates new instance of NumberFilter
39      *
40      * @param fieldName Name of field to associate filter with
41      */

42     public NumberFilter(String JavaDoc fieldName) {
43         super(fieldName);
44     }
45
46     /**
47      * Creates clause from specified condition and float to compare our field to
48      *
49      * @param condition Condition to insert into clause
50      * @param compareTo Float to compare to
51      * @return Constructed clause
52      */

53     private String JavaDoc createClause(String JavaDoc condition, Float JavaDoc compareTo) {
54         if ( condition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NULL) || condition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NOT_NULL) ) {
55             return createNullComparison(condition);
56         } else {
57             return fieldName + " " + condition + " " + compareTo.toString();
58         }
59     }
60
61     /**
62      * Creates first clause
63      *
64      * @param condition Congruence condition
65      * @param compareTo Float to compare to
66      */

67     public void createFirstClause(String JavaDoc condition, Float JavaDoc compareTo) {
68         this.firstCondition = condition;
69         this.firstValue = compareTo;
70         setFirstClause(createClause(condition, compareTo));
71     }
72
73     /**
74      * Creates second clause
75      *
76      * @param condition Congruence condition
77      * @param compareTo Float to compare to
78      * @param logicCopula Logic copula to place between first and second conditions
79      */

80     public void createSecondClause(String JavaDoc condition, Float JavaDoc compareTo, String JavaDoc logicCopula) {
81         this.secondCondition = condition;
82         this.secondValue = compareTo;
83         this.logicCopula = logicCopula;
84         setSecondClause(createClause(condition, compareTo), logicCopula);
85     }
86
87     /**
88      * Creates second clause with AND logic copula
89      *
90      * @param condition Congruence condition
91      * @param compareTo Float to compare to
92      */

93     public void createSecondClause(String JavaDoc condition, Float JavaDoc compareTo) {
94         createSecondClause(condition, compareTo, FilterConditions.LOGIC_COPULA_AND);
95     }
96
97     /**
98      * Returns first condition
99      *
100      * @return first condition
101      */

102     public String JavaDoc getFirstCondition() {
103         return firstCondition;
104     }
105
106     /**
107      * Returns first value
108      *
109      * @return first value
110      */

111     public Float JavaDoc getFirstValue() {
112         return firstValue;
113     }
114
115     /**
116      * Returns second condition
117      *
118      * @return second condition
119      */

120     public String JavaDoc getSecondCondition() {
121         return secondCondition;
122     }
123
124     /**
125      * Returns second value
126      *
127      * @return second value
128      */

129     public Float JavaDoc getSecondValue() {
130         return secondValue;
131     }
132
133     /**
134      * Returns logic copula
135      *
136      * @return logic copula
137      */

138     public String JavaDoc getLogicCopula() {
139         return logicCopula;
140     }
141
142 }
143
Popular Tags