01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: 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: public abstract class RMap implements RTestable {
31:
32: abstract public Object newInstance();
33:
34: TEntry entry() {
35: return new TEntry();
36: }
37:
38: public Object set(Object obj, int ver) {
39: TEntry[] arr = entry().test(ver);
40: Map map = (Map) obj;
41: map.clear();
42: for (int i = 0; i < arr.length; i++) {
43: map.put(arr[i].key, arr[i].value);
44: }
45: return obj;
46: }
47:
48: public void compare(ObjectContainer con, Object obj, int ver) {
49: Map map = (Map) obj;
50: TEntry[] entries = new TEntry[map.size()];
51: Iterator it = map.keySet().iterator();
52: int i = 0;
53: while (it.hasNext()) {
54: entries[i] = new TEntry();
55: entries[i].key = it.next();
56: i++;
57: }
58: for (i = 0; i < entries.length; i++) {
59: entries[i].value = map.get(entries[i].key);
60: }
61: entry().compare(entries, ver, false);
62: }
63:
64: public void specific(ObjectContainer con, int step) {
65: TEntry entry = entry().firstElement();
66: Map map = (Map) newInstance();
67: if (step > 0) {
68: map.put(entry.key, entry.value);
69: ObjectSet set = con.get(map);
70: Collection4 col = new Collection4();
71: while (set.hasNext()) {
72: Object obj = set.next();
73: if (obj.getClass() == map.getClass()) {
74: col.add(obj);
75: }
76: }
77: if (col.size() != step) {
78: Regression.addError("Map member query not found");
79: }
80: }
81: entry = entry().noElement();
82: map.put(entry.key, entry.value);
83: if (con.get(map).size() != 0) {
84: Regression.addError("Map member query found too many");
85: }
86: }
87:
88: public boolean jdk2() {
89: return true;
90: }
91:
92: public boolean ver3() {
93: return false;
94: }
95: }
|