Class Tokens.TokenIterator

  • All Implemented Interfaces:
    java.util.Iterator<java.lang.String>
    Enclosing class:
    Tokens

    static final class Tokens.TokenIterator
    extends java.lang.Object
    implements java.util.Iterator<java.lang.String>
    Iterator that lazily splits a string into tokens.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private char separator  
      private java.lang.String text  
      private int tokenIndex  
      private boolean trimming  
    • Constructor Summary

      Constructors 
      Constructor Description
      TokenIterator​(java.lang.String text, char separator, boolean trimming)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()  
      java.lang.String next()  
      private int nextSeparator​(int from)
      Finds the position of the next separator that follows the current token.
      private int nextToken​(int from)
      Finds the start of the next token, i.e.
      void remove()  
      private int trimBack​(int from)
      Backtracks to find the non-whitespace end of the current token.
      • 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

      • text

        private final java.lang.String text
      • separator

        private final char separator
      • trimming

        private final boolean trimming
      • tokenIndex

        private int tokenIndex
    • Constructor Detail

      • TokenIterator

        TokenIterator​(java.lang.String text,
                      char separator,
                      boolean trimming)
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<java.lang.String>
      • next

        public java.lang.String next()
        Specified by:
        next in interface java.util.Iterator<java.lang.String>
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<java.lang.String>
      • nextToken

        private int nextToken​(int from)
        Finds the start of the next token, i.e. not the separator or whitespace when trimming.
      • nextSeparator

        private int nextSeparator​(int from)
        Finds the position of the next separator that follows the current token.
      • trimBack

        private int trimBack​(int from)
        Backtracks to find the non-whitespace end of the current token.