KickJava   Java API By Example, From Geeks To Geeks.

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


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 UShortValue implements Value
18 {
19   private Integer JavaDoc m_value;
20
21
22   public UShortValue()
23   {
24     this(0);
25   }
26
27
28   public UShortValue(int value)
29   {
30     m_value = new Integer JavaDoc(value);
31   }
32
33
34   public UShortValue(Object JavaDoc value)
35   {
36     m_value = (Integer JavaDoc)value;
37   }
38
39
40   public void setValue(Object JavaDoc value)
41   {
42     m_value = (Integer JavaDoc)value;
43   }
44
45
46   public int getTypeId()
47   {
48     return ValueType.USHORT;
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.USHORT)
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.USHORT) {
76       Integer JavaDoc i = (Integer JavaDoc)nv.getValue();
77       result = (m_value.intValue() < i.intValue());
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.USHORT) {
109       Integer JavaDoc i = (Integer JavaDoc)nv.getValue();
110       result = new UShortValue(m_value.intValue() + i.intValue());
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.USHORT) {
124       Integer JavaDoc i = (Integer JavaDoc)nv.getValue();
125       int val = m_value.intValue() - i.intValue();
126       if (val < 0)
127         result = ValueFactory.createLong(val);
128       else
129         result = new UShortValue(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.USHORT) {
143       Integer JavaDoc i = (Integer JavaDoc)nv.getValue();
144       result = ValueFactory.createULong(m_value.intValue() * i.intValue());
145     }
146     else
147       throw new IllegalArgumentException JavaDoc();
148
149     return result;
150   }
151
152
153   public Value divide(Value nv)
154   {
155     Value result = null;
156
157     if (nv.getTypeId() == ValueType.USHORT) {
158       Integer JavaDoc i = (Integer JavaDoc)nv.getValue();
159       result = new UShortValue(m_value.intValue() / i.intValue());
160     }
161     else
162       throw new IllegalArgumentException JavaDoc();
163
164     return result;
165   }
166
167
168   public Value negate()
169   {
170     return ValueFactory.createLong(-1 * m_value.intValue());
171   }
172
173
174   public Value convert(int typeId)
175   {
176     Value result = null;
177
178     switch (typeId) {
179       case ValueType.USHORT:
180         result = new UShortValue(m_value);
181         break;
182
183       case ValueType.LONG:
184         result = ValueFactory.createLong(m_value.intValue());
185         break;
186
187       case ValueType.ULONG:
188         result = ValueFactory.createULong(m_value.longValue());
189         break;
190
191       case ValueType.FLOAT:
192         result = ValueFactory.createFloat(m_value.floatValue());
193         break;
194
195       case ValueType.DOUBLE:
196         result = ValueFactory.createDouble(m_value.doubleValue());
197         break;
198
199       default:
200         throw new IllegalArgumentException JavaDoc();
201     }
202
203     return result;
204   }
205
206
207   public String JavaDoc toString()
208   {
209     return m_value.toString();
210   }
211 }
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Popular Tags