Class AbstractInput

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected IntDeque deque
      Contains the peeked characters that haven't been read (by the read methods) yet.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractInput()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected CharsWrapper consumeDeque​(char[] array, int offset, boolean mustReadAll)
      Consumes the chars of the deque and put them in an array.
      protected abstract int directRead()
      Tries to parse the next character without taking care of the peek deque.
      protected abstract char directReadChar()
      Tries to parse the next character without taking care of the peek deque.
      int peek()
      Returns the next character, without moving the reading position forward.
      int peek​(int n)
      Returns the next (n+1)th character, without moving the reading position forward.
      char peekChar()
      Returns the next character, without moving the reading position forward.
      char peekChar​(int n)
      Returns the next (n+1)th character, without moving the reading position forward.
      void pushBack​(char c)
      Pushes a character back to the input, so that it will be returned by the next reading operation.
      int read()
      Reads the next character.
      char readChar()
      Reads the next character, throwing an exception if there is no more available data.
      CharsWrapper readCharsUntil​(char[] stop)
      Reads all the characters until a character contained in stop is reached, and returns the CharsWrapper that contains all the characters before the stop.
      CharsWrapper readUntil​(char[] stop)
      Reads all the character until a character containde in stop is reached or there is no more available data, and returns the CharsWrapper that contains all the characters before the stop (or the end of the data).
      void skipPeeks()
      Skips all the character that have been peeked and not parsed yet.
      • Methods inherited from class java.lang.Object

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

      • deque

        protected final IntDeque deque
        Contains the peeked characters that haven't been read (by the read methods) yet.
    • Constructor Detail

      • AbstractInput

        public AbstractInput()
    • Method Detail

      • directRead

        protected abstract int directRead()
        Tries to parse the next character without taking care of the peek deque.
        Returns:
        the next character, or -1 if the EOS has been reached
      • directReadChar

        protected abstract char directReadChar()
        Tries to parse the next character without taking care of the peek deque.
        Returns:
        the next character
        Throws:
        ParsingException - if the EOS has been reached
      • read

        public int read()
        Description copied from interface: CharacterInput
        Reads the next character.
        Specified by:
        read in interface CharacterInput
        Returns:
        the next char, or -1 if there is no more available data
      • readChar

        public char readChar()
        Description copied from interface: CharacterInput
        Reads the next character, throwing an exception if there is no more available data.
        Specified by:
        readChar in interface CharacterInput
        Returns:
        the next character
      • peek

        public int peek()
        Description copied from interface: CharacterInput
        Returns the next character, without moving the reading position forward. After a call to peek(), the method CharacterInput.read() will return the exact same character.

        This method behaves exactly like peek(0)

        Specified by:
        peek in interface CharacterInput
        Returns:
        the next character, or -1 if there is no more available data
      • peek

        public int peek​(int n)
        Description copied from interface: CharacterInput
        Returns the next (n+1)th character, without moving the reading position forward. The next character is n=0, then it's n=1 and so on.
        Specified by:
        peek in interface CharacterInput
        Parameters:
        n - the position to peek
        Returns:
        the next (n+1)th character
      • peekChar

        public char peekChar()
        Description copied from interface: CharacterInput
        Returns the next character, without moving the reading position forward. After a call to peek(), the method CharacterInput.read() will return the exact same character.

        This method behaves exactly like peekChar(0)

        This method throws an exception if there is no more available data.

        Specified by:
        peekChar in interface CharacterInput
        Returns:
        the next character
      • peekChar

        public char peekChar​(int n)
        Description copied from interface: CharacterInput
        Returns the next (n+1)th character, without moving the reading position forward. The next character is n=0, then it's n=1 and so on.

        This method throws an exception if there is no more available data.

        Specified by:
        peekChar in interface CharacterInput
        Parameters:
        n - the position to peek
        Returns:
        the next (n+1)th character
      • skipPeeks

        public void skipPeeks()
        Description copied from interface: CharacterInput
        Skips all the character that have been peeked and not parsed yet.
        Specified by:
        skipPeeks in interface CharacterInput
      • pushBack

        public void pushBack​(char c)
        Description copied from interface: CharacterInput
        Pushes a character back to the input, so that it will be returned by the next reading operation.
        Specified by:
        pushBack in interface CharacterInput
        Parameters:
        c - the character to push back
      • readUntil

        public CharsWrapper readUntil​(char[] stop)
        Description copied from interface: CharacterInput
        Reads all the character until a character containde in stop is reached or there is no more available data, and returns the CharsWrapper that contains all the characters before the stop (or the end of the data).
        Specified by:
        readUntil in interface CharacterInput
        Parameters:
        stop - the characters to stop at
        Returns:
        a CharsWrapper that contains all the characters parse before the stop (or the end of the data), not null
      • readCharsUntil

        public CharsWrapper readCharsUntil​(char[] stop)
        Description copied from interface: CharacterInput
        Reads all the characters until a character contained in stop is reached, and returns the CharsWrapper that contains all the characters before the stop.
        Specified by:
        readCharsUntil in interface CharacterInput
        Parameters:
        stop - the characters to stop at
        Returns:
        a CharsWrapper that contains all the characters parse before the stop
      • consumeDeque

        protected CharsWrapper consumeDeque​(char[] array,
                                            int offset,
                                            boolean mustReadAll)
        Consumes the chars of the deque and put them in an array.
        Parameters:
        array - the destination array
        offset - the beginning index in the array
        mustReadAll - true to throw an exception if the array can't be fulled, false to return a CharsWrapper containing the read characters.
        Returns:
        a CharsWrapper containing the read characters if the array can't be fulled, or null