KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > expression > lib > GreaterEqual


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 /**
25  * Package definition.
26  */

27
28 package org.objectweb.medor.expression.lib;
29
30 import org.objectweb.medor.expression.api.Expression;
31 import org.objectweb.medor.expression.api.Operator;
32
33 import java.sql.Time JavaDoc;
34 import java.sql.Timestamp JavaDoc;
35 import java.text.Collator JavaDoc;
36 import java.util.Date JavaDoc;
37
38 /**
39  * This class implements the QueryComparator interface; it represents ">="
40  * mathematical comparator. Methods evaluate allow comparison between different
41  * variable types; int , char, long, ...
42  */

43 public class GreaterEqual extends BasicComparator {
44
45     private int strength = Collator.PRIMARY;
46
47     public GreaterEqual() {
48     }
49
50     public GreaterEqual(int strength) {
51         this.strength = strength;
52     }
53
54     public GreaterEqual(Expression l, Expression r) {
55         super(l, r);
56     }
57     public Object JavaDoc clone(Object JavaDoc clone, java.util.Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
58         clone = super.clone(clone, obj2clone);
59         ((GreaterEqual) clone).strength = strength;
60         return clone;
61     }
62
63     public boolean evaluate(Object JavaDoc op1, Object JavaDoc op2) {
64         boolean result = false;
65         if (op1 instanceof Character JavaDoc) {
66             Character JavaDoc o1 = (Character JavaDoc) op1;
67             Character JavaDoc o2 = (Character JavaDoc) op2;
68             result = (o1.compareTo(o2) >= 0);
69         }
70         else if (op1 instanceof Long JavaDoc) {
71             Long JavaDoc o1 = (Long JavaDoc) op1;
72             Long JavaDoc o2 = (Long JavaDoc) op2;
73             result = (o1.compareTo(o2) >= 0);
74         }
75         else if (op1 instanceof Short JavaDoc) {
76             Short JavaDoc o1 = (Short JavaDoc) op1;
77             Short JavaDoc o2 = (Short JavaDoc) op2;
78             result = (o1.compareTo(o2) >= 0);
79         }
80         else if (op1 instanceof Integer JavaDoc) {
81             Integer JavaDoc o1 = (Integer JavaDoc) op1;
82             Integer JavaDoc o2 = (Integer JavaDoc) op2;
83             result = (o1.compareTo(o2) >= 0);
84         }
85         else if (op1 instanceof Float JavaDoc) {
86             Float JavaDoc o1 = (Float JavaDoc) op1;
87             Float JavaDoc o2 = (Float JavaDoc) op2;
88             result = (o1.compareTo(o2) >= 0);
89         }
90         else if (op1 instanceof Double JavaDoc) {
91             Double JavaDoc o1 = (Double JavaDoc) op1;
92             Double JavaDoc o2 = (Double JavaDoc) op2;
93             result = (o1.compareTo(o2) >= 0);
94         }
95         else if (op1 instanceof Byte JavaDoc) {
96             Byte JavaDoc o1 = (Byte JavaDoc) op1;
97             Byte JavaDoc o2 = (Byte JavaDoc) op2;
98             result = (o1.compareTo(o2) >= 0);
99         }
100         else if (op1 instanceof Date JavaDoc) {
101             Date JavaDoc o1 = (Date JavaDoc) op1;
102             Date JavaDoc o2 = (Date JavaDoc) op2;
103             result = (o1.compareTo(o2) >= 0);
104
105         }
106         else if (op1 instanceof Time JavaDoc) {
107             Time JavaDoc o1 = (Time JavaDoc) op1;
108             Time JavaDoc o2 = (Time JavaDoc) op2;
109             result = (o1.compareTo(o2) >= 0);
110
111         }
112         else if (op1 instanceof Timestamp JavaDoc) {
113             Timestamp JavaDoc o1 = (Timestamp JavaDoc) op1;
114             Timestamp JavaDoc o2 = (Timestamp JavaDoc) op2;
115             result = (o1.compareTo(o2) >= 0);
116
117         }
118         else if (op1 instanceof String JavaDoc) {
119             Collator JavaDoc myCollator = Collator.getInstance();
120             myCollator.setStrength(strength);
121             String JavaDoc o1 = (String JavaDoc) op1;
122             String JavaDoc o2 = (String JavaDoc) op2;
123             result = (myCollator.compare(o1, o2) >= 0);
124         }
125         return result;
126     }
127
128     public boolean evaluate(int op1, int op2) {
129         return (op1 >= op2);
130     }
131
132     public boolean evaluate(int op1, short op2) {
133         return (op1 >= op2);
134     }
135
136     public boolean evaluate(int op1, long op2) {
137         return (op1 >= op2);
138     }
139
140     public boolean evaluate(int op1, float op2) {
141         return (op1 >= op2);
142     }
143
144     public boolean evaluate(int op1, double op2) {
145         return (op1 >= op2);
146     }
147
148     public boolean evaluate(float op1, float op2) {
149         return (op1 >= op2);
150     }
151
152     public boolean evaluate(float op1, short op2) {
153         return (op1 >= op2);
154     }
155
156     public boolean evaluate(float op1, int op2) {
157         return (op1 >= op2);
158     }
159
160     public boolean evaluate(float op1, long op2) {
161         return (op1 >= op2);
162     }
163
164     public boolean evaluate(float op1, double op2) {
165         return (op1 >= op2);
166     }
167
168     public boolean evaluate(char op1, char op2) {
169         return (op1 >= op2);
170     }
171
172     public boolean evaluate(long op1, short op2) {
173         return (op1 >= op2);
174     }
175
176     public boolean evaluate(long op1, int op2) {
177         return (op1 >= op2);
178     }
179
180     public boolean evaluate(long op1, long op2) {
181         return (op1 >= op2);
182     }
183
184     public boolean evaluate(long op1, float op2) {
185         return (op1 >= op2);
186     }
187
188     public boolean evaluate(long op1, double op2) {
189         return (op1 >= op2);
190     }
191
192     public boolean evaluate(double op1, short op2) {
193         return (op1 >= op2);
194     }
195
196     public boolean evaluate(double op1, int op2) {
197         return (op1 >= op2);
198     }
199
200     public boolean evaluate(double op1, long op2) {
201         return (op1 >= op2);
202     }
203
204     public boolean evaluate(double op1, float op2) {
205         return (op1 >= op2);
206     }
207
208     public boolean evaluate(double op1, double op2) {
209         return (op1 >= op2);
210     }
211
212     public boolean evaluate(boolean op1, boolean op2) {
213         return false;
214     }
215
216     public boolean evaluate(String JavaDoc op1, String JavaDoc op2) {
217         //strength = opt;
218
Collator JavaDoc myCollator = Collator.getInstance();
219         myCollator.setStrength(strength);
220         return (myCollator.compare(op1, op2) >= 0);
221     }
222
223     public String JavaDoc getOperatorString() {
224         return Operator.GREATEREQUAL;
225     }
226
227 }
228
229
Popular Tags