KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > NestedLists


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;
22
23 import java.util.*;
24
25 import com.db4o.query.*;
26
27
28 /**
29  *
30  */

31 public class NestedLists {
32     
33     static final int DEPTH = 10;
34     
35     List list;
36     String JavaDoc name;
37     
38     public void storeOne() {
39         nest(DEPTH);
40         name = "root";
41     }
42     
43     private void nest(int depth) {
44         if(depth > 0) {
45             list = Test.objectContainer().collections().newLinkedList();
46             NestedLists nl = new NestedLists();
47             nl.name = "nested";
48             nl.nest(depth - 1);
49             list.add(nl);
50         }
51     }
52     
53     
54     
55     public void test() {
56         Query q = Test.query();
57         q.constrain(NestedLists.class);
58         q.descend("name").constrain("root");
59         NestedLists nl = (NestedLists)q.execute().next();
60         for (int i = 0; i < DEPTH - 1; i++) {
61             nl = nl.checkNest();
62         }
63     }
64     
65     private NestedLists checkNest() {
66         Test.ensure(list != null);
67         NestedLists nl = (NestedLists)list.get(0);
68         Test.ensure(nl.name.equals("nested"));
69         return nl;
70     }
71     
72     public String JavaDoc toString() {
73         String JavaDoc str = "NestedList ";
74         if(name != null) {
75             str += name;
76         }
77         if(list != null) {
78             str += " list valid";
79         }else {
80             str += " list INVALID";
81         }
82         return str;
83     }
84     
85
86 }
87
Popular Tags