@SuppressWarnings("unchecked") @Override public boolean equals(Object obj) { if ((obj != null) && (obj.getClass().equals(this.getClass()))) { Tree<T> otherTree = (Tree<T>) obj; if (!(this.label.equals(otherTree.label))) return false; if (this.getNumberOfChildren() != otherTree.getNumberOfChildren()) return false; for (int childId = 0; childId < children.size(); childId++) { if (!(children.get(childId).equals(otherTree.children.get(childId)))) return false; } return true; } return false; }
/** * This function returns a list of trees from a node in the tree to the root. If the node is * deeper than maxdepth, then the bottom maxDepth nodes are returned. */ @Deprecated public static <T> List<Tree<T>> getPathTreesToRoot(Tree<T> tree, Tree<T> node, int maxDepth) throws Exception { List<Tree<T>> path = new ArrayList<>(); int depth = 0; Tree<T> t = node; while (!t.equals(tree)) { path.add(t); t = t.getParent(); if (t == null) throw new Exception(node + " is not an element of " + tree); depth++; if (depth > maxDepth) { break; } } path.add(tree); Collections.reverse(path); return path; }
/** * This function returns a list of trees from a node in the tree to the root. If the node is * deeper than maxdepth, then the bottom maxDepth nodes are returned. */ @Deprecated public static <T> List<Tree<T>> getPathTreesToRoot(Tree<T> tree, Tree<T> node, int maxDepth) throws Exception { List<Tree<T>> path = new ArrayList<>(); int depth = 0; Tree<T> t = node; while (!t.equals(tree)) { path.add(t); t = t.getParent(); if (t == null) throw new Exception(node + " is not an element of " + tree); depth++; if (depth > maxDepth) { break; } } path.add(tree); Collections.reverse(path); return path; }
@SuppressWarnings("unchecked") @Override public boolean equals(Object obj) { if ((obj != null) && (obj.getClass().equals(this.getClass()))) { Tree<T> otherTree = (Tree<T>) obj; if (!(this.label.equals(otherTree.label))) return false; if (this.getNumberOfChildren() != otherTree.getNumberOfChildren()) return false; for (int childId = 0; childId < children.size(); childId++) { if (!(children.get(childId).equals(otherTree.children.get(childId)))) return false; } return true; } return false; }
/** * This function returns a list of trees from a node in the tree to the root. If the node is * deeper than maxdepth, then the bottom maxDepth nodes are returned. */ @Deprecated public static <T> List<Tree<T>> getPathTreesToRoot(Tree<T> tree, Tree<T> node, int maxDepth) throws Exception { List<Tree<T>> path = new ArrayList<>(); int depth = 0; Tree<T> t = node; while (!t.equals(tree)) { path.add(t); t = t.getParent(); if (t == null) throw new Exception(node + " is not an element of " + tree); depth++; if (depth > maxDepth) { break; } } path.add(tree); Collections.reverse(path); return path; }
/** * This function returns a list of trees from a node in the tree to the root. If the node is * deeper than maxdepth, then the bottom maxDepth nodes are returned. */ @Deprecated public static <T> List<Tree<T>> getPathTreesToRoot(Tree<T> tree, Tree<T> node, int maxDepth) throws Exception { List<Tree<T>> path = new ArrayList<>(); int depth = 0; Tree<T> t = node; while (!t.equals(tree)) { path.add(t); t = t.getParent(); if (t == null) throw new Exception(node + " is not an element of " + tree); depth++; if (depth > maxDepth) { break; } } path.add(tree); Collections.reverse(path); return path; }
@Deprecated public static <T> List<T> getPathToRoot(Tree<T> tree, Tree<T> leaf, int maxDepth) throws Exception { List<T> path = new ArrayList<>(); int depth = 0; Tree<T> t = leaf; while (!t.equals(tree)) { path.add(t.getLabel()); t = t.getParent(); depth++; if (depth > maxDepth) { break; } } path.add(tree.getLabel()); Collections.reverse(path); return path; }
@Deprecated public static <T> List<T> getPathToRoot(Tree<T> tree, Tree<T> leaf, int maxDepth) throws Exception { List<T> path = new ArrayList<>(); int depth = 0; Tree<T> t = leaf; while (!t.equals(tree)) { path.add(t.getLabel()); t = t.getParent(); depth++; if (depth > maxDepth) { break; } } path.add(tree.getLabel()); Collections.reverse(path); return path; }
@Deprecated public static <T> List<T> getPathToRoot(Tree<T> tree, Tree<T> leaf, int maxDepth) throws Exception { List<T> path = new ArrayList<>(); int depth = 0; Tree<T> t = leaf; while (!t.equals(tree)) { path.add(t.getLabel()); t = t.getParent(); depth++; if (depth > maxDepth) { break; } } path.add(tree.getLabel()); Collections.reverse(path); return path; }
@Deprecated public static <T> List<T> getPathToRoot(Tree<T> tree, Tree<T> leaf, int maxDepth) throws Exception { List<T> path = new ArrayList<>(); int depth = 0; Tree<T> t = leaf; while (!t.equals(tree)) { path.add(t.getLabel()); t = t.getParent(); depth++; if (depth > maxDepth) { break; } } path.add(tree.getLabel()); Collections.reverse(path); return path; }