KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > java > PrimitiveWrappers


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test.java;
22
23 import java.lang.reflect.*;
24
25 import com.db4o.inside.marshall.*;
26 import com.db4o.test.*;
27
28
29 public class PrimitiveWrappers {
30     
31     public Boolean JavaDoc boolNull;
32     public Boolean JavaDoc boolMin;
33     public Boolean JavaDoc boolMax;
34     
35     public Byte JavaDoc bNull;
36     public Byte JavaDoc bMin;
37     public Byte JavaDoc bMax;
38     
39     public Character JavaDoc cNull;
40     public Character JavaDoc cMin;
41     public Character JavaDoc cMax;
42     
43     public Double JavaDoc dNull;
44     public Double JavaDoc dMin;
45     public Double JavaDoc dMax;
46     
47     public Float JavaDoc fNull;
48     public Float JavaDoc fMin;
49     public Float JavaDoc fMax;
50     
51     public Integer JavaDoc iNull;
52     public Integer JavaDoc iMin;
53     public Integer JavaDoc iMax;
54     
55     public Long JavaDoc lNull;
56     public Long JavaDoc lMin;
57     public Long JavaDoc lMax;
58     
59     public Short JavaDoc sNull;
60     public Short JavaDoc sMin;
61     public Short JavaDoc sMax;
62     
63     
64     public void storeOne(){
65         
66         boolMin = new Boolean JavaDoc(false);
67         boolMax = new Boolean JavaDoc(true);
68         
69         bMin = new Byte JavaDoc(Byte.MAX_VALUE);
70         bMax = new Byte JavaDoc(Byte.MAX_VALUE);
71         
72         cMin = new Character JavaDoc(Character.MIN_VALUE);
73         cMax = new Character JavaDoc(Character.MAX_VALUE);
74         
75         dMin = new Double JavaDoc(Double.MIN_VALUE);
76         dMax = new Double JavaDoc(Double.MAX_VALUE);
77         
78         fMin = new Float JavaDoc(Float.MIN_VALUE);
79         fMax = new Float JavaDoc(Float.MAX_VALUE);
80         
81         iMin = new Integer JavaDoc(Integer.MIN_VALUE);
82         iMax = new Integer JavaDoc(Integer.MAX_VALUE);
83         
84         lMin = new Long JavaDoc(Long.MIN_VALUE);
85         lMax = new Long JavaDoc(Long.MAX_VALUE);
86         
87         sMin = new Short JavaDoc(Short.MIN_VALUE);
88         sMax = new Short JavaDoc(Short.MAX_VALUE);
89         
90     }
91     
92     public void testOne(){
93         PrimitiveWrappers original = new PrimitiveWrappers();
94         original.storeOne();
95         Test.ensure(this.equals(original));
96     }
97     
98     public boolean equals(Object JavaDoc obj) {
99         if(! (obj instanceof PrimitiveWrappers)){
100             return false;
101         }
102         try {
103             Class JavaDoc clazz = getClass();
104             Field[] fields = clazz.getDeclaredFields();
105             for (int i = 0; i < fields.length; i++) {
106                 Field field = fields[i];
107                 Object JavaDoc myMember = field.get(this);
108                 Object JavaDoc otherMember = field.get(obj);
109                 if(myMember == null){
110                     if(otherMember != null){
111                         return false;
112                     }
113                 }else{
114                     if(! myMember.equals(otherMember)){
115                         return false;
116                     }
117                 }
118             }
119         } catch (Exception JavaDoc e) {
120             e.printStackTrace();
121         }
122         return true;
123     }
124
125 }
126
Popular Tags