Exemplo n.º 1
0
 private void removeThisFirstLevelChildFromSubtree(Node node) throws NodeDoesNotExistException {
   if (node.getPosition().equals(Constants.POSITION.RIGHT.toString())
       && this.isChildAlreadyExists(node, this.getRight())) {
     this.getRight().remove(node.getId());
   } else if (node.getPosition().equals(Constants.POSITION.LEFT.toString())
       && this.isChildAlreadyExists(node, this.getLeft())) {
     this.getLeft().remove(node.getId());
   } else throw new NodeDoesNotExistException();
 }
Exemplo n.º 2
0
 private void addThisFirstLevelChildToSubTree(Node node) {
   if (node.getPosition().equals(Constants.POSITION.RIGHT.toString())) {
     ArrayList<String> rightSubTree = this.getRight();
     if (this.isChildAlreadyExists(node, rightSubTree)) rightSubTree.remove(node.getId());
     rightSubTree.add(rightSubTree.size(), node.getId());
   }
   if (node.getPosition().equals(Constants.POSITION.LEFT.toString())) {
     ArrayList<String> leftSubTree = this.getLeft();
     if (this.isChildAlreadyExists(node, leftSubTree)) leftSubTree.remove(node.getId());
     leftSubTree.add(leftSubTree.size(), node.getId());
   }
 }