KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > types > TEntry


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.types;
22
23 import com.db4o.test.*;
24
25 public class TEntry {
26
27     public Object JavaDoc key;
28     public Object JavaDoc value;
29
30     public TEntry(){
31     }
32
33     public TEntry(Object JavaDoc key, Object JavaDoc value) {
34         this.key = key;
35         this.value = value;
36     }
37
38     public TEntry firstElement(){
39         return new TEntry("first", "firstvalue");
40     }
41
42     public TEntry lastElement(){
43         return new TEntry(new ObjectSimplePublic("lastKey"), new ObjectSimplePublic("lastValue"));
44     }
45
46     public TEntry noElement(){
47         return new TEntry("NO", "babe");
48     }
49
50     public TEntry[] test(int ver){
51         if(ver == 1){
52             return new TEntry[]{
53                 firstElement(),
54                 new TEntry(new Integer JavaDoc(111), new ObjectSimplePublic("111")),
55                 new TEntry(new Long JavaDoc(9999111), new Double JavaDoc(0.4566)),
56                 /*
57                 
58                 need to extend compare for the following
59                 
60                 new Entry(
61                     new ObjectSimplePublic[]{
62                         new ObjectSimplePublic("killer1"), new ObjectSimplePublic("killer2")
63                     },
64                     new ObjectSimplePublic[]{
65                         new ObjectSimplePublic("killer3"), null, new ObjectSimplePublic("killer4")
66                     }
67                 ),
68                 */

69                 lastElement()
70             };
71         }
72         return new TEntry[]{
73             new TEntry(new Integer JavaDoc(222), new ObjectSimplePublic("111")),
74             new TEntry("222", "TrippleTwo"),
75             new TEntry(new ObjectSimplePublic("2222"), new ObjectSimplePublic("222")),
76         };
77     }
78
79     public void compare(TEntry[] a_cmp, int oneOrTwo, boolean keysOnly){
80         TEntry[] tests = test(oneOrTwo);
81         TEntry[] cmp = new TEntry[a_cmp.length];
82         System.arraycopy(a_cmp,0, cmp, 0, a_cmp.length);
83         if(cmp == null){
84             Regression.addError("Entry:argument is null");
85             return;
86         }
87         if(cmp.length != tests.length){
88             Regression.addError("Entry:arrays of different length");
89             return;
90         }
91         for(int i = 0; i < tests.length; i ++){
92             boolean found = false;
93             for(int j=0; j < cmp.length; j++){
94                 if(cmp[j] != null){
95                     if(tests[i].key.equals(cmp[j].key)){
96                         if(!keysOnly){
97                             if(! tests[i].value.equals(cmp[j].value)){
98                                 Regression.addError("Entry:inequality");
99                                 return;
100                             }
101                         }
102                         cmp[j] = null;
103                         found = true;
104                         break;
105                     }
106                 }
107             }
108             if(! found){
109                 
110                 Regression.addError("element not found");
111             }
112         }
113     }
114 }
Popular Tags