Documentation of 'cc.redberry.core.tensor.iterator.TreeTraverseIterator' Java class
TreeTraverseIterator
cc.redberry.core.tensor.iterator

Class TreeTraverseIterator<T extends Payload<T>>



  • public final class TreeTraverseIterator<T extends Payload<T>>
    extends java.lang.Object
    An iterator for tensors that allows the programmer to traverse the tensor tree structure, modify the tensor during iteration, and obtain information about iterator current position in the tensor. A TensorTreeIterator has current element, so all methods are defined in terms of the cursor position. *

    Example:

          Tensor tensor = Tensors.parse("Cos[a+b+Sin[x]]");
          TensorIterator iterator = new TreeTraverseIterator(tensor);
          TraverseState state;
          while ((state = iterator.next()) != null)
               System.out.println(state + " " + iterator.depth() + " " + iterator.current());
     
    This code will print:
        Entering   Cos[a+b+Sin[y*c+x]]
        Entering   a+b+Sin[y*c+x]
        Entering   a
        Leaving   a
        Entering   b
        Leaving   b
        Entering   Sin[y*c+x]
        Entering   y*c+x
        Entering   y*c
        Entering   y
        Leaving   y
        Entering   c
        Leaving   c
        Leaving   y*c
        Entering   x
        Leaving   x
        Leaving   y*c+x
        Leaving   Sin[y*c+x]
        Leaving   a+b+Sin[y*c+x]
        Leaving   Cos[a+b+Sin[y*c+x]]
     

    Since:
    1.0
    • Method Detail

      • next

        public TraverseState next()
        Moves iterator to the next state.
        Returns:
        next traverse state or null if there is no next element
      • set

        public void set(Tensor tensor)
        Replaces the current cursor with the specified element.
        Parameters:
        tensor - the element with which to replace the current cursor
      • depth

        public int depth()
        Returns depth in the tree, relatively to the current cursor position. Note that depth is counted from zero (e.g. zero will be returned after first next()). If next() never called or last next() was null , this method returns -1.
        Returns:
        depth in the tree relatively to the current cursor position
      • isUnder

        public boolean isUnder(Indicator<Tensor> indicator,
                               int searchDepth)
      • checkLevel

        public boolean checkLevel(Indicator<Tensor> indicator,
                                  int level)
        Checks specified condition at position specified by relative level to current cursor.
        Parameters:
        indicator - level relative position of element to be tested
        Returns:
        true if condition satisfies at specified level
      • current

        public Tensor current()
        Returns current cursor.
        Returns:
        current cursor.
      • result

        public Tensor result()
        Return the resulting tensor.
        Returns:
        the resulting tensor

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.