KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > jre11 > staging > PrimitiveWrapperArrayTestCase


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.db4ounit.jre11.staging;
22
23 import db4ounit.*;
24 import db4ounit.extensions.*;
25
26
27 public class PrimitiveWrapperArrayTestCase extends AbstractDb4oTestCase {
28
29     public static void main(String JavaDoc[] args) {
30         new PrimitiveWrapperArrayTestCase().runSolo();
31     }
32     
33     protected void store() throws Exception JavaDoc {
34         store(Item.testInstance());
35     }
36     
37     public void test(){
38         Item item = (Item) retrieveOnlyInstance(Item.class);
39         Assert.areEqual(Item.testInstance(), item);
40     }
41     
42     public static class Item{
43         
44         public Boolean JavaDoc[] _booleans;
45         
46         public Item(){
47             
48         }
49         
50         public Item(Boolean JavaDoc[] booleans){
51             _booleans = booleans;
52         }
53         
54         public static Item testInstance(){
55             Boolean JavaDoc[] booleans = new Boolean JavaDoc[]{new Boolean JavaDoc(true), new Boolean JavaDoc(false), null };
56             return new Item(booleans);
57         }
58         
59         public boolean equals(Object JavaDoc obj) {
60             if(! (obj instanceof Item)){
61                 return false;
62             }
63             Item other = (Item)obj;
64             return areEqual(_booleans, other._booleans);
65         }
66         
67         public static boolean areEqual(Boolean JavaDoc[] cmp, Boolean JavaDoc[] with){
68             if(cmp == null){
69                 return with == null;
70             }
71             if(with == null){
72                 return false;
73             }
74             if(cmp.length != with.length){
75                 return false;
76             }
77             for (int i = 0; i < cmp.length; i++) {
78                 if(! areEqual(cmp[i], with[i])){
79                     return false;
80                 }
81             }
82             return true;
83         }
84         
85         public static boolean areEqual(Boolean JavaDoc cmp, Boolean JavaDoc with){
86             if(cmp == null){
87                 return with == null;
88             }
89             return cmp.equals(with);
90         }
91         
92         public String JavaDoc toString() {
93             String JavaDoc res = "Item: ";
94             if(_booleans == null){
95                 return res + "[null]";
96             }
97             if(_booleans.length == 0){
98                 return res + "{ }";
99             }
100             res += "{ " + _booleans[0];
101             for (int i = 1; i < _booleans.length; i++) {
102                 res += ", " + _booleans[i];
103             }
104             res += " }";
105             return res;
106         }
107         
108     }
109
110 }
111
Popular Tags