Class TokenIterator

  • All Implemented Interfaces:
    java.util.Iterator<Token>

    public final class TokenIterator
    extends TokenSink
    implements java.util.Iterator<Token>
    Iterator that will iterate over all tokens in list
    • Constructor Detail

      • TokenIterator

        protected TokenIterator​(TokenList tokens)
        Constructor
    • Method Detail

      • hasNext

        public boolean hasNext()
        true if a next element exists
        Specified by:
        hasNext in interface java.util.Iterator<Token>
      • next

        public Token next()
        Moves the iterator to the next Token in the TokenList and returns that token.
        Specified by:
        next in interface java.util.Iterator<Token>
      • getNext

        public Token getNext()
        Gets the next Token, without advancing the pointer.
      • getNextPositionIncrement

        public int getNextPositionIncrement()
        Returns the position increment for the next Token
      • getPositionIncrement

        public int getPositionIncrement()
        Returns the position increment for the current Token
        Returns:
        the position increment for the current Token
      • setPositionIncrement

        public void setPositionIncrement​(int increment)
        Sets the position increment for the current Token
      • set

        public void set​(java.lang.String t)
        Replaces the current Token with a new Token
        Parameters:
        t - The string value for the new Token to replace the current Token
      • set

        public void set​(Token t)
        Replaces the current Token with a new Token
        Parameters:
        t - The Token to replace the current Token with
      • add

        public void add​(Token t,
                        int increment)
        Appends a token.
        Specified by:
        add in class TokenSink
        Parameters:
        t - The Token to add
        increment - The position increment for the newly added token
      • remove

        public void remove()
        Removes the current Token from the TokenList
        Specified by:
        remove in interface java.util.Iterator<Token>
      • getState

        public TokenIterator.State getState()
        Experimental: Get the current state of iteration.

        NOTE: it is recommended that you create a minimal number of saved states. States can be reused by calling saveState(State) to save the current state of iteration to an existing TokenIterator.State instance.

      • saveState

        public void saveState​(TokenIterator.State state)
        Experimental: save the current state of iteration to state.
      • restoreState

        public void restoreState​(TokenIterator.State state)
        Experimental: restore the state of iteration from state.