示例#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();
 }
示例#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());
   }
 }
示例#3
0
 public Node(String id, String text, Node parent, String rootId, int index) {
   this._id = id;
   this.name = text;
   this.left = new ArrayList<>();
   this.right = new ArrayList<>();
   this.childSubTree = new ArrayList<>();
   this.parentId = (parent != null) ? parent.getId() : null;
   this.rootId = rootId;
   this.depth = (parent != null) ? parent.getDepth() + 1 : 0;
   this.index = index;
   this.position =
       (parent != null)
           ? ((this.rootId.equals(this.parentId)
               ? this.getFirstLevelChildPosition()
               : parent.getPosition()))
           : null;
 }