Class CharacterIterator


  • final class CharacterIterator
    extends java.lang.Object
    Iterator which iterates through the input string and returns characters from that string.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int pos  
      private java.lang.String s  
    • Constructor Summary

      Constructors 
      Constructor Description
      CharacterIterator​(java.lang.String s)
      Creates a new iterator initialized with the given input string.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char current()
      Returns character at the current position.
      java.lang.String getInput()
      Returns the input String on which this iterator operates.
      boolean hasNext()
      Determines whether there is next character in the iteration chain.
      char next()
      Returns next character in the iteration chain and increase the current position.
      char peek()
      Returns the next character without increasing the position.
      int pos()
      Returns the current internal position of the iterator.
      void setPosition​(int newPosition)
      Changes the current position to the position.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • pos

        private int pos
      • s

        private java.lang.String s
    • Constructor Detail

      • CharacterIterator

        public CharacterIterator​(java.lang.String s)
        Creates a new iterator initialized with the given input string.
        Parameters:
        s - String trough which the iterator iterates.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Determines whether there is next character in the iteration chain.
        Returns:
        True if there is a character which can be retrieved by next(), false otherwise.
      • next

        public char next()
        Returns next character in the iteration chain and increase the current position.
        Returns:
        Next character.
        Throws:
        java.lang.RuntimeException - The method might throw exception when there is no more character to be retrieved.
      • peek

        public char peek()
        Returns the next character without increasing the position. The method does the same as next() but the position is not changed by calling this method.
        Returns:
        Next character.
      • pos

        public int pos()
        Returns the current internal position of the iterator.
        Returns:
        current position of the iterator
      • getInput

        public java.lang.String getInput()
        Returns the input String on which this iterator operates.
        Returns:
        String which initialized this iterator.
      • setPosition

        public void setPosition​(int newPosition)
        Changes the current position to the position.
        Parameters:
        newPosition - New position for the iterator.
      • current

        public char current()
        Returns character at the current position.
        Returns:
        Character from current position.