T - the argument type of the operationpublic class Program<T> extends Object implements Op<T>
| Constructor and Description |
|---|
Program(String name,
Tree<? extends Op<T>,?> tree)
Create a new program with the given name and the given operation tree.
|
| Modifier and Type | Method and Description |
|---|---|
T |
apply(T[] args) |
int |
arity()
Return the arity of the operation function.
|
static void |
check(Tree<? extends Op<?>,?> program)
Validates the given program tree.
|
T |
eval(T... args)
Convenient method, which lets you apply the program function without
explicitly create a wrapper array.
|
static <T> T |
eval(Tree<? extends Op<T>,?> tree,
T... variables)
Evaluates the given operation tree with the given variables.
|
String |
name()
Return the name of the operation.
|
static <A> TreeNode<Op<A>> |
of(int depth,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new program tree from the given (non) terminal operations with
the desired depth.
|
String |
toString() |
static <A> TreeNode<Op<A>> |
toTree(ISeq<? extends FlatTree<? extends Op<A>,?>> nodes,
ISeq<? extends Op<A>> terminals)
Creates a valid program tree from the given flattened sequence of
op nodes.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitget, isTerminal, ofpublic Program(String name, Tree<? extends Op<T>,?> tree)
name - the program nametree - the operation treeNullPointerException - if one of the given arguments is nullIllegalArgumentException - if the given operation tree is invalid,
which means there is at least one node where the operation arity
and the node child count differ.public int arity()
Op@SafeVarargs public final T eval(T... args)
args - the function argumentsNullPointerException - if the given variable array is nullIllegalArgumentException - if the length of the arguments array
is smaller than the program arityapply(Object[])@SafeVarargs public static <T> T eval(Tree<? extends Op<T>,?> tree, T... variables)
T - the argument typetree - the operation treevariables - the input variablesNullPointerException - if one of the arguments is nullIllegalArgumentException - if the length of the variable array
is smaller than the program aritypublic static void check(Tree<? extends Op<?>,?> program)
program - the program to validateNullPointerException - if the given program is nullIllegalArgumentException - if the given operation tree is invalid,
which means there is at least one node where the operation arity
and the node child count differ.public static <A> TreeNode<Op<A>> of(int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
A - the operational typedepth - the desired depth of the program treeoperations - the list of non-terminal operationsterminals - the list of terminal operationsNullPointerException - if one of the given operations is
nullIllegalArgumentException - if the given tree depth is smaller than
zeropublic static <A> TreeNode<Op<A>> toTree(ISeq<? extends FlatTree<? extends Op<A>,?>> nodes, ISeq<? extends Op<A>> terminals)
operations and termination nodes are
used for repairing the program tree, if necessary.A - the operation argument typenodes - the flattened, possible corrupt, program treeterminals - the usable non-terminal operation nodes to use for
reparationNullPointerException - if one of the arguments is nullIllegalArgumentException - if the nodes sequence is empty© 2007-2017 Franz Wilhelmstötter (2017-08-22 19:30)