Class Text

java.lang.Object
net.mtrop.doom.text.Text
All Implemented Interfaces:
CharSequence, TextObject

public class Text extends Object implements TextObject, CharSequence
A generic text object. Contains only a StringBuilder that can be written to or read from.
Since:
2.19.0
Author:
Matthew Tropiano
  • Constructor Details

    • Text

      public Text()
      Creates a new Text object.
  • Method Details

    • length

      public int length()
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int index)
      Specified by:
      charAt in interface CharSequence
    • indexOf

      public int indexOf(String str)
      Returns the index of the first occurrence of the provided string.
      Parameters:
      str - the string to search for.
      Returns:
      the index or -1 if not found.
    • indexOf

      public int indexOf(String str, int fromIndex)
      Returns the index of the first occurrence of the provided string, starting from a provided index.
      Parameters:
      str - the string to search for.
      fromIndex - the index to start searching from.
      Returns:
      the index or -1 if not found.
    • lastIndexOf

      public int lastIndexOf(String str)
      Returns the index of the last occurrence of the provided string.
      Parameters:
      str - the string to search for.
      Returns:
      the index or -1 if not found.
    • lastIndexOf

      public int lastIndexOf(String str, int fromIndex)
      Returns the index of the last occurrence of the provided string, starting from a provided index, searching backwards.
      Parameters:
      str - the string to search for.
      fromIndex - the index to start searching from.
      Returns:
      the index or -1 if not found.
    • getMatcherForPattern

      public Matcher getMatcherForPattern(Pattern regex)
      Returns a Matcher for a given RegEx pattern.
      Parameters:
      regex - the RegEx pattern to get a matcher for.
      Returns:
      the matcher for this Text.
    • subSequence

      public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • getBuilder

      public StringBuilder getBuilder()
      Returns:
      a reference to the underlying StringBuilder.
    • create

      public <TO extends TextObject> TO create(Class<TO> toClass) throws IOException
      Returns a new object, where the contents of this Text is read as a different TextObject-implementing object.
      Type Parameters:
      TO - the TextObject subtype.
      Parameters:
      toClass - the class to create.
      Returns:
      the new object.
      Throws:
      IOException - if an error occurs during the read - most commonly a ParseException.
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • readText

      public void readText(Reader reader) throws IOException
      Description copied from interface: TextObject
      Reads from an Reader and sets this object's fields.
      Specified by:
      readText in interface TextObject
      Parameters:
      reader - the Reader to read from.
      Throws:
      IOException - if a read error occurs.
    • writeText

      public void writeText(Writer writer) throws IOException
      Description copied from interface: TextObject
      Writes this object to a Writer.
      Specified by:
      writeText in interface TextObject
      Parameters:
      writer - the Writer to write to.
      Throws:
      IOException - if a write error occurs.