1 29 package jegg.type; 30 31 import java.util.Iterator ; 32 33 40 public class TypeTree 41 { 42 private Node root = new Node(Object .class,null); 43 44 public TypeTree() 45 { 46 super(); 47 } 48 49 public Node find(Class c) 50 { 51 return root.findNearest(c); 52 } 53 54 public Node getRoot() 55 { 56 return root; 57 } 58 59 public void insert(Class c, Object cookie) 60 { 61 if (Object .class.equals(c)) 62 { 63 if (null == root.getCookie()) 64 { 65 root.setCookie(cookie); 66 } 67 } 68 else 69 { 70 Node nd = new Node(c,cookie); 71 if (!root.insert(nd)) 72 { 73 if (!nd.insert(root)) 74 { 75 throw new IllegalStateException ("unable to insert class "+c.getName()); 76 } 77 } 78 } 79 } 80 81 public Iterator iterator() 82 { 83 return new TypeTreeIterator(this,true); 84 } 85 } 86 | Popular Tags |