Source:
<code>public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) { this.commands = new CompositeCommandImpl.CompositeCommandBuilder<AbstractCanvasHandler, CanvasViolation>() .reverse() .build(); CommandResult<CanvasViolation> rootResult = super.execute(context); if (CommandUtils.isError(rootResult)) { return rootResult; } if (GraphUtils.hasChildren(getCandidate())) { Graph graph = context.getGraphIndex().getGraph(); childrenTraverseProcessor.consume(graph, getCandidate(), node -> { commands.addCommand(new CloneCanvasNodeCommand(getCandidate(), node, getShapeSetId())); }); <START> childrenTraverseProcessor.consume(graph, getCandidate(), node -> { <END> node.getOutEdges() .stream() .filter(edge -> edge.getContent() instanceof Dock) .forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode()))); node.getOutEdges() .stream() .filter(edge -> edge.getContent() instanceof ViewConnector) .forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId()))); }); } if (GraphUtils.hasDockedNodes(getCandidate())) { List<Edge> edges = getCandidate().getOutEdges(); edges.stream() .filter(edge -> edge.getContent() instanceof Dock) .map(edge -> edge.getTargetNode()) .forEach(targetNode -> { commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId())); commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode)); }); } return commands.execute(context); }</code><technical_language>consuming graph nodes once? I code a lines</technical_language>

Target:
public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) { commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .reverse() .build(); commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId())); if (GraphUtils.hasChildren(getCandidate())) { Graph graph = context.getGraphIndex().getGraph(); List<Edge> clonedEdges = new ArrayList<>(); childrenTraverseProcessor.get() .setRootUUID(getCandidate().getUUID()) .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { @Override public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) { commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId())); clonedEdges.addAll(node.getOutEdges()); return false; } }); clonedEdges.stream() .filter(edge -> edge.getContent() instanceof Dock) .forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode()))); clonedEdges .stream() .filter(edge -> edge.getContent() instanceof ViewConnector) .forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId()))); } if (GraphUtils.hasDockedNodes(getCandidate())) { List<Edge> edges = getCandidate().getOutEdges(); edges.stream() .filter(edge -> edge.getContent() instanceof Dock) .map(edge -> edge.getTargetNode()) .forEach(targetNode -> { commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId())); commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode)); }); } return commands.execute(context); }