/** * add a path to the path trie * @param path */ public void addPath(String path) { if (path == null) { return; } String[] pathComponents = path.split("/"); TrieNode parent = rootNode; String part = null; if (pathComponents.length <= 1) { throw new IllegalArgumentException("Invalid path " + path); } for (int i=1; i<pathComponents.length; i++) { part = pathComponents[i]; if (parent.getChild(part) == null) { parent.addChild(part, new TrieNode(parent)); } parent = parent.getChild(part); } parent.setProperty(true); }
/** * delete a path from the trie * @param path the path to be deleted */ public void deletePath(String path) { if (path == null) { return; } String[] pathComponents = path.split("/"); TrieNode parent = rootNode; String part = null; if (pathComponents.length <= 1) { throw new IllegalArgumentException("Invalid path " + path); } for (int i=1; i<pathComponents.length; i++) { part = pathComponents[i]; if (parent.getChild(part) == null) { //the path does not exist return; } parent = parent.getChild(part); LOG.info("{}",parent); } TrieNode realParent = parent.getParent(); realParent.deleteChild(part); }
/** * delete child from this node * @param childName the string name of the child to * be deleted */ void deleteChild(String childName) { synchronized(children) { if (!children.containsKey(childName)) { return; } TrieNode childNode = children.get(childName); // this is the only child node. if (childNode.getChildren().length == 1) { childNode.setParent(null); children.remove(childName); } else { // their are more child nodes // so just reset property. childNode.setProperty(false); } } }
int lastindex = -1; while((i < pathComponents.length)) { if (parent.getChild(pathComponents[i]) != null) { part = pathComponents[i]; parent = parent.getChild(part); components.add(part); if (parent.getProperty()) { lastindex = i-1;
/** * delete child from this node * @param childName the string name of the child to * be deleted */ void deleteChild(String childName) { synchronized(children) { if (!children.containsKey(childName)) { return; } TrieNode childNode = children.get(childName); // this is the only child node. if (childNode.getChildren().length == 1) { childNode.setParent(null); children.remove(childName); } else { // their are more child nodes // so just reset property. childNode.setProperty(false); } } }
/** * delete a path from the trie * @param path the path to be deleted */ public void deletePath(String path) { if (path == null) { return; } String[] pathComponents = path.split("/"); TrieNode parent = rootNode; String part = null; if (pathComponents.length <= 1) { throw new IllegalArgumentException("Invalid path " + path); } for (int i=1; i<pathComponents.length; i++) { part = pathComponents[i]; if (parent.getChild(part) == null) { //the path does not exist return; } parent = parent.getChild(part); LOG.info(parent); } TrieNode realParent = parent.getParent(); realParent.deleteChild(part); }
/** * add a path to the path trie * @param path */ public void addPath(String path) { if (path == null) { return; } String[] pathComponents = path.split("/"); TrieNode parent = rootNode; String part = null; if (pathComponents.length <= 1) { throw new IllegalArgumentException("Invalid path " + path); } for (int i=1; i<pathComponents.length; i++) { part = pathComponents[i]; if (parent.getChild(part) == null) { parent.addChild(part, new TrieNode(parent)); } parent = parent.getChild(part); } parent.setProperty(true); }
/** * construct a new PathTrie with * a root node of / */ public PathTrie() { this.rootNode = new TrieNode(null); }
int lastindex = -1; while((i < pathComponents.length)) { if (parent.getChild(pathComponents[i]) != null) { part = pathComponents[i]; parent = parent.getChild(part); components.add(part); if (parent.getProperty()) { lastindex = i-1;
int lastindex = -1; while((i < pathComponents.length)) { if (parent.getChild(pathComponents[i]) != null) { part = pathComponents[i]; parent = parent.getChild(part); components.add(part); if (parent.getProperty()) { lastindex = i-1;
/** * delete child from this node * @param childName the string name of the child to * be deleted */ void deleteChild(String childName) { synchronized(children) { if (!children.containsKey(childName)) { return; } TrieNode childNode = children.get(childName); // this is the only child node. if (childNode.getChildren().length == 1) { childNode.setParent(null); children.remove(childName); } else { // their are more child nodes // so just reset property. childNode.setProperty(false); } } }
/** * delete a path from the trie * @param path the path to be deleted */ public void deletePath(String path) { if (path == null) { return; } String[] pathComponents = path.split("/"); TrieNode parent = rootNode; String part = null; if (pathComponents.length <= 1) { throw new IllegalArgumentException("Invalid path " + path); } for (int i=1; i<pathComponents.length; i++) { part = pathComponents[i]; if (parent.getChild(part) == null) { //the path does not exist return; } parent = parent.getChild(part); LOG.info("{}",parent); } TrieNode realParent = parent.getParent(); realParent.deleteChild(part); }
/** * clear all nodes */ public void clear() { for(String child : rootNode.getChildren()) { rootNode.deleteChild(child); } } }
/** * construct a new PathTrie with * a root node of / */ public PathTrie() { this.rootNode = new TrieNode(null); }
/** * add a path to the path trie * @param path */ public void addPath(String path) { if (path == null) { return; } String[] pathComponents = path.split("/"); TrieNode parent = rootNode; String part = null; if (pathComponents.length <= 1) { throw new IllegalArgumentException("Invalid path " + path); } for (int i=1; i<pathComponents.length; i++) { part = pathComponents[i]; if (parent.getChild(part) == null) { parent.addChild(part, new TrieNode(parent)); } parent = parent.getChild(part); } parent.setProperty(true); }
/** * clear all nodes */ public void clear() { for(String child : rootNode.getChildren()) { rootNode.deleteChild(child); } } }
/** * construct a new PathTrie with * a root node of / */ public PathTrie() { this.rootNode = new TrieNode(null); }