ilog.rules.brl.syntaxtree

Class IlrSyntaxTree.Iterator

  • java.lang.Object
    • ilog.rules.brl.syntaxtree.IlrSyntaxTree.Iterator
  • All Implemented Interfaces:
    java.util.Iterator
    Enclosing class:
    IlrSyntaxTree


    public static class IlrSyntaxTree.Iterator
    extends java.lang.Object
    implements java.util.Iterator
    An iterator which iterates over the nodes of a syntax tree. This iterator should be given a start node, where the iteration starts, and a direction, which defines the behavior of the iterator. A test can be specified with a IlrSyntaxTree.NodeTester object given as an argument in the constructor. The iterator skips every node that fails the test.

    Depending on the value of the direction parameter, the iterator does the following:

    • IlrSyntaxTree.DOWN: It iterates over the subnodes of the start node, in a depth-first manner. The iterator starts at the start node, then goes down its subnodes until if finds one that matches the tester. If none is found when it reaches a leaf node, it then goes up again and continues with the next sibling of this leaf node.
    • IlrSyntaxTree.UP: It iterates over the supernodes of the start node until the tree root node is reached.
    • IlrSyntaxTree.LEFT: It iterates over the preceding siblings of the start node, until it reaches the very first sibling node.
    • IlrSyntaxTree.RIGHT: It iterates over the next siblings of the start node, until it reaches the very last sibling node.
    • IlrSyntaxTree.SUBNODES: It iterates over the subnodes of the start node, and does not go deeper.

    The root node and its subnodes should not be modified while the iterator is in use.

    Since:
    JRules 4.0
    • Constructor Detail

      • IlrSyntaxTree.Iterator

        public IlrSyntaxTree.Iterator(IlrSyntaxTree syntaxTree)
        Constructs an instance of Iterator. This iterator iterates over all the nodes of syntaxTree in a depth-first manner.
        Parameters:
        syntaxTree - The syntax tree to iterate on.
      • IlrSyntaxTree.Iterator

        public IlrSyntaxTree.Iterator(IlrSyntaxTree.Node root)
        Constructs an instance of Iterator. This iterator iterates over all the subnodes of node in a depth-first manner.
        Parameters:
        root - The root node of the syntax tree.
      • IlrSyntaxTree.Iterator

        public IlrSyntaxTree.Iterator(IlrSyntaxTree.Node root,
                              IlrSyntaxTree.NodeTester tester)
        Constructs an instance of Iterator. This iterator iterates over all the subnodes of node in a depth-first manner. The tester is applied when looking for the next node.

        This iterator returns only nodes which satisfy the tester.

        Parameters:
        root - The root node of the syntax tree.
        tester - The filter for the iteration. Only those nodes that satisfy the test are included in the iteration.
      • IlrSyntaxTree.Iterator

        public IlrSyntaxTree.Iterator(IlrSyntaxTree.Node root,
                              IlrSyntaxTree.NodeTester tester,
                              int direction)
        Constructs an instance of Iterator, using the specified node as the root node. This iterator iterates over the syntax tree, starting from root, in the specified direction. The tester will be applied when looking for the next node.

        This iterator only returns nodes which satisfy the tester.

        The direction must be one of the following :IlrSyntaxTree.UP, IlrSyntaxTree.DOWN,IlrSyntaxTree.LEFT,IlrSyntaxTree.RIGHT,IlrSyntaxTree.SUBNODES.

        Since:
        JRules 4.5
        Parameters:
        root - The root node of the syntax tree.
        tester - The filter for the iteration. Only those nodes that satisfy the test are included in the iteration.
        direction - The direction the iterator takes when it navigates the syntax tree.
    • Method Detail

      • hasNextNode

        public boolean hasNextNode()
        Checks if there is a next node.
        Returns:
        true if there is a next node, false otherwise.
      • nextNode

        public IlrSyntaxTree.Node nextNode()
        Gets the next node which satisfies the test.
        Returns:
        The next node that satisfies the test, null if there is none.
      • hasNext

        public boolean hasNext()
        Checks if there is a next node.
        Specified by:
        hasNext in interface java.util.Iterator
        Returns:
        true if there is a next node, false otherwise.
      • next

        public java.lang.Object next()
        Gets the next node which satisfies the test.
        Specified by:
        next in interface java.util.Iterator
        Returns:
        The next node that satisfies the test, null if there is none.
      • remove

        public void remove()
        The remove() method is not implemented. The node tree should not be modified while this iterator is in use.
        Specified by:
        remove in interface java.util.Iterator
        Throws:
        java.lang.UnsupportedOperationException

© Copyright IBM Corp. 1987, 2017