protected List<R> visitChildrenAllowingConcurrentModification(ParentNode<? extends N> node) {
    List<R> results = new ArrayList<>(node.numChildren());
    // use toArray to create a copy to avoid concurrent modification exception
    for (Node child : node.getChildren().toArray(EMPTY_NODE_ARRAY)) {
      // safe since the parent only contains subtypes of N.
      @SuppressWarnings("unchecked")
      N typedChild = (N) child;
      results.add(visit(typedChild));
    }
    return results;
  }
protected List < R > visitChildrenAllowingConcurrentModification ( ParentNode < ? extends N > node ) { List < R > results = new ArrayList < > ( node . numChildren ( ) ) ; for ( Node child : node . getChildren ( ) . toArray ( EMPTY_NODE_ARRAY ) ) { @ SuppressWarnings ( "unchecked" ) N typedChild = ( N ) child ; results . add ( visit ( typedChild ) ) ; } return results ; }
Helper to visit all the children of a node, in order.

<p>This method differs from {@code visitChildren} in that we are iterating through a copy of
the children. Thus, concurrent modification of the list of children is allowed.

@param node The parent node whose children to visit.
@return The list of return values from visiting the children.
@see #visitChildren