KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > selector > SDouble


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2000,2001 (C) Exoffice Technologies Inc. All Rights Reserved.
42  */

43
44 package org.exolab.jms.selector;
45
46
47 /**
48  * This class is an adapter for the Double type.
49  *
50  * @version $Revision: 1.1 $ $Date: 2004/11/26 01:50:44 $
51  * @author <a HREF="mailto:tima@intalio.com">Tim Anderson</a>
52  * @see SNumber
53  */

54 final class SDouble extends SNumber {
55
56     /**
57      * The wrapped value
58      */

59     private final double _value;
60
61     /**
62      * Construct a new <code>SDouble</code>, initialised to <code>0</code>
63      */

64     public SDouble() {
65         _value = 0;
66     }
67
68     /**
69      * Construct a new <code>SDouble</code>
70      *
71      * @param value the underlying value
72      */

73     public SDouble(final double value) {
74         _value = value;
75     }
76
77     /**
78      * Returns the addition of a number to this
79      *
80      * @param number the number to add
81      * @return the value of <code>this + number<code>
82      */

83     public SNumber add(final SNumber number) {
84         return new SDouble(_value + number.getDouble());
85     }
86
87     /**
88      * Returns the value of the substraction of a number from this
89      *
90      * @param number the number to subtract
91      * @return the value of <code>this - number<code>
92      */

93     public SNumber subtract(final SNumber number) {
94         return new SDouble(_value - number.getDouble());
95     }
96
97     /**
98      * Returns the multiplication of a number to this
99      *
100      * @param number the number to multiply
101      * @return the value of <code>this * number<code>
102      */

103     public SNumber multiply(final SNumber number) {
104         return new SDouble(_value * number.getDouble());
105     }
106
107     /**
108      * Returns the division of a number from this
109      *
110      * @param number the number to divide
111      * @return the value of <code>this / number<code>
112      */

113     public SNumber divide(final SNumber number) {
114         SNumber result = null;
115         try {
116             result = new SDouble(_value / number.getDouble());
117         } catch (ArithmeticException JavaDoc ignore) {
118         }
119         return result;
120     }
121
122     /**
123      * Returns the value of this as a <code>long</code>
124      *
125      * @return the value of this as a <code>long</code>
126      */

127     public long getLong() {
128         return (long) _value;
129     }
130
131     /**
132      * Returns the value of this as a <code>double</code>
133      *
134      * @return the value of this as a <code>double</code>
135      */

136     public double getDouble() {
137         return _value;
138     }
139
140     /**
141      * Returns the value of this, wrapped in a <code>Double</code>
142      *
143      * @return the value of this, wrapped in a <code>Double</code>
144      */

145     public Object JavaDoc getObject() {
146         return new Double JavaDoc(_value);
147     }
148
149     /**
150      * Determines if this is equal to another object.
151      *
152      * @param obj the object to compare. An instance of <code>SNumber</code>
153      * @return <code>SBool.TRUE</code> if <code>this = obj</code>, otherwise
154      * <code>SBool.FALSE</code>
155      */

156     public SBool equal(final SObject obj) {
157         SBool result = SBool.FALSE;
158         double rhs = ((SNumber) obj).getDouble();
159         if (_value == rhs) {
160             result = SBool.TRUE;
161         }
162         return result;
163     }
164
165     /**
166      * Determines if this is less than another object.
167      *
168      * @param obj the object to compare. An instance of <code>SNumber</code>
169      * @return <code>SBool.TRUE</code> if <code>this &lt; obj</code>, otherwise
170      * <code>SBool.FALSE</code>
171      */

172     public SBool less(final SObject obj) {
173         SBool result = SBool.FALSE;
174         double rhs = ((SNumber) obj).getDouble();
175         if (_value < rhs) {
176             result = SBool.TRUE;
177         }
178         return result;
179     }
180
181     /**
182      * Determines if this is greater than another object.
183      *
184      * @param obj the object to compare. An instance of <code>SNumber</code>
185      * @return <code>SBool.TRUE</code> if <code>this &gt; obj</code>, otherwise
186      * <code>SBool.FALSE</code>
187      */

188     public SBool greater(final SObject obj) {
189         SBool result = SBool.FALSE;
190         double rhs = ((SNumber) obj).getDouble();
191         if (_value > rhs) {
192             result = SBool.TRUE;
193         }
194         return result;
195     }
196
197 } //-- SDouble
198
Popular Tags