KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > constraint > ULongValue


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.constraint;
15
16
17 public class ULongValue implements Value
18 {
19   private Long JavaDoc m_value;
20
21
22   public ULongValue()
23   {
24     this(0);
25   }
26
27
28   public ULongValue(long value)
29   {
30     m_value = new Long JavaDoc(value);
31   }
32
33
34   public ULongValue(Object JavaDoc value)
35   {
36     m_value = (Long JavaDoc)value;
37   }
38
39
40   public void setValue(Object JavaDoc value)
41   {
42     m_value = (Long JavaDoc)value;
43   }
44
45
46   public int getTypeId()
47   {
48     return ValueType.ULONG;
49   }
50
51
52   public Object JavaDoc getValue()
53   {
54     return m_value;
55   }
56
57
58   public boolean equals(Value nv)
59   {
60     boolean result = false;
61
62     if (nv.getTypeId() == ValueType.ULONG)
63       result = m_value.equals(nv.getValue());
64     else
65       throw new IllegalArgumentException JavaDoc();
66
67     return result;
68   }
69
70
71   public boolean lessThan(Value nv)
72   {
73     boolean result = false;
74
75     if (nv.getTypeId() == ValueType.ULONG) {
76       Long JavaDoc l = (Long JavaDoc)nv.getValue();
77       result = (m_value.longValue() < l.longValue());
78     }
79     else
80       throw new IllegalArgumentException JavaDoc();
81
82     return result;
83   }
84
85
86   public boolean lessThanEqual(Value nv)
87   {
88     return (lessThan(nv) || equals(nv));
89   }
90
91
92   public boolean greaterThan(Value nv)
93   {
94     return (! lessThan(nv) && ! equals(nv));
95   }
96
97
98   public boolean greaterThanEqual(Value nv)
99   {
100     return (! lessThan(nv));
101   }
102
103
104   public Value plus(Value nv)
105   {
106     Value result = null;
107
108     if (nv.getTypeId() == ValueType.ULONG) {
109       Long JavaDoc l = (Long JavaDoc)nv.getValue();
110       result = new ULongValue(m_value.longValue() + l.longValue());
111     }
112     else
113       throw new IllegalArgumentException JavaDoc();
114
115     return result;
116   }
117
118
119   public Value minus(Value nv)
120   {
121     Value result = null;
122
123     if (nv.getTypeId() == ValueType.ULONG) {
124       Long JavaDoc l = (Long JavaDoc)nv.getValue();
125       long val = m_value.longValue() - l.longValue();
126       if (val < 0)
127         result = ValueFactory.createLong((int)val);
128       else
129         result = new ULongValue(val);
130     }
131     else
132       throw new IllegalArgumentException JavaDoc();
133
134     return result;
135   }
136
137
138   public Value multiply(Value nv)
139   {
140     Value result = null;
141
142     if (nv.getTypeId() == ValueType.ULONG) {
143       Long JavaDoc l = (Long JavaDoc)nv.getValue();
144       result =
145         ValueFactory.createULong(m_value.longValue() * l.longValue());
146     }
147     else
148       throw new IllegalArgumentException JavaDoc();
149
150     return result;
151   }
152
153
154   public Value divide(Value nv)
155   {
156     Value result = null;
157
158     if (nv.getTypeId() == ValueType.ULONG) {
159       Long JavaDoc l = (Long JavaDoc)nv.getValue();
160       result = new ULongValue(m_value.longValue() / l.longValue());
161     }
162     else
163       throw new IllegalArgumentException JavaDoc();
164
165     return result;
166   }
167
168
169   public Value negate()
170   {
171     return ValueFactory.createLong(-1 * m_value.intValue());
172   }
173
174
175   public Value convert(int typeId)
176   {
177     Value result = null;
178
179     switch (typeId) {
180       case ValueType.LONG:
181         result = ValueFactory.createLong(m_value.intValue());
182         break;
183
184       case ValueType.ULONG:
185         result = new ULongValue(m_value);
186         break;
187
188       case ValueType.FLOAT:
189         result = ValueFactory.createFloat(m_value.floatValue());
190         break;
191
192       case ValueType.DOUBLE:
193         result = ValueFactory.createDouble(m_value.doubleValue());
194         break;
195
196       default:
197         throw new IllegalArgumentException JavaDoc();
198     }
199
200     return result;
201   }
202
203
204   public String JavaDoc toString()
205   {
206     return m_value.toString();
207   }
208 }
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
Popular Tags