Interface ArgumentReader
-
- All Known Subinterfaces:
ArgumentReader.Immutable
,ArgumentReader.Mutable
public interface ArgumentReader
AnArgumentReader
allows for sequential reading of an inputString
, by providing a "cursor" that advances when part of theString
is read.The base
ArgumentReader
interface (this) only contains methods that get the state of the reader. The sub-interfaces,ArgumentReader.Immutable
andArgumentReader.Mutable
indicate whether the reader is indicating state or is an active reader.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ArgumentReader.Immutable
Represents aArgumentReader
where the cursor position cannot be changed.static interface
ArgumentReader.Mutable
Represents aArgumentReader
where the cursor may move.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
canRead()
Gets whether this reader has not finished reading the input string.ArgumentParseException
createException(Component errorMessage)
Creates anArgumentParseException
with the provided message, based on the current state of this object.int
cursor()
Gets the location of the cursor.String
input()
Gets the argument string that is being read by this reader.String
parsed()
Gets the substring that has already been parsed.char
peekCharacter()
Gets the character after the cursor ifcanRead()
is true.String
remaining()
Gets the substring that has yet to be read.int
remainingLength()
Get the number of characters that have not yet been read.int
totalLength()
Gets the length of the input string.
-
-
-
Method Detail
-
input
String input()
Gets the argument string that is being read by this reader.- Returns:
- The input
String
-
remainingLength
int remainingLength()
Get the number of characters that have not yet been read.- Returns:
- The length of the remaining string
-
totalLength
int totalLength()
Gets the length of the input string.- Returns:
- The length of the input string
-
cursor
int cursor()
Gets the location of the cursor.If zero, the cursor has not yet read a character. If equal to
totalLength()
, this cursor is at the end of the string, andcanRead()
will befalse
- Returns:
- The location of the cursor
-
parsed
String parsed()
Gets the substring that has already been parsed.- Returns:
- The substring that has been parsed.
-
remaining
String remaining()
Gets the substring that has yet to be read.- Returns:
- The substring that has yet to be read.
-
canRead
boolean canRead()
Gets whether this reader has not finished reading the input string.This is equivalent to
remainingLength()
> 0- Returns:
true
if there are further characters to read.
-
peekCharacter
char peekCharacter()
Gets the character after the cursor ifcanRead()
is true.- Returns:
- The next character
- Throws:
IllegalStateException
- ifcanRead()
is false
-
createException
ArgumentParseException createException(Component errorMessage)
Creates anArgumentParseException
with the provided message, based on the current state of this object.Note that the exception will not be thrown. It is up to the caller of this method to throw the exception.
- Parameters:
errorMessage
- The error message to display- Returns:
- The exception
-
-