001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test.java;
022:
023: import java.lang.reflect.*;
024:
025: import com.db4o.test.*;
026:
027: public class PrimitiveWrappers {
028:
029: public Boolean boolNull;
030: public Boolean boolMin;
031: public Boolean boolMax;
032:
033: public Byte bNull;
034: public Byte bMin;
035: public Byte bMax;
036:
037: public Character cNull;
038: public Character cMin;
039: public Character cMax;
040:
041: public Double dNull;
042: public Double dMin;
043: public Double dMax;
044:
045: public Float fNull;
046: public Float fMin;
047: public Float fMax;
048:
049: public Integer iNull;
050: public Integer iMin;
051: public Integer iMax;
052:
053: public Long lNull;
054: public Long lMin;
055: public Long lMax;
056:
057: public Short sNull;
058: public Short sMin;
059: public Short sMax;
060:
061: public void storeOne() {
062:
063: boolMin = new Boolean(false);
064: boolMax = new Boolean(true);
065:
066: bMin = new Byte(Byte.MAX_VALUE);
067: bMax = new Byte(Byte.MAX_VALUE);
068:
069: cMin = new Character(Character.MIN_VALUE);
070: cMax = new Character(Character.MAX_VALUE);
071:
072: dMin = new Double(Double.MIN_VALUE);
073: dMax = new Double(Double.MAX_VALUE);
074:
075: fMin = new Float(Float.MIN_VALUE);
076: fMax = new Float(Float.MAX_VALUE);
077:
078: iMin = new Integer(Integer.MIN_VALUE);
079: iMax = new Integer(Integer.MAX_VALUE);
080:
081: lMin = new Long(Long.MIN_VALUE);
082: lMax = new Long(Long.MAX_VALUE);
083:
084: sMin = new Short(Short.MIN_VALUE);
085: sMax = new Short(Short.MAX_VALUE);
086:
087: }
088:
089: public void testOne() {
090: PrimitiveWrappers original = new PrimitiveWrappers();
091: original.storeOne();
092: Test.ensure(this .equals(original));
093: }
094:
095: public boolean equals(Object obj) {
096: if (!(obj instanceof PrimitiveWrappers)) {
097: return false;
098: }
099: try {
100: Class clazz = getClass();
101: Field[] fields = clazz.getDeclaredFields();
102: for (int i = 0; i < fields.length; i++) {
103: Field field = fields[i];
104: Object myMember = field.get(this );
105: Object otherMember = field.get(obj);
106: if (myMember == null) {
107: if (otherMember != null) {
108: return false;
109: }
110: } else {
111: if (!myMember.equals(otherMember)) {
112: return false;
113: }
114: }
115: }
116: } catch (Exception e) {
117: e.printStackTrace();
118: }
119: return true;
120: }
121:
122: }
|