DepUtils { static public DepTreeNode getNodeForResource(URI requestUri, Map<URI, DepTreeNode> dependencies) { DepTreeNode result = null; for (Entry<URI, DepTreeNode> dependency : dependencies.entrySet()) { URI uri = dependency.getKey(); if (requestUri.getScheme() == null && uri.getScheme() != null || requestUri.getScheme() != null && !requestUri.getScheme().equals(uri.getScheme())) continue; if (requestUri.getHost() == null && uri.getHost() != null || requestUri.getHost() != null && !requestUri.getHost().equals(uri.getHost())) continue; if (requestUri.getPath().equals(uri.getPath()) || requestUri.getPath().startsWith(uri.getPath()) && (uri.getPath().endsWith("/") || requestUri.getPath().charAt(uri.getPath().length()) == '/')) { if (requestUri.getPath().equals(uri.getPath())) { return dependency.getValue(); } else { String modulePath = requestUri.getPath().substring(uri.getPath().length()); if (modulePath.startsWith("/")) { modulePath = modulePath.substring(1); } result = dependency.getValue().getDescendent(modulePath); } break; } } return result; }  static Collection<URI> removeRedundantPaths(Collection<URI> uris); static DepTreeNode getNodeForResource(URI requestUri,
			Map<URI, DepTreeNode> dependencies); static ParseResult parseDependencies(Node node, Set<String> dependentFeatures);  }
@Test public void testGetNodeForFilepath() throws URISyntaxException { URI[] paths = new URI[] { new URI("/a/a/x"), new URI("/a/y"), new URI("/b/a/z"), }; DepTreeNode x = new DepTreeNode("", null); DepTreeNode y = new DepTreeNode("", null); DepTreeNode z = new DepTreeNode("", null); DepTreeNode t1 = x.createOrGet("1/1", null); DepTreeNode t2 = x.createOrGet("1/2", null); DepTreeNode t3 = z.createOrGet("3", null); Map<URI, DepTreeNode> map = new HashMap<URI, DepTreeNode>(); map.put(paths[0], x); map.put(paths[1], y); map.put(paths[2], z); DepTreeNode node = DepUtils.getNodeForResource(new URI(paths[0].getPath()+"/1"), map); assertEquals(node.getName(), "1"); node = DepUtils.getNodeForResource(new URI(paths[0].getPath()+"/1/1"), map); assertEquals(node, t1); node = DepUtils.getNodeForResource(new URI(paths[0].getPath()+"/1/2"), map); assertEquals(node, t2); node = DepUtils.getNodeForResource(new URI(paths[2].getPath()+"/3"), map); assertEquals(node, t3); node = DepUtils.getNodeForResource(paths[1], map); assertEquals(node, y); node = DepUtils.getNodeForResource(paths[2], map); assertEquals(node, z); node = DepUtils.getNodeForResource(new URI(paths[0].getPath()+"/2"), map); assertNull(node); node = DepUtils.getNodeForResource(new URI("/a/a"), map); assertNull(node); }