/** * The only way to get a new graph * * @param root the graph's root name * @return */ public static GraphTree makeGraph(String root) { GraphTree rootNode = new GraphTree(root); rootNode.pathsMap = new HashMap<Integer, GraphTree>(); rootNode.pathsMap.put(rootNode.getPath().hashCode(), rootNode); return rootNode; }
synchronized private void addChild(String childName) { if(!childsMap.containsKey(childName)) { GraphTree newChild = new GraphTree(childName); childsMap.put(childName, newChild); newChild.parent = this; newChild.pathsMap = pathsMap; pathsMap.put(newChild.getPath().hashCode(), newChild); } }
private boolean evaluateTree(ParamsBean params, JrdsJSONWriter w, HostsList root, GraphTree trytree) throws IOException { for(GraphTree tree: findRoot(Collections.singleton(trytree))) { sub(params, w, tree, "tree", Filter.EVERYTHING, "", tree.getPath().hashCode()); } return true; }
/** * @param f, can be null * @return */ public List<GraphNode> enumerateChildsGraph(Filter f) { List<GraphNode> retValue = new ArrayList<GraphNode>(); if(graphsSet != null) { if(f == null) retValue.addAll(graphsSet.values()); else { for(GraphNode g: graphsSet.values()) { String path = this.getPath() + "/" + g.getName(); if(f.acceptGraph(g, path)) retValue.add(g); } } } if(childsMap != null) { for(GraphTree child: childsMap.values()) { retValue.addAll(child.enumerateChildsGraph(f)); } } return retValue; }
private boolean evaluateFilter(ParamsBean params, JrdsJSONWriter w, HostsList root, Filter f) throws IOException { Collection<GraphTree> level = root.getTrees(); // We construct the graph tree root to use // The tree is parsed twice, that's not optimal Collection<GraphTree> rootToDo = new HashSet<GraphTree>(level.size()); for(GraphTree tree: level) { GraphTree testTree = f.setRoot(tree); if(testTree != null && !rootToDo.contains(testTree) && testTree.enumerateChildsGraph(f).size() > 0) { rootToDo.add(testTree); } } for(GraphTree tree: findRoot(rootToDo)) { sub(params, w, tree, "tree", f, "", tree.getPath().hashCode()); } return true; }