Class StringWithPosition


  • class StringWithPosition
    extends java.lang.Object
    A helper class for string comparisons.
    Author:
    Holger Eichelberger
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int pos  
      private char[] string  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringWithPosition​(java.lang.String string)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char at()
      Returns the character at the actual position.
      char at​(int inc)
      Returns the character at the actual position including the increment inc.
      void consumeLine()
      Consumes the line including the line end starting at the current position.
      void consumeLineEnd()
      Consumes the line end starting at the current position.
      void consumeLineUntilEnd()
      Consumes the line until the line end starting at the current position.
      void inc()
      Increments the actual position by 1.
      void inc​(int inc)
      Increments the actual position by inc.
      boolean inRange()
      Returns whether the actual position is in range.
      boolean inRange​(int inc)
      Returns whether the actual position including the increment inc is in range.
      private boolean isLineEnd()
      Returns whether the actual character is a line end character.
      int pos()
      Returns the actual position.
      • Methods inherited from class java.lang.Object

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

      • string

        private char[] string
      • pos

        private int pos
    • Constructor Detail

      • StringWithPosition

        public StringWithPosition​(java.lang.String string)
        Creates a new instance.
        Parameters:
        string - the string to be stored
    • Method Detail

      • pos

        public int pos()
        Returns the actual position.
        Returns:
        the actual position
      • at

        public char at()
        Returns the character at the actual position.
        Returns:
        the character at the actual position
        Throws:
        java.lang.IndexOutOfBoundsException - in case that the position is invalid
      • inRange

        public boolean inRange()
        Returns whether the actual position is in range.
        Returns:
        true if the actual position is in range, false else
      • inc

        public void inc()
        Increments the actual position by 1.
      • inc

        public void inc​(int inc)
        Increments the actual position by inc.
        Parameters:
        inc - the increment
      • inRange

        public boolean inRange​(int inc)
        Returns whether the actual position including the increment inc is in range.
        Parameters:
        inc - the increment
        Returns:
        true if the specified position is in range, false else
      • at

        public char at​(int inc)
        Returns the character at the actual position including the increment inc.
        Parameters:
        inc - the increment
        Returns:
        the character at the actual position
        Throws:
        java.lang.IndexOutOfBoundsException - in case that the specified position is invalid
      • consumeLineEnd

        public void consumeLineEnd()
        Consumes the line end starting at the current position.
      • consumeLineUntilEnd

        public void consumeLineUntilEnd()
        Consumes the line until the line end starting at the current position.
      • consumeLine

        public void consumeLine()
        Consumes the line including the line end starting at the current position.
      • isLineEnd

        private boolean isLineEnd()
        Returns whether the actual character is a line end character.
        Returns:
        true if it is a line end character, false else