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
;
28 public class RInteger
extends ARObject
{
31 static RInteger mone
= new RInteger(-1);
32 static RInteger zero
= new RInteger( 0);
33 static RInteger one
= new RInteger( 1);
35 private RInteger(long i
){
40 * Parses the given string, and returns an RInteger Object
41 * @param s String to parse
42 * @return RInteger value for the given string
43 * @throws RulesException
45 static public long getIntegerValue(String s
) throws RulesException
{
46 if(s
==null || (s
= s
.trim()).length()==0 || s
.equalsIgnoreCase("null")){
50 long v
= Long
.parseLong(s
);
52 } catch (NumberFormatException e
) {
53 throw new RulesException("Conversion Error","RInteger.getIntegerValue()","Could not covert the string '"+s
+"' to an integer: "+e
.getMessage());
57 static public RInteger
getRIntegerValue(String s
) throws RulesException
{
58 return getRIntegerValue(getIntegerValue(s
));
61 static public RInteger
getRIntegerValue(long i
){
63 if(i
== -1) return mone
;
64 if(i
== 0) return zero
;
65 if(i
== 1) return one
;
66 return new RInteger(i
);
69 static public RInteger
getRIntegerValue(double i
){
70 return getRIntegerValue((long) i
);
73 static public RInteger
getRIntegerValue(int i
){
74 return getRIntegerValue((long) i
);
81 public double doubleValue() {
85 public int intValue() {
89 public long longValue() throws RulesException
{
93 public boolean equals(IRObject o
) throws RulesException
{
94 return value
== o
.intValue();
97 public String
postFix() {
101 public RInteger
rIntegerValue() throws RulesException
{
105 public String
stringValue() {
106 String str
= Long
.toString(value
);
110 public String
toString(){
111 return stringValue();
115 * returns 0 if both are equal. -1 if this object is less than the argument.
116 * 1 if this object is greater than the argument
118 public int compare(IRObject irObject
) throws RulesException
{
119 return (this.value
==irObject
.intValue())?
0:((this.value
<irObject
.intValue())?
-1:0);