Class Substring


  • public class Substring
    extends java.lang.Object
    An substring which also provides access to the full (query) string it is a substring of. This is immutable.
    Author:
    bratseth
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int end
      The end of the substring
      int start
      The start of the substring
      java.lang.String string
      The string this is a substring of
    • Constructor Summary

      Constructors 
      Constructor Description
      Substring​(int start, int end, java.lang.String string)  
      Substring​(java.lang.String string)
      Creates a substring which is identical to the string containing it
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char charAfter​(int n)
      Returns the character n places (0 base) after the end of the value substring into the superstring.
      char charBefore​(int n)
      Returns the character n places (0 base) before the start of the value substring into the superstring.
      java.lang.String getSuperstring()
      Returns the entire string this is a substring of.
      java.lang.String getValue()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • start

        public final int start
        The start of the substring
      • end

        public final int end
        The end of the substring
      • string

        public final java.lang.String string
        The string this is a substring of
    • Constructor Detail

      • Substring

        public Substring​(java.lang.String string)
        Creates a substring which is identical to the string containing it
      • Substring

        public Substring​(int start,
                         int end,
                         java.lang.String string)
    • Method Detail

      • getValue

        public java.lang.String getValue()
      • getSuperstring

        public java.lang.String getSuperstring()
        Returns the entire string this is a substring of. The start and end offsets are into this string.
      • charAfter

        public char charAfter​(int n)
        Returns the character n places (0 base) after the end of the value substring into the superstring. For example charAfter(0) returns the first character after the end of the substring
        Returns:
        the char n planes after the end of the substring
        Throws:
        java.lang.IndexOutOfBoundsException - if the string is not long enough to have a character at this position
      • charBefore

        public char charBefore​(int n)
        Returns the character n places (0 base) before the start of the value substring into the superstring. For example charBefore(0) returns the first character before the start of the substring
        Returns:
        the char n planes before the start of the substring
        Throws:
        java.lang.IndexOutOfBoundsException - if the string does not have a character at this position
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object