KickJava   Java API By Example, From Geeks To Geeks.

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


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