| 1 21 package com.db4o.test; 22 23 import java.util.*; 24 25 import com.db4o.query.*; 26 27 28 31 public class NestedLists { 32 33 static final int DEPTH = 10; 34 35 List list; 36 String 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 toString() { 73 String 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 |