/** * @return the depth of the given path, being zero if the path is the root path (i.e. the empty * string) or > 0 depending on how many steps compose the path */ public static int depth(String path) { return split(path).size(); }
/** * @return the depth of the given path, being zero if the path is the root path (i.e. the empty * string) or > 0 depending on how many steps compose the path */ public static int depth(String path) { return split(path).size(); }
public List<String> toPath(String path, @Nullable String node) { ArrayList<String> pathlist = new ArrayList<>(); pathlist.add(NodeRef.ROOT); pathlist.addAll(NodeRef.split(path)); if (node != null) { pathlist.add(node); } return pathlist; }
public MutableTree getChild(String path) throws IllegalArgumentException { return getChild(NodeRef.split(path)); }
public void setChild(String parentPath, Node node) { List<String> parentSteps = split(parentPath); setChild(parentSteps, node); }
public void setChild(String parentPath, Node node) { List<String> parentSteps = split(parentPath); setChild(parentSteps, node); }
public DiffPathFilter(List<String> filters) { Preconditions.checkNotNull(filters, "filter list is null"); Preconditions.checkArgument(!filters.isEmpty(), "Don't use an empty filter list"); pathFilter = new PathFilter(NodeRef.ROOT); for (String f : filters) { Preconditions.checkArgument(!Strings.isNullOrEmpty(f)); pathFilter.add(NodeRef.split(f)); } }
public MutableTree getChild(String path) throws IllegalArgumentException { return getChild(NodeRef.split(path)); }
/** * Remove the parent path from the given child path. * * @param parentPath the parent path to remove * @param childPath the child path to remove from * @return the stripped child path */ public static String removeParent(final String parentPath, final String childPath) { checkArgument(isChild(parentPath, childPath)); List<String> parent = split(parentPath); List<String> child = split(childPath); child = child.subList(parent.size(), child.size()); String strippedChildPath = child.get(0); for (int i = 1; i < child.size(); i++) { strippedChildPath = appendChild(strippedChildPath, child.get(i)); } return strippedChildPath; }
@Nullable public MutableTree removeChild(String path) { NodeRef.checkValidPath(path); final List<String> querySteps = NodeRef.split(path); List<String> visited = new ArrayList<>(querySteps.size()); MutableTree tree = this; MutableTree removed = null; for (Iterator<String> childNames = querySteps.iterator(); childNames.hasNext();) { String childName = childNames.next(); visited.add(childName); MutableTree child = tree.childTrees.get(childName); if (child == null) { break; } if (querySteps.equals(visited)) { removed = tree.childTrees.remove(childName); break; } else { tree = child; } } return removed; }
@Nullable public MutableTree removeChild(String path) { NodeRef.checkValidPath(path); final List<String> querySteps = NodeRef.split(path); List<String> visited = new ArrayList<>(querySteps.size()); MutableTree tree = this; MutableTree removed = null; for (Iterator<String> childNames = querySteps.iterator(); childNames.hasNext();) { String childName = childNames.next(); visited.add(childName); MutableTree child = tree.childTrees.get(childName); if (child == null) { break; } if (querySteps.equals(visited)) { removed = tree.childTrees.remove(childName); break; } else { tree = child; } } return removed; }
/** * Remove the parent path from the given child path. * * @param parentPath the parent path to remove * @param childPath the child path to remove from * @return the stripped child path */ public static String removeParent(final String parentPath, final String childPath) { checkArgument(isChild(parentPath, childPath)); ImmutableList<String> parent = split(parentPath); ImmutableList<String> child = split(childPath); child = child.subList(parent.size(), child.size()); String strippedChildPath = child.get(0); for (int i = 1; i < child.size(); i++) { strippedChildPath = appendChild(strippedChildPath, child.get(i)); } return strippedChildPath; }
public void forceChild(final String parentPath, final Node treeNode) { List<String> parentSteps = NodeRef.split(parentPath); MutableTree parent = this; for (String name : parentSteps) { MutableTree child = parent.childTrees.get(name); if (child == null) { child = new MutableTree(name); parent.childTrees.put(name, child); } parent = child; } MutableTree tree = parent.childTrees.get(treeNode.getName()); if (tree == null) { tree = new MutableTree(treeNode); parent.childTrees.put(treeNode.getName(), tree); } else { tree.setNode(treeNode); } }
public void forceChild(final String parentPath, final Node treeNode) { ImmutableList<String> parentSteps = NodeRef.split(parentPath); MutableTree parent = this; for (String name : parentSteps) { MutableTree child = parent.childTrees.get(name); if (child == null) { child = new MutableTree(name); parent.childTrees.put(name, child); } parent = child; } MutableTree tree = parent.childTrees.get(treeNode.getName()); if (tree == null) { tree = new MutableTree(treeNode); parent.childTrees.put(treeNode.getName(), tree); } else { tree.setNode(treeNode); } }