Class LookaheadTokenFilter<T extends LookaheadTokenFilter.Position>

All Implemented Interfaces:
Closeable, AutoCloseable, Unwrappable<TokenStream>
Direct Known Subclasses:
MockGraphTokenFilter, MockRandomLookaheadTokenFilter

public abstract class LookaheadTokenFilter<T extends LookaheadTokenFilter.Position> extends TokenFilter
An abstract TokenFilter to make it easier to build graph token filters requiring some lookahead. This class handles the details of buffering up tokens, recording them by position, restoring them, providing access to them, etc.
  • Field Details

  • Constructor Details

    • LookaheadTokenFilter

      protected LookaheadTokenFilter(TokenStream input)
  • Method Details

    • insertToken

      protected void insertToken() throws IOException
      Call this only from within afterPosition, to insert a new token. After calling this you should set any necessary token you need.
      Throws:
      IOException
    • afterPosition

      protected void afterPosition() throws IOException
      This is called when all input tokens leaving a given position have been returned. Override this and call insertToken and then set whichever token's attributes you want, if you want to inject a token starting from this position.
      Throws:
      IOException
    • newPosition

      protected abstract T newPosition()
    • peekToken

      protected boolean peekToken() throws IOException
      Returns true if there is a new token.
      Throws:
      IOException
    • nextToken

      protected boolean nextToken() throws IOException
      Call this when you are done looking ahead; it will set the next token to return. Return the boolean back to the caller.
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class TokenFilter
      Throws:
      IOException