public class StringArgumentReader extends Object implements ArgumentReader
ArgumentReader that reads a string| Constructor and Description |
|---|
StringArgumentReader(String arg)
Creates a new
ArgumentReader that reads a string |
| Modifier and Type | Method and Description |
|---|---|
boolean |
atEnd()
Gets whether the reader has reached the last character.
|
char |
get()
Gets the current character this reader is looking at
|
int |
index()
Gets the current index of the reader
|
void |
jumpTo(int index)
Sets the index to something else, "jumping" to that location
|
char |
next()
Advances the reader by 1, returning the current character after advancing
|
@NotNull String |
nextWord()
Returns the next word and places the reader on the space after that word, or the last character in the reader
|
int |
size()
Gets the size of the underlying data
|
@NotNull String |
splice(int beginning)
Performs a splice that gets a string starting at index
beginning and ending at index ArgumentReader.size() |
@NotNull String |
splice(int beginning,
int end)
Performs a splice that gets a string starting at index
beginning and ending at index end |
String |
toString() |
public StringArgumentReader(String arg)
ArgumentReader that reads a stringarg - The string to readpublic char get()
ArgumentReaderget in interface ArgumentReaderpublic char next()
ArgumentReader
char next = reader.next();
char current = reader.get();
assert next == current;
next in interface ArgumentReaderpublic boolean atEnd()
ArgumentReaderArgumentReader.next() will throw an exception.
This is the same as checking if ArgumentReader.index() == ArgumentReader.size() - 1atEnd in interface ArgumentReadertrue if the reader is at the last character, false otherwisepublic int index()
ArgumentReaderindex in interface ArgumentReaderpublic int size()
ArgumentReadersize in interface ArgumentReaderpublic void jumpTo(int index)
ArgumentReaderjumpTo in interface ArgumentReaderindex - The index to set to@NotNull public @NotNull String splice(int beginning)
ArgumentReaderbeginning and ending at index ArgumentReader.size()
// reader has the internal string of "hello there"
String spliced = reader.splice(2);
assert spliced.equals("llo there");
splice in interface ArgumentReaderbeginning - The index to start at@NotNull public @NotNull String splice(int beginning, int end)
ArgumentReaderbeginning and ending at index end
// reader has the internal string of "hello there"
String spliced = reader.splice(2, 8);
assert spliced.equals("llo th");
splice in interface ArgumentReaderbeginning - The index to start atend - The index to end at@NotNull public @NotNull String nextWord()
ArgumentReader
// reader has the internal string of "hello there"
String word = reader.nextWord();
assert word.equals("hello");
assert reader.get() == ' ';
nextWord in interface ArgumentReaderCopyright © 2024. All rights reserved.