KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > test2 > RMap


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.test2;
22
23 import java.util.*;
24
25 import com.db4o.*;
26 import com.db4o.foundation.*;
27 import com.db4o.test.*;
28 import com.db4o.test.types.*;
29
30
31 public abstract class RMap implements RTestable{
32
33     abstract public Object JavaDoc newInstance();
34
35     TEntry entry(){
36         return new TEntry();
37     }
38
39     public Object JavaDoc set(Object JavaDoc obj, int ver){
40         TEntry[] arr = entry().test(ver);
41         Map map = (Map)obj;
42         map.clear();
43         for(int i = 0; i < arr.length; i ++){
44             map.put(arr[i].key, arr[i].value);
45         }
46         return obj;
47     }
48
49     public void compare(ObjectContainer con, Object JavaDoc obj, int ver){
50         Map map = (Map)obj;
51         TEntry[] entries = new TEntry[map.size()];
52         Iterator it = map.keySet().iterator();
53         int i = 0;
54         while(it.hasNext()){
55             entries[i] = new TEntry();
56             entries[i].key = it.next();
57             i++;
58         }
59         for(i = 0; i < entries.length; i ++){
60             entries[i].value = map.get(entries[i].key);
61         }
62         entry().compare(entries, ver, false);
63     }
64
65     public void specific(ObjectContainer con, int step){
66         TEntry entry = entry().firstElement();
67         Map map = (Map)newInstance();
68         if(step > 0){
69             map.put(entry.key, entry.value);
70             ObjectSet set = con.get(map);
71             Collection4 col = new Collection4();
72             while(set.hasNext()){
73                 Object JavaDoc obj = set.next();
74                 if(obj.getClass() == map.getClass()){
75                     col.add(obj);
76                 }
77             }
78             if(col.size() != step){
79                 Regression.addError("Map member query not found" );
80             }
81         }
82         entry = entry().noElement();
83         map.put(entry.key, entry.value);
84         if(con.get(map).size() != 0){
85             Regression.addError("Map member query found too many");
86         }
87     }
88
89
90     public boolean jdk2(){
91         return true;
92     }
93
94
95     public boolean ver3(){
96         return false;
97     }
98 }
Popular Tags