KickJava   Java API By Example, From Geeks To Geeks.

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


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 RCollection 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         Collection col = (Collection)obj;
42         col.clear();
43         for(int i = 0; i < arr.length; i ++){
44             col.add(arr[i].key);
45         }
46         return obj;
47     }
48
49     public void compare(ObjectContainer con, Object JavaDoc obj, int ver){
50         Collection col = (Collection)obj;
51         TEntry[] entries = new TEntry[col.size()];
52         Iterator it = col.iterator();
53         int i = 0;
54         while(it.hasNext()){
55             entries[i] = new TEntry();
56             entries[i].key = it.next();
57             i++;
58         }
59         entry().compare(entries, ver, true);
60     }
61
62     public void specific(ObjectContainer con, int step){
63         TEntry entry = entry().firstElement();
64         Collection col = (Collection)newInstance();
65         if(step > 0){
66             col.add(entry.key);
67                         ObjectSet set = con.get(col);
68             Collection4 sizeCalc = new Collection4();
69             while(set.hasNext()){
70                 Object JavaDoc obj = set.next();
71                 if(obj.getClass() == col.getClass()){
72                     sizeCalc.add(obj);
73                 }
74             }
75             if(sizeCalc.size() != step){
76                 Regression.addError("Collection member query not found");
77             }
78         }
79         entry = entry().noElement();
80         col.add(entry.key);
81         if(con.get(col).size() != 0){
82             Regression.addError("Collection member query found too many");
83         }
84     }
85
86
87     public boolean jdk2(){
88         return true;
89     }
90
91     public boolean ver3(){
92         return false;
93     }
94 }
Popular Tags