Interface TreeRewriter<V>

 All Known Implementing Classes:
TreeRewriteRule
,TRS
 Functional Interface:
 This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface TreeRewriter<V>
Interface for rewriting a given tree. The rewrite is performed on a mutableTreeNode
and is done in place.Description from Wikipedia: In mathematics, computer science, and logic, rewriting covers a wide range of (potentially nondeterministic) methods of replacing subterms of a formula with other terms. In their most basic form, they consist of a set of objects, plus relations on how to transform those objects. Rewriting can be nondeterministic. One rule to rewrite a term could be applied in many different ways to that term, or more than one rule could be applicable. Rewriting systems then do not provide an algorithm for changing one term to another, but a set of possible rule applications. When combined with an appropriate algorithm, however, rewrite systems can be viewed as computer programs, and several theorem provers and declarative programming languages are based on term rewriting.
 Since:
 5.0
 Version:
 5.0
 API Note:
 The rewriting is done in place, to a mutable
TreeNode
object.


Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <V> TreeRewriter<V>
concat(TreeRewriter<V>... rewriters)
Concat the givenrewriters
to one treerewriter.default int
rewrite(TreeNode<V> tree)
Applies the rewriting to the given (mutable)tree
.int
rewrite(TreeNode<V> tree, int limit)
Applies the rewriting to the given (mutable)tree
.static <V> int
rewrite(TreeNode<V> tree, int limit, Iterable<? extends TreeRewriter<V>> rewriters)
Rewrites the giventree
by applying the givenrewriters
.static <V> int
rewrite(TreeNode<V> tree, Iterable<? extends TreeRewriter<V>> rewriters)
Rewrites the giventree
by applying the givenrewriters
.



Method Detail

rewrite
int rewrite(TreeNode<V> tree, int limit)
Applies the rewriting to the given (mutable)tree
. The tree rewrite is done in place. Via thelimit
parameter, the termination of the treerewrite process can be guaranteed. Parameters:
tree
 the tree to be rewrittenlimit
 the maximal number this rewrite rule is applied to the given tree. This guarantees the termination of the rewrite method. Returns:
 the number of rewrites applied to the input
tree
 Throws:
NullPointerException
 if the giventree
isnull
IllegalArgumentException
 if thelimit
is smaller than one

rewrite
default int rewrite(TreeNode<V> tree)
Applies the rewriting to the given (mutable)tree
. The tree rewrite is done in place. The limit of the applied rewrites is set unlimited (Integer.MAX_VALUE
). Parameters:
tree
 the tree to be rewritten Returns:
true
if the tree has been changed (rewritten) by this method,false
if the tree hasn't been changed Throws:
NullPointerException
 if the giventree
isnull
 See Also:
rewrite(TreeNode, int)

rewrite
static <V> int rewrite(TreeNode<V> tree, int limit, Iterable<? extends TreeRewriter<V>> rewriters)
Rewrites the giventree
by applying the givenrewriters
. This method to apply the all rewriters, in the order they are given in the sequence, until the tree stays unchanged. Type Parameters:
V
 the tree value type Parameters:
tree
 the tree to rewritelimit
 the maximal number this rewrite rule is applied to the given tree. This guarantees the termination of the rewrite method.rewriters
 the rewriters applied to the tree Returns:
true
if the tree has been changed (rewritten) by this method,false
if the tree hasn't been changed Throws:
NullPointerException
 if one of the arguments isnull
IllegalArgumentException
 if thelimit
is smaller than zero

rewrite
static <V> int rewrite(TreeNode<V> tree, Iterable<? extends TreeRewriter<V>> rewriters)
Rewrites the giventree
by applying the givenrewriters
. This method to apply the all rewriters, in the order they are given in the sequence, until the tree stays unchanged. Type Parameters:
V
 the tree value type Parameters:
tree
 the tree to rewriterewriters
 the rewriters applied to the tree Returns:
true
if the tree has been changed (rewritten) by this method,false
if the tree hasn't been changed Throws:
NullPointerException
 if one of the arguments isnull
 See Also:
rewrite(TreeNode, int, Iterable)

concat
@SafeVarargs static <V> TreeRewriter<V> concat(TreeRewriter<V>... rewriters)
Concat the givenrewriters
to one treerewriter. Type Parameters:
V
 the tree value type Parameters:
rewriters
 the treerewriter to concatenate Returns:
 a new treerewriter which concatenates the given one
 Throws:
NullPointerException
 if the givenrewriters
arenull
IllegalArgumentException
 if thelimit
is smaller than zero

