001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.pobjects.basic;
018:
019: import junit.framework.Assert;
020:
021: import java.math.BigDecimal;
022: import java.math.BigInteger;
023: import java.io.Serializable;
024:
025: /**
026: * This class contains the primitive type that Speedo must support:
027: * boolean
028: * byte
029: * short
030: * int
031: * long
032: * float
033: * double
034: * char
035: * Boolean
036: * Byte
037: * Short
038: * Integer
039: * Long
040: * Float
041: * Double
042: * Character
043: * String
044: * BigDecimal
045: * BigInteger
046: *
047: * @author S.Chassande-Barrioz
048: */
049: public class BasicType implements Serializable {
050:
051: private boolean boolean_field;
052: private byte byte_field;
053: private short short_field;
054: private int int_field;
055: private long long_field;
056: private float float_field;
057: private double double_field;
058: private char char_field;
059:
060: private Boolean oboolean_field;
061: private Byte obyte_field;
062: private Short oshort_field;
063: private Integer oint_field;
064: private Long olong_field;
065: private Float ofloat_field;
066: private Double odouble_field;
067: private Character ochar_field;
068:
069: private char[] chararray_field;
070: private byte[] bytearray_field;
071: private double[] doubleArray_field;
072: private String string_field;
073: private BigDecimal bigdecimal_field;
074: private BigInteger biginteger_field;
075:
076: public void assign(long longval) {
077: this .boolean_field = (longval % 2) == 1;
078: this .oboolean_field = (boolean_field ? new Boolean(
079: boolean_field) : null);
080:
081: this .byte_field = (byte) longval;
082: this .obyte_field = (boolean_field ? new Byte(byte_field) : null);
083:
084: this .char_field = (char) longval;
085: this .ochar_field = (boolean_field ? new Character(char_field)
086: : null);
087:
088: this .short_field = (short) longval;
089: this .oshort_field = (boolean_field ? new Short(short_field)
090: : null);
091:
092: this .int_field = (int) longval;
093: this .oint_field = (boolean_field ? new Integer(int_field)
094: : null);
095:
096: this .long_field = longval;
097: this .olong_field = (boolean_field ? new Long(long_field) : null);
098:
099: this .float_field = longval;
100: this .ofloat_field = (boolean_field ? new Float(float_field)
101: : null);
102:
103: this .double_field = longval;
104: this .odouble_field = (boolean_field ? new Double(double_field)
105: : null);
106:
107: this .chararray_field = (boolean_field ? new char[] { char_field }
108: : null);
109: this .bytearray_field = (boolean_field ? new byte[] { byte_field }
110: : null);
111: this .doubleArray_field = (boolean_field ? new double[] { double_field }
112: : null);
113: this .string_field = (boolean_field ? "str" + longval : null);
114: biginteger_field = (boolean_field ? new BigInteger("" + longval)
115: : null);
116: bigdecimal_field = (boolean_field ? new BigDecimal(
117: biginteger_field) : null);
118: }
119:
120: public void check(long longval) {
121: boolean isnull = (longval % 2) != 1;
122: Assert.assertEquals("bad boolean_field value", boolean_field,
123: (longval % 2) == 1);
124: Assert.assertEquals("bad boolean_field value", byte_field,
125: (byte) longval);
126: Assert.assertEquals("bad boolean_field value", char_field,
127: (char) longval);
128: Assert.assertEquals("bad boolean_field value", short_field,
129: (short) longval);
130: Assert.assertEquals("bad boolean_field value", int_field,
131: (int) longval);
132: Assert.assertEquals("bad boolean_field value", long_field,
133: longval);
134: if (isnull) {
135: Assert
136: .assertNull("oboolean_field not null",
137: oboolean_field);
138: Assert.assertNull("obyte_field not null", obyte_field);
139: Assert.assertNull("ochar_field not null", ochar_field);
140: Assert.assertNull("oshort_field not null", oshort_field);
141: Assert.assertNull("oint_field not null", oint_field);
142: Assert.assertNull("olong_field not null", olong_field);
143: Assert.assertNull("ofloat_field not null", ofloat_field);
144: Assert.assertNull("odouble_field not null", odouble_field);
145: Assert.assertNull("chararray_field not null",
146: chararray_field);
147: Assert.assertNull("bytearray_field not null",
148: bytearray_field);
149: Assert.assertNull("doublearray_field not null",
150: doubleArray_field);
151: Assert.assertNull("string_field not null", string_field);
152: Assert.assertNull("biginteger_field not null",
153: biginteger_field);
154: Assert.assertNull("bigdecimal_field not null",
155: bigdecimal_field);
156: } else {
157: Assert.assertNotNull("oboolean_field null", oboolean_field);
158: Assert.assertNotNull("obyte_field null", obyte_field);
159: Assert.assertNotNull("ochar_field null", ochar_field);
160: Assert.assertNotNull("oshort_field null", oshort_field);
161: Assert.assertNotNull("oint_field null", oint_field);
162: Assert.assertNotNull("olong_field null", olong_field);
163: Assert.assertNotNull("ofloat_field null", ofloat_field);
164: Assert.assertNotNull("odouble_field null", odouble_field);
165: Assert.assertNotNull("chararray_field null",
166: chararray_field);
167: Assert.assertNotNull("bytearray_field null",
168: bytearray_field);
169: Assert.assertNotNull("doubleArray_field null",
170: doubleArray_field);
171: Assert.assertNotNull("string_field null", string_field);
172: Assert.assertNotNull("biginteger_field null",
173: biginteger_field);
174: Assert.assertNotNull("bigdecimal_field null",
175: bigdecimal_field);
176:
177: Assert.assertEquals("oboolean_field bad value",
178: boolean_field, oboolean_field.booleanValue());
179: Assert.assertEquals("obyte_field bad value", byte_field,
180: obyte_field.byteValue());
181: Assert.assertEquals("ochar_field bad value", char_field,
182: ochar_field.charValue());
183: Assert.assertEquals("oshort_field bad value", short_field,
184: oshort_field.shortValue());
185: Assert.assertEquals("oint_field bad value", int_field,
186: oint_field.intValue());
187: Assert.assertEquals("olong_field bad value", long_field,
188: olong_field.longValue());
189: Assert.assertEquals("chararray_field bad value", 1,
190: chararray_field.length);
191: Assert.assertEquals("chararray_field bad value",
192: char_field, chararray_field[0]);
193: Assert.assertEquals("bytearray_field bad value", 1,
194: bytearray_field.length);
195: Assert.assertEquals("bytearray_field bad value",
196: byte_field, bytearray_field[0]);
197: Assert.assertEquals("doubleArray_field bad value", 1,
198: doubleArray_field.length);
199: Assert.assertEquals("string_field bad value", "str"
200: + longval, string_field);
201: Assert.assertEquals("biginteger_field bad value",
202: new BigInteger("" + longval), biginteger_field);
203: BigDecimal expected = new BigDecimal(biginteger_field);
204: BigDecimal found = bigdecimal_field;
205: Assert.assertTrue("bigdecimal_field bad value, expected "
206: + expected + ", found: " + found, expected
207: .compareTo(found) == 0);
208: }
209: }
210:
211: public boolean retrieve_boolean_field() {
212: return boolean_field;
213: }
214:
215: public void assign_boolean_field(boolean boolean_field) {
216: this .boolean_field = boolean_field;
217: }
218:
219: public byte retrieve_byte_field() {
220: return byte_field;
221: }
222:
223: public void assign_byte_field(byte byte_field) {
224: this .byte_field = byte_field;
225: }
226:
227: public short retrieve_short_field() {
228: return short_field;
229: }
230:
231: public void assign_short_field(short short_field) {
232: this .short_field = short_field;
233: }
234:
235: public int retrieve_int_field() {
236: return int_field;
237: }
238:
239: public void assign_int_field(int int_field) {
240: this .int_field = int_field;
241: }
242:
243: public long retrieve_long_field() {
244: return long_field;
245: }
246:
247: public void assign_long_field(long long_field) {
248: this .long_field = long_field;
249: }
250:
251: public float retrieve_float_field() {
252: return float_field;
253: }
254:
255: public void assign_float_field(float float_field) {
256: this .float_field = float_field;
257: }
258:
259: public double retrieve_double_field() {
260: return double_field;
261: }
262:
263: public void assign_double_field(double double_field) {
264: this .double_field = double_field;
265: }
266:
267: public char retrieve_char_field() {
268: return char_field;
269: }
270:
271: public void assign_char_field(char char_field) {
272: this .char_field = char_field;
273: }
274:
275: public Boolean retrieve_oboolean_field() {
276: return oboolean_field;
277: }
278:
279: public void assign_oboolean_field(Boolean oboolean_field) {
280: this .oboolean_field = oboolean_field;
281: }
282:
283: public Byte retrieve_obyte_field() {
284: return obyte_field;
285: }
286:
287: public void assign_obyte_field(Byte obyte_field) {
288: this .obyte_field = obyte_field;
289: }
290:
291: public Short retrieve_oshort_field() {
292: return oshort_field;
293: }
294:
295: public void assign_oshort_field(Short oshort_field) {
296: this .oshort_field = oshort_field;
297: }
298:
299: public Integer retrieve_oint_field() {
300: return oint_field;
301: }
302:
303: public void assign_oint_field(Integer oint_field) {
304: this .oint_field = oint_field;
305: }
306:
307: public Long retrieve_olong_field() {
308: return olong_field;
309: }
310:
311: public void assign_olong_field(Long olong_field) {
312: this .olong_field = olong_field;
313: }
314:
315: public Float retrieve_Float_field() {
316: return ofloat_field;
317: }
318:
319: public void assign_Float_field(Float Float_field) {
320: this .ofloat_field = Float_field;
321: }
322:
323: public Double retrieve_Double_field() {
324: return odouble_field;
325: }
326:
327: public void assign_Double_field(Double Double_field) {
328: this .odouble_field = Double_field;
329: }
330:
331: public Character retrieve_ochar_field() {
332: return ochar_field;
333: }
334:
335: public void assign_ochar_field(Character ochar_field) {
336: this .ochar_field = ochar_field;
337: }
338:
339: public String retrieve_string_field() {
340: return string_field;
341: }
342:
343: public void assign_string_field(String string_field) {
344: this .string_field = string_field;
345: }
346:
347: public BigDecimal retrieve_bigdecimal_field() {
348: return bigdecimal_field;
349: }
350:
351: public void assign_bigdecimal_field(BigDecimal bigdecimal_field) {
352: this .bigdecimal_field = bigdecimal_field;
353: }
354:
355: public BigInteger retrieve_biginteger_field() {
356: return biginteger_field;
357: }
358:
359: public void assign_biginteger_field(BigInteger biginteger_field) {
360: this .biginteger_field = biginteger_field;
361: }
362:
363: public char[] retrieve_chararray_field() {
364: return chararray_field;
365: }
366:
367: public void assign_chararray_field(char[] chararray_field) {
368: this .chararray_field = chararray_field;
369: }
370:
371: public byte[] retrieve_bytearray_field() {
372: return bytearray_field;
373: }
374:
375: public void assign_bytearray_field(byte[] bytearray_field) {
376: this .bytearray_field = bytearray_field;
377: }
378:
379: public double[] retrieve_doublearray_field() {
380: return doubleArray_field;
381: }
382:
383: public void assign_doublearray_field(double[] doubleArray_field) {
384: this.doubleArray_field = doubleArray_field;
385: }
386:
387: }
|