KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > pobjects > basic > BasicType


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.pobjects.basic;
19
20 import junit.framework.Assert;
21
22 import java.math.BigDecimal JavaDoc;
23 import java.math.BigInteger JavaDoc;
24 import java.io.Serializable JavaDoc;
25
26 /**
27  * This class contains the primitive type that Speedo must support:
28  * boolean
29  * byte
30  * short
31  * int
32  * long
33  * float
34  * double
35  * char
36  * Boolean
37  * Byte
38  * Short
39  * Integer
40  * Long
41  * Float
42  * Double
43  * Character
44  * String
45  * BigDecimal
46  * BigInteger
47  *
48  * @author S.Chassande-Barrioz
49  */

50 public class BasicType implements Serializable JavaDoc {
51
52     private boolean boolean_field;
53     private byte byte_field;
54     private short short_field;
55     private int int_field;
56     private long long_field;
57     private float float_field;
58     private double double_field;
59     private char char_field;
60
61     private Boolean JavaDoc oboolean_field;
62     private Byte JavaDoc obyte_field;
63     private Short JavaDoc oshort_field;
64     private Integer JavaDoc oint_field;
65     private Long JavaDoc olong_field;
66     private Float JavaDoc ofloat_field;
67     private Double JavaDoc odouble_field;
68     private Character JavaDoc ochar_field;
69
70     private char[] chararray_field;
71     private byte[] bytearray_field;
72     private double[] doubleArray_field;
73     private String JavaDoc string_field;
74     private BigDecimal JavaDoc bigdecimal_field;
75     private BigInteger JavaDoc biginteger_field;
76     
77
78     public void assign(long longval) {
79         this.boolean_field = (longval % 2) == 1;
80         this.oboolean_field = (boolean_field ? new Boolean JavaDoc(boolean_field) : null);
81
82         this.byte_field = (byte) longval;
83         this.obyte_field = (boolean_field ? new Byte JavaDoc(byte_field) : null);
84
85         this.char_field = (char) longval;
86         this.ochar_field = (boolean_field ? new Character JavaDoc(char_field) : null);
87
88         this.short_field = (short) longval;
89         this.oshort_field = (boolean_field ? new Short JavaDoc(short_field) : null);
90
91         this.int_field = (int) longval;
92         this.oint_field = (boolean_field ? new Integer JavaDoc(int_field) : null);
93
94         this.long_field = longval;
95         this.olong_field = (boolean_field ? new Long JavaDoc(long_field) : null);
96
97         this.float_field = longval;
98         this.ofloat_field = (boolean_field ? new Float JavaDoc(float_field) : null);
99
100         this.double_field = longval;
101         this.odouble_field = (boolean_field ? new Double JavaDoc(double_field) : null);
102
103         this.chararray_field = (boolean_field ? new char[] {char_field} : null);
104         this.bytearray_field = (boolean_field ? new byte[] {byte_field} : null);
105         this.doubleArray_field = (boolean_field ? new double[] {double_field} : null);
106         this.string_field = (boolean_field ? "str" + longval : null);
107         biginteger_field = (boolean_field ? new BigInteger JavaDoc("" + longval) : null);
108         bigdecimal_field = (boolean_field ? new BigDecimal JavaDoc(biginteger_field) : null);
109     }
110
111     public void check(long longval) {
112         boolean isnull = (longval % 2) != 1;
113         Assert.assertEquals("bad boolean_field value", boolean_field, (longval % 2) == 1);
114         Assert.assertEquals("bad boolean_field value", byte_field, (byte) longval);
115         Assert.assertEquals("bad boolean_field value", char_field, (char) longval);
116         Assert.assertEquals("bad boolean_field value", short_field, (short) longval);
117         Assert.assertEquals("bad boolean_field value", int_field, (int) longval);
118         Assert.assertEquals("bad boolean_field value", long_field, longval);
119         if (isnull) {
120             Assert.assertNull("oboolean_field not null", oboolean_field);
121             Assert.assertNull("obyte_field not null", obyte_field);
122             Assert.assertNull("ochar_field not null", ochar_field);
123             Assert.assertNull("oshort_field not null", oshort_field);
124             Assert.assertNull("oint_field not null", oint_field);
125             Assert.assertNull("olong_field not null", olong_field);
126             Assert.assertNull("ofloat_field not null", ofloat_field);
127             Assert.assertNull("odouble_field not null", odouble_field);
128             Assert.assertNull("chararray_field not null", chararray_field);
129             Assert.assertNull("bytearray_field not null", bytearray_field);
130             Assert.assertNull("doublearray_field not null", doubleArray_field);
131             Assert.assertNull("string_field not null", string_field);
132             Assert.assertNull("biginteger_field not null", biginteger_field);
133             Assert.assertNull("bigdecimal_field not null", bigdecimal_field);
134         } else {
135             Assert.assertNotNull("oboolean_field null", oboolean_field);
136             Assert.assertNotNull("obyte_field null", obyte_field);
137             Assert.assertNotNull("ochar_field null", ochar_field);
138             Assert.assertNotNull("oshort_field null", oshort_field);
139             Assert.assertNotNull("oint_field null", oint_field);
140             Assert.assertNotNull("olong_field null", olong_field);
141             Assert.assertNotNull("ofloat_field null", ofloat_field);
142             Assert.assertNotNull("odouble_field null", odouble_field);
143             Assert.assertNotNull("chararray_field null", chararray_field);
144             Assert.assertNotNull("bytearray_field null", bytearray_field);
145             Assert.assertNotNull("doubleArray_field null", doubleArray_field);
146             Assert.assertNotNull("string_field null", string_field);
147             Assert.assertNotNull("biginteger_field null", biginteger_field);
148             Assert.assertNotNull("bigdecimal_field null", bigdecimal_field);
149
150             Assert.assertEquals("oboolean_field bad value", boolean_field, oboolean_field.booleanValue());
151             Assert.assertEquals("obyte_field bad value", byte_field, obyte_field.byteValue());
152             Assert.assertEquals("ochar_field bad value", char_field, ochar_field.charValue());
153             Assert.assertEquals("oshort_field bad value", short_field, oshort_field.shortValue());
154             Assert.assertEquals("oint_field bad value", int_field, oint_field.intValue());
155             Assert.assertEquals("olong_field bad value", long_field, olong_field.longValue());
156             Assert.assertEquals("chararray_field bad value", 1, chararray_field.length);
157             Assert.assertEquals("chararray_field bad value", char_field, chararray_field[0]);
158             Assert.assertEquals("bytearray_field bad value", 1, bytearray_field.length);
159             Assert.assertEquals("bytearray_field bad value", byte_field, bytearray_field[0]);
160             Assert.assertEquals("doubleArray_field bad value", 1, doubleArray_field.length);
161             Assert.assertEquals("string_field bad value", "str" + longval, string_field);
162             Assert.assertEquals("biginteger_field bad value", new BigInteger JavaDoc("" + longval), biginteger_field);
163             BigDecimal JavaDoc expected = new BigDecimal JavaDoc(biginteger_field);
164             BigDecimal JavaDoc found = bigdecimal_field;
165             Assert.assertTrue("bigdecimal_field bad value, expected " + expected
166                 + ", found: " + found,
167                 expected.compareTo(found)==0);
168         }
169     }
170
171     public boolean retrieve_boolean_field() {
172         return boolean_field;
173     }
174
175     public void assign_boolean_field(boolean boolean_field) {
176         this.boolean_field = boolean_field;
177     }
178
179     public byte retrieve_byte_field() {
180         return byte_field;
181     }
182
183     public void assign_byte_field(byte byte_field) {
184         this.byte_field = byte_field;
185     }
186
187     public short retrieve_short_field() {
188         return short_field;
189     }
190
191     public void assign_short_field(short short_field) {
192         this.short_field = short_field;
193     }
194
195     public int retrieve_int_field() {
196         return int_field;
197     }
198
199     public void assign_int_field(int int_field) {
200         this.int_field = int_field;
201     }
202
203     public long retrieve_long_field() {
204         return long_field;
205     }
206
207     public void assign_long_field(long long_field) {
208         this.long_field = long_field;
209     }
210
211     public float retrieve_float_field() {
212         return float_field;
213     }
214
215     public void assign_float_field(float float_field) {
216         this.float_field = float_field;
217     }
218
219     public double retrieve_double_field() {
220         return double_field;
221     }
222
223     public void assign_double_field(double double_field) {
224         this.double_field = double_field;
225     }
226
227     public char retrieve_char_field() {
228         return char_field;
229     }
230
231     public void assign_char_field(char char_field) {
232         this.char_field = char_field;
233     }
234
235     public Boolean JavaDoc retrieve_oboolean_field() {
236         return oboolean_field;
237     }
238
239     public void assign_oboolean_field(Boolean JavaDoc oboolean_field) {
240         this.oboolean_field = oboolean_field;
241     }
242
243     public Byte JavaDoc retrieve_obyte_field() {
244         return obyte_field;
245     }
246
247     public void assign_obyte_field(Byte JavaDoc obyte_field) {
248         this.obyte_field = obyte_field;
249     }
250
251     public Short JavaDoc retrieve_oshort_field() {
252         return oshort_field;
253     }
254
255     public void assign_oshort_field(Short JavaDoc oshort_field) {
256         this.oshort_field = oshort_field;
257     }
258
259     public Integer JavaDoc retrieve_oint_field() {
260         return oint_field;
261     }
262
263     public void assign_oint_field(Integer JavaDoc oint_field) {
264         this.oint_field = oint_field;
265     }
266
267     public Long JavaDoc retrieve_olong_field() {
268         return olong_field;
269     }
270
271     public void assign_olong_field(Long JavaDoc olong_field) {
272         this.olong_field = olong_field;
273     }
274
275     public Float JavaDoc retrieve_Float_field() {
276         return ofloat_field;
277     }
278
279     public void assign_Float_field(Float JavaDoc Float_field) {
280         this.ofloat_field = Float_field;
281     }
282
283     public Double JavaDoc retrieve_Double_field() {
284         return odouble_field;
285     }
286
287     public void assign_Double_field(Double JavaDoc Double_field) {
288         this.odouble_field = Double_field;
289     }
290
291     public Character JavaDoc retrieve_ochar_field() {
292         return ochar_field;
293     }
294
295     public void assign_ochar_field(Character JavaDoc ochar_field) {
296         this.ochar_field = ochar_field;
297     }
298
299     public String JavaDoc retrieve_string_field() {
300         return string_field;
301     }
302
303     public void assign_string_field(String JavaDoc string_field) {
304         this.string_field = string_field;
305     }
306
307     public BigDecimal JavaDoc retrieve_bigdecimal_field() {
308         return bigdecimal_field;
309     }
310
311     public void assign_bigdecimal_field(BigDecimal JavaDoc bigdecimal_field) {
312         this.bigdecimal_field = bigdecimal_field;
313     }
314
315     public BigInteger JavaDoc retrieve_biginteger_field() {
316         return biginteger_field;
317     }
318
319     public void assign_biginteger_field(BigInteger JavaDoc biginteger_field) {
320         this.biginteger_field = biginteger_field;
321     }
322
323     public char[] retrieve_chararray_field() {
324         return chararray_field;
325     }
326
327     public void assign_chararray_field(char[] chararray_field) {
328         this.chararray_field = chararray_field;
329     }
330
331     public byte[] retrieve_bytearray_field() {
332         return bytearray_field;
333     }
334
335     public void assign_bytearray_field(byte[] bytearray_field) {
336         this.bytearray_field = bytearray_field;
337     }
338
339     public double[] retrieve_doublearray_field() {
340         return doubleArray_field;
341     }
342
343     public void assign_doublearray_field(double[] doubleArray_field) {
344         this.doubleArray_field = doubleArray_field;
345     }
346
347
348 }
349
Popular Tags