Class ByteSequenceIterator

  • All Implemented Interfaces:
    java.util.Iterator<java.nio.ByteBuffer>

    public final class ByteSequenceIterator
    extends java.lang.Object
    implements java.util.Iterator<java.nio.ByteBuffer>
    An iterator that traverses the right language of a given node (all sequences reachable from a given node).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] arcs
      An arc stack for DFS when processing the automaton.
      private byte[] buffer
      A buffer for the current sequence of bytes from the current node to the root.
      private java.nio.ByteBuffer bufferWrapper
      Reusable byte buffer wrapper around buffer.
      private static int EXPECTED_MAX_STATES
      Default expected depth of the recursion stack (estimated longest sequence in the automaton).
      private FSA fsa
      The FSA to which this iterator belongs.
      private java.nio.ByteBuffer nextElement
      An internal cache for the next element in the FSA
      private int position
      Current processing depth in arcs.
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteSequenceIterator​(FSA fsa)
      Create an instance of the iterator iterating over all automaton sequences.
      ByteSequenceIterator​(FSA fsa, int node)
      Create an instance of the iterator for a given node.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.nio.ByteBuffer advance()
      Advances to the next available final state.
      boolean hasNext()
      Returns true if there are still elements in this iterator.
      java.nio.ByteBuffer next()  
      private void pushNode​(int node)
      Descends to a given node, adds its arcs to the stack to be traversed.
      void remove()
      Not implemented in this iterator.
      ByteSequenceIterator restartFrom​(int node)
      Restart walking from node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • EXPECTED_MAX_STATES

        private static final int EXPECTED_MAX_STATES
        Default expected depth of the recursion stack (estimated longest sequence in the automaton). Buffers expand by the same value if exceeded.
        See Also:
        Constant Field Values
      • fsa

        private final FSA fsa
        The FSA to which this iterator belongs.
      • nextElement

        private java.nio.ByteBuffer nextElement
        An internal cache for the next element in the FSA
      • buffer

        private byte[] buffer
        A buffer for the current sequence of bytes from the current node to the root.
      • bufferWrapper

        private java.nio.ByteBuffer bufferWrapper
        Reusable byte buffer wrapper around buffer.
      • arcs

        private int[] arcs
        An arc stack for DFS when processing the automaton.
      • position

        private int position
        Current processing depth in arcs.
    • Constructor Detail

      • ByteSequenceIterator

        public ByteSequenceIterator​(FSA fsa)
        Create an instance of the iterator iterating over all automaton sequences.
        Parameters:
        fsa - The automaton to iterate over.
      • ByteSequenceIterator

        public ByteSequenceIterator​(FSA fsa,
                                    int node)
        Create an instance of the iterator for a given node.
        Parameters:
        fsa - The automaton to iterate over.
        node - The starting node's identifier (can be the FSA.getRootNode()).
    • Method Detail

      • restartFrom

        public ByteSequenceIterator restartFrom​(int node)
        Restart walking from node. Allows iterator reuse.
        Parameters:
        node - Restart the iterator from node.
        Returns:
        Returns this for call chaining.
      • hasNext

        public boolean hasNext()
        Returns true if there are still elements in this iterator.
        Specified by:
        hasNext in interface java.util.Iterator<java.nio.ByteBuffer>
      • next

        public java.nio.ByteBuffer next()
        Specified by:
        next in interface java.util.Iterator<java.nio.ByteBuffer>
        Returns:
        Returns a ByteBuffer with the sequence corresponding to the next final state in the automaton.
      • advance

        private final java.nio.ByteBuffer advance()
        Advances to the next available final state.
      • remove

        public void remove()
        Not implemented in this iterator.
        Specified by:
        remove in interface java.util.Iterator<java.nio.ByteBuffer>
      • pushNode

        private void pushNode​(int node)
        Descends to a given node, adds its arcs to the stack to be traversed.