KickJava   Java API By Example, From Geeks To Geeks.

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


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  *
36  * @author Sebastien Chassande-Barrioz
37  */

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