code: public int getMaxDepth() {
          if (isLeaf()) {
              // set and return at the same time
              return setMaxDepth(depth);
          }
          if (maxDepth == 0) {
              setMaxDepth(children.stream()
                      .max((c1, c2) -> Math.max(c1.getMaxDepth(), c2.getMaxDepth()))
                      .get().getDepth());
          }
          return maxDepth;
      }
docs: This method returns the maximum depth of the current branch from this node
  onwards.
  <br/>
  Example: If this node has only one child with a depth of 3. This node will also
  return 3, since the child is the deepest node in the current branch.
  <br/>
  If this is called on the root node, it will return the maximum depth of the whole
  tree.
  
  @return maximum depth of the current branch