Package net.mtrop.doom.text
Class Text
java.lang.Object
net.mtrop.doom.text.Text
- All Implemented Interfaces:
CharSequence
,TextObject
A generic text object.
Contains only a StringBuilder that can be written to or read from.
- Since:
- 2.19.0
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.mtrop.doom.object.TextObject
TextObject.ParseException, TextObject.Reflect, TextObject.Transformer<TO extends TextObject>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) <TO extends TextObject>
TOReturns a new object, where the contents of this Text is read as a different TextObject-implementing object.getMatcherForPattern
(Pattern regex) Returns a Matcher for a given RegEx pattern.int
Returns the index of the first occurrence of the provided string.int
Returns the index of the first occurrence of the provided string, starting from a provided index.int
lastIndexOf
(String str) Returns the index of the last occurrence of the provided string.int
lastIndexOf
(String str, int fromIndex) Returns the index of the last occurrence of the provided string, starting from a provided index, searching backwards.int
length()
void
Reads from anReader
and sets this object's fields.subSequence
(int start, int end) toString()
void
Writes this object to aWriter
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
Text
public Text()Creates a new Text object.
-
-
Method Details
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAt
in interfaceCharSequence
-
indexOf
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
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
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
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
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
- Specified by:
subSequence
in interfaceCharSequence
-
getBuilder
- Returns:
- a reference to the underlying StringBuilder.
-
create
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
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
readText
Description copied from interface:TextObject
Reads from anReader
and sets this object's fields.- Specified by:
readText
in interfaceTextObject
- Parameters:
reader
- theReader
to read from.- Throws:
IOException
- if a read error occurs.
-
writeText
Description copied from interface:TextObject
Writes this object to aWriter
.- Specified by:
writeText
in interfaceTextObject
- Parameters:
writer
- theWriter
to write to.- Throws:
IOException
- if a write error occurs.
-