4 * Copyright 2004-2007 MTBJ, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package com
.dtrules
.interpreter
;
21 import com
.dtrules
.infrastructure
.RulesException
;
27 public class RDouble
extends ARObject
{
30 static RDouble mone
= new RDouble(-1.0);
31 static RDouble zero
= new RDouble(0.0);
32 static RDouble one
= new RDouble(1.0);
34 private RDouble(double v
){
38 static public double getDoubleValue(String s
) throws RulesException
{
39 if(s
==null || s
.trim().length()==0){
43 double v
= Double
.parseDouble(s
);
45 } catch (NumberFormatException e
) {
46 throw new RulesException("Conversion Error","RDouble.getDoubleValue()","Could not covert the string '"+s
+"' to a double: "+e
.getMessage());
50 * Parses the given string, and returns an RDouble Object
51 * @param s String to parse
52 * @return RDouble value for the given string
53 * @throws RulesException
55 static public RDouble
getRDoubleValue(String s
) throws RulesException
{
56 return getRDoubleValue(getDoubleValue(s
));
61 static public RDouble
getRDoubleValue(double v
){
62 if(v
== -1.0) return mone
;
63 if(v
== 0.0) return zero
;
64 if(v
== 1.0) return one
;
66 return new RDouble(v
);
69 static public RDouble
getRDoubleValue(int v
){
70 return getRDoubleValue((double) v
);
73 static public RDouble
getRDoubleValue(long v
){
74 return getRDoubleValue((double) v
);
77 public RDouble
rDoubleValue() {
81 public double doubleValue() {
85 public int intValue() {
90 public long longValue() {
94 public RInteger
rIntegerValue() {
95 return RInteger
.getRIntegerValue((long)value
);
99 * Returns the type for this object.
105 public String
stringValue() {
106 return Double
.toString(value
);
110 * returns 0 if both are equal. -1 if this object is less than the argument.
111 * 1 if this object is greater than the argument
113 public int compare(IRObject irObject
) throws RulesException
{
114 return (this.value
==irObject
.doubleValue())?
0:((this.value
<irObject
.doubleValue())?
-1:0);
118 public boolean equals(IRObject o
) throws RulesException
{
119 return value
== o
.doubleValue();
122 public String
toString() {
123 return Double
.toString(value
);