DepTreeNode implements Cloneable, Serializable { public DepTreeNode createOrGet(String path, URI uri) { if (path.startsWith("/")) { throw new IllegalArgumentException(path); } if (path.length() == 0) return this; String[] pathComps = path.split("/"); DepTreeNode node = this; int i = 0; for (String comp : pathComps) { DepTreeNode childNode = node.getChild(comp); if (childNode == null) { childNode = new DepTreeNode(comp, i == pathComps.length-1 ? uri : null); node.add(childNode); } node = childNode; i++; } return node; } DepTreeNode(String name, URI uri); String getName(); long lastModified(); long lastModifiedDep(); long lastModifiedDepTree(); DepTreeNode getParent(); DepTreeNode getRoot(); String[] getDefineDepArray(); String[] getRequireDepArray(); String[] getDependentFeatures(); String getParentPath(); String getFullPathName(); void add(DepTreeNode child); void overlay(DepTreeNode node); void addAll(Collection<DepTreeNode> children); DepTreeNode createOrGet(String path, URI uri); DepTreeNode getDescendent(String path); void remove(DepTreeNode child); void removeAll(); Map<String, DepTreeNode> getChildren(); DepTreeNode getChild(String name); void prune(); void setDependencies(String[] defineDependencies, String[] requireDependencies, String[] dependentFeatures, long lastModifiedFile, long lastModifiedDep); @Override String toString(); String toStringTree(); @Override DepTreeNode clone(); IConfig getConfig();  }
@Test public void testCreateOrGet() { DepTreeNode root = new DepTreeNode("root", null); DepTreeNode grandchild = root.createOrGet("child/grandchild", null); DepTreeNode child = root.getChild("child"); assertEquals(child.getParent(), root); assertEquals(grandchild.getParent(), child); DepTreeNode node = root.createOrGet("child/grandchild", null); assertEquals(node, grandchild); try { root.createOrGet("/badpath", null); fail("Exception not thrown"); } catch (IllegalArgumentException ex) {} }