Interface TreeRewriter<V>

All Known Implementing Classes:
ConstRewriter, 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.

Interface for rewriting a given tree. The rewrite is performed on a mutable TreeNode and is done in place.

Description from Wikipedia: In mathematics, computer science, and logic, rewriting covers a wide range of (potentially non-deterministic) methods of replacing sub-terms 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 non-deterministic. 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

    Modifier and Type
    Method
    Description
    static <V> TreeRewriter<V>
    concat(TreeRewriter<V>... rewriters)
    Concat the given rewriters to one tree-rewriter.
    default int
    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 given tree by applying the given rewriters.
    static <V> int
    rewrite(TreeNode<V> tree, Iterable<? extends TreeRewriter<V>> rewriters)
    Rewrites the given tree by applying the given rewriters.
  • Method Details

    • rewrite

      int rewrite(TreeNode<V> tree, int limit)
      Applies the rewriting to the given (mutable) tree. The tree rewrite is done in place. Via the limit parameter, the termination of the tree-rewrite process can be guaranteed.
      Parameters:
      tree - the tree to be rewritten
      limit - 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 given tree is null
      IllegalArgumentException - if the limit 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 given tree is null
      See Also:
    • rewrite

      static <V> int rewrite(TreeNode<V> tree, int limit, Iterable<? extends TreeRewriter<V>> rewriters)
      Rewrites the given tree by applying the given rewriters. This method to apply 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 rewrite
      limit - 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 is null
      IllegalArgumentException - if the limit is smaller than zero
    • rewrite

      static <V> int rewrite(TreeNode<V> tree, Iterable<? extends TreeRewriter<V>> rewriters)
      Rewrites the given tree by applying the given rewriters. This method to apply 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 rewrite
      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 is null
      See Also:
    • concat

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