KickJava   Java API By Example, From Geeks To Geeks.

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


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

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