KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > api > jms > selector > syntax > MantaLong


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Coridan.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46 package org.mr.api.jms.selector.syntax;
47
48
49 /**
50  * This class is an adapter for the Long type.
51  *
52  */

53 final class MantaLong extends MantaNumber {
54
55     /**
56      * The wrapped value
57      */

58     private long value;
59
60     
61     /**
62      * Construct a new MantaLong
63      *
64      * @param value the underlying value
65      */

66     public MantaLong(final long value) {
67         this.value = value;
68     }//MantaLong
69

70     
71     /**
72      * Returns the addition of a number to this
73      *
74      * @param number the number to add
75      * @return the value of this + number
76      */

77     public MantaNumber add(final MantaNumber number) {
78         MantaNumber result;
79         
80         if (number instanceof MantaDouble) {
81             result = promote().add(number);
82         }//if
83
else {
84             result = new MantaLong(value + number.getLong());
85         }//else
86
return result;
87     }//add
88

89
90     /**
91      * Returns the value of the substraction of a number from this
92      *
93      * @param number the number to subtract
94      * @return the value of this - number
95      */

96     public MantaNumber subtract(final MantaNumber number) {
97         MantaNumber result;
98         if (number instanceof MantaDouble) {
99             result = promote().subtract(number);
100         }//if
101
else {
102             result = new MantaLong(value - number.getLong());
103         }//else
104
return result;
105     }//subtract
106

107     
108     /**
109      * Returns the multiplication of a number to this
110      *
111      * @param number the number to multiply
112      * @return the value of this * number
113      */

114     public MantaNumber multiply(final MantaNumber number) {
115         MantaNumber result;
116         if (number instanceof MantaDouble) {
117             result = promote().multiply(number);
118         }//if
119
else {
120             result = new MantaLong(value * number.getLong());
121         }//else
122
return result;
123     }//multiply
124

125
126     /**
127      * Returns the division of a number from this
128      *
129      * @param number the number to divide
130      * @return the value of this / number
131      */

132     public MantaNumber divide(final MantaNumber number) {
133         MantaNumber result = null;
134         try {
135             if (number instanceof MantaDouble) {
136                 result = promote().divide(number);
137             }//if
138
else {
139                 result = new MantaLong(value / number.getLong());
140             }//else
141
}//try
142
catch (ArithmeticException JavaDoc ignore) {
143         }//catch
144
return result;
145     }//devide
146

147     
148     /**
149      * Returns the value of this as a long
150      *
151      * @return the value of this as a long
152      */

153     public long getLong() {
154         return value;
155     }//getLong
156

157     
158     /**
159      * Returns the value of this as a double
160      *
161      * @return the value of this as a double
162      */

163     public double getDouble() {
164         return value;
165     }//getDouble
166

167
168     /**
169      * Returns the value of this, wrapped in a Long
170      *
171      * @return the value of this, wrapped in a Long
172      */

173     public Object JavaDoc getObject() {
174         return new Long JavaDoc(value);
175     }//getObject
176

177
178     /**
179      * Determines if this is equal to another object.
180      *
181      * @param obj the object to compare. An instance of MantaNumber
182      * @return MantaBoolean.TRUE if this = obj, otherwise MantaBoolean.FALSE
183      */

184     public MantaBoolean equal(final MantaObject obj) {
185         MantaBoolean result = null;
186         
187         if (obj instanceof MantaLong) {
188             long rightHand = ((MantaNumber) obj).getLong();
189             if (value == rightHand) {
190                 result = MantaBoolean.TRUE;
191             }//if
192
else {
193                 result = MantaBoolean.FALSE;
194             }//else
195
}//if
196
else if (obj instanceof MantaDouble) {
197             result = promote().equal(obj);
198         }//else if
199
return result;
200     }//equal
201

202
203     /**
204      * Determines if this is less than another object.
205      *
206      * @param obj the object to compare. An instance of MantaNumber
207      * @return MantaBoolean.TRUE if this &lt; obj, otherwise MantaBoolean.FALSE
208      */

209     public MantaBoolean less(final MantaObject obj) {
210         MantaBoolean result = null;
211         
212         if (obj instanceof MantaLong) {
213             long rightHand = ((MantaNumber) obj).getLong();
214             if (value < rightHand) {
215                 result = MantaBoolean.TRUE;
216             }//if
217
else {
218                 result = MantaBoolean.FALSE;
219             }//else
220
}//if
221
else if (obj instanceof MantaDouble) {
222             result = promote().less(obj);
223         }//else if
224
return result;
225     }//less
226

227
228     /**
229      * Determines if this is greater than another object.
230      *
231      * @param obj the object to compare. An instance of MantaNumber
232      * @return MantaBoolean.TRUE if this &gt; obj, otherwise MantaBoolean.FALSE
233      */

234     public MantaBoolean greater(final MantaObject obj) {
235         MantaBoolean result = null;
236         if (obj instanceof MantaLong) {
237             long rightHand = ((MantaNumber) obj).getLong();
238             if (value > rightHand) {
239                 result = MantaBoolean.TRUE;
240             }//if
241
else {
242                 result = MantaBoolean.FALSE;
243             }//else
244
}//if
245
else if (obj instanceof MantaDouble) {
246             result = promote().greater(obj);
247         }//elseif
248
return result;
249     }//greater
250

251
252     /**
253      * Promotes this to a double
254      *
255      * @return the value of this as a double
256      */

257     private MantaDouble promote() {
258         return new MantaDouble(value);
259     }//promote
260

261 }//MantaLong
262
Popular Tags