Пример #1
0
  /** Applies function recursively from the given node. */
  public void applyRecursively(
      final Node<Payload> fromNode, final Function<Node<Payload>, Node<Payload>> modifier) {
    modifier.apply(fromNode);

    for (Node<Payload> child : fromNode.getChildren()) {
      applyRecursively(child, modifier);
    }
  }
Пример #2
0
 protected void dump(final Node<Payload> node, final int depth, final StringBuilder sb) {
   sb.append(Strings.repeat("  ", depth));
   sb.append(node.getLabel());
   sb.append(" (").append(node.getPath()).append(")");
   if (node.getPayload().isMarked()) {
     sb.append("*");
   }
   sb.append("\n");
   for (Node<Payload> child : node.getChildren()) {
     dump(child, depth + 1, sb);
   }
 }
Пример #3
0
  /**
   * Returns true if parent exists (passed in node is not ROOT), and parent's all children are
   * marked (their {@link Payload#isMarked()} is {@code true} for all of them.
   */
  protected boolean isParentAllChildMarkedForRuleB(final Node<Payload> node) {
    final Node<Payload> parent = node.getParent();

    if (parent != null) {
      final List<Node<Payload>> children = parent.getChildren();

      if (children.size() < 2) {
        return false;
      }

      for (Node<Payload> child : children) {
        if (!child.getPayload().isMarked()) {
          return false;
        }
      }

      return true;
    } else {
      return false;
    }
  }
Пример #4
0
 /**
  * Optimizes the tree by making the marked nodes as leafs, basically cutting all the branches that
  * are below marked node.
  */
 protected void optimizeTreeSize(final Node<Payload> changedNode) {
   // simply "cut off" children if any
   for (Node<Payload> child : changedNode.getChildren()) {
     changedNode.removeChild(child);
   }
 }