public static <A> TreeNode<Op<A>> toTree(
		final ISeq<? extends FlatTree<? extends Op<A>, ?>> nodes,
		final ISeq<? extends Op<A>> terminals
	) {
		if (nodes.isEmpty()) {
			throw new IllegalArgumentException("Tree nodes must not be empty.");
		}

		final Op<A> op = requireNonNull(nodes.get(0).value());
		final TreeNode<Op<A>> tree = TreeNode.of(op);
		return toTree(
			tree,
			0,
			nodes,
			offsets(nodes),
			terminals,
			RandomRegistry.random()
		);
	}
Creates a valid program tree from the given flattened sequence of
op nodes. The given {@code operations} and {@code termination} nodes are
used for <em>repairing</em> the program tree, if necessary.

@param nodes the flattened, possible corrupt, program tree
@param terminals the usable non-terminal operation nodes to use for
       reparation
@param <A> the operation argument type
@return a new valid program tree build from the flattened program tree
@throws NullPointerException if one of the arguments is {@code null}
@throws IllegalArgumentException if the {@code nodes} sequence is empty
jenetics.prog/src/main/java/io/jenetics/prog/op/Program.java