KickJava   Java API By Example, From Geeks To Geeks.

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


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