Package org.incendo.cloud.context
Interface CommandInput
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionappendString(@NonNull String string) Suffixes theinputwith the givenstringand return a new command input containing the updated string.copy()Returns a copy of this instance.@org.checkerframework.checker.index.qual.NonNegative intcursor()Returns the cursor position.cursor(@org.checkerframework.checker.index.qual.NonNegative int position) Sets the cursor positiondifference(@NonNull CommandInput that) Returns the input that has been consumed bythatinput that has not been consumed byinput.difference(@NonNull CommandInput that, boolean includeTrailingWhitespace) Returns the input that has been consumed bythatinput that has not been consumed byinput.static @NonNull CommandInputempty()Returns a newCommandInputwith an empty string as the input.default booleanReturns whether theremaining inputcontains any non-whitespace characters.default booleanReturns whether there is anyremaining inputleft to read.default booleanhasRemainingInput(boolean ignoreWhitespace) Returns whether there is anything left to read.input()Returns the complete input string.default booleanisEmpty()Returns whether there is nothing left to read.default booleanisEmpty(boolean ignoreWhitespace) Returns whether there is nothing left to read.default booleanisValidBoolean(boolean liberal) Returns whetherpeekString()contain a validBooleanwithin the given range.default booleanisValidByte(byte min, byte max) Returns whetherpeekString()contain a validBytewithin the given range.default booleanisValidByte(@NonNull ByteRange range) Returns whetherpeekString()contain a validBytewithin the given range.default booleanisValidDouble(double min, double max) Returns whetherpeekString()contain a validDoublewithin the given range.default booleanisValidDouble(@NonNull DoubleRange range) Returns whetherpeekString()contain a validDoublewithin the given range.default booleanisValidFloat(float min, float max) Returns whetherpeekString()contain a validFloatwithin the given range.default booleanisValidFloat(@NonNull FloatRange range) Returns whetherpeekString()contain a validFloatwithin the given range.default booleanisValidInteger(int min, int max) Returns whetherpeekString()contain a validIntegerwithin the given range.default booleanisValidInteger(@NonNull IntRange range) Returns whetherpeekString()contain a validIntegerwithin the given range.default booleanisValidLong(long min, long max) Returns whetherpeekString()contain a validLongwithin the given range.default booleanisValidLong(@NonNull LongRange range) Returns whetherpeekString()contain a validLongwithin the given range.default booleanisValidShort(short min, short max) Returns whetherpeekString()contain a validShortwithin the given range.default booleanisValidShort(@NonNull ShortRange range) Returns whetherpeekString()contain a validShortwithin the given range.default charReturns the last remaining character.Returns the last remaining token.default @org.checkerframework.checker.index.qual.NonNegative intlength()Returns the length of the input string.voidmoveCursor(int chars) Moves the cursorcharspositions.static @NonNull CommandInputReturns a newCommandInputinstance from the giveninput.static @NonNull CommandInputReturns a newCommandInputinstance from the giveninput.default charpeek()Reads the character at the cursor without moving the cursor.Peeksuntil the next whitespace is encountered, skipping leading whitespace.peekString(@org.checkerframework.checker.index.qual.NonNegative int chars) Readscharscharacters of theremaining inputwithout moving the cursor.default charread()Reads the character at the cursor and move the cursor one character.read(@org.checkerframework.checker.index.qual.NonNegative int chars) default booleanReads thestring until the next whitespaceand parses in into aBoolean.default bytereadByte()Reads thestring until the next whitespaceand parses in into aByte.default doubleReads thestring until the next whitespaceand parses in into aDouble.default floatReads thestring until the next whitespaceand parses in into aFloat.Returns the read input.default intReads thestring until the next whitespaceand parses in into aInteger.default intreadInteger(int radix) Reads thestring until the next whitespaceand parses in into aInteger.default longreadLong()Reads thestring until the next whitespaceand parses in into aLong.default shortReads thestring until the next whitespaceand parses in into aShort.Skips initial whitespace andreadsuntil the next whitespace is encountered.Readsuntil the next whitespace is encountered.readStringSkipWhitespace(boolean preserveSingleSpace) Readsuntil the next whitespace is encountered.readUntil(char separator) Reads until theseparator, and then preserves it.readUntilAndSkip(char separator) Reads until theseparator, and then skips the separator.Returns the remaining input.default @org.checkerframework.checker.index.qual.NonNegative intReturns the length of the remaining input.default @org.checkerframework.checker.index.qual.NonNegative intReturns the number of remaining tokens.default @NonNull CommandInputSkips any whitespace characters at the head of the input.default @NonNull CommandInputskipWhitespace(boolean preserveSingleSpace) Skips any whitespace characters at the head of the input.default @NonNull CommandInputskipWhitespace(int maxSpaces) SkipsmaxSpacesof whitespace characters at the head of the input.default @NonNull CommandInputskipWhitespace(int maxSpaces, boolean preserveSingleSpace) SkipsmaxSpacesof whitespace characters at the head of the input.
-
Field Details
-
BOOLEAN_STRICT
-
BOOLEAN_LIBERAL
-
BOOLEAN_LIBERAL_TRUE
-
-
Method Details
-
of
Returns a newCommandInputinstance from the giveninput.- Parameters:
input- the input string- Returns:
- the command input instance
-
of
Returns a newCommandInputinstance from the giveninput.- Parameters:
input- the input string- Returns:
- the command input instance
-
empty
Returns a newCommandInputwith an empty string as the input.- Returns:
- the command input instance
-
input
Returns the complete input string.- Returns:
- the complete input
-
cursor
Returns the cursor position.This must always be non-negative, and less than
length().- Returns:
- the cursor position
-
length
Returns the length of the input string.This should always be equal to the length of
input().- Returns:
- the length of the input string
-
remainingLength
Returns the length of the remaining input.- Returns:
- the length of the remaining input.
-
remainingTokens
Returns the number of remaining tokens.- Returns:
- the number of remaining tokens
-
remainingInput
Returns the remaining input.- Returns:
- the remaining input.
-
readInput
Returns the read input.- Returns:
- the read input
-
appendString
Suffixes theinputwith the givenstringand return a new command input containing the updated string.This does not modify
thisinstance.- Parameters:
string- the string- Returns:
- the command input with the appended string
-
hasRemainingInput
Returns whether there is anyremaining inputleft to read.- Returns:
- whether there is any remaining input
-
isEmpty
Returns whether there is nothing left to read. This does not ignore whitespace.- Returns:
- whether there is nothing left to read.
-
isEmpty
Returns whether there is nothing left to read.- Parameters:
ignoreWhitespace- whether to ignore whitespace- Returns:
- whether there is nothing left to read.
-
hasRemainingInput
Returns whether there is anything left to read.- Parameters:
ignoreWhitespace- whether to ignore whitespace- Returns:
- whether there is anything left to read.
-
moveCursor
void moveCursor(int chars) Moves the cursorcharspositions.- Parameters:
chars- the number of characters to move the cursor- Throws:
CommandInput.CursorOutOfBoundsException- IfcharsexceedsremainingLength()
-
cursor
Sets the cursor position- Parameters:
position- the new position- Returns:
this
-
peekString
@SideEffectFree default @NonNull String peekString(@org.checkerframework.checker.index.qual.NonNegative int chars) Readscharscharacters of theremaining inputwithout moving the cursor.- Parameters:
chars- the number of characters to read- Returns:
- the read characters
- Throws:
CommandInput.CursorOutOfBoundsException- IfcharsexceedsremainingLength()
-
read
- Parameters:
chars- the number of characters to read- Returns:
- the read characters
- Throws:
CommandInput.CursorOutOfBoundsException- IfcharsexceedsremainingLength()
-
peek
Reads the character at the cursor without moving the cursor.- Returns:
- the character at the cursor.
- Throws:
CommandInput.CursorOutOfBoundsException- If the cursor has exceeded the input
-
read
default char read()Reads the character at the cursor and move the cursor one character.- Returns:
- the character at the cursor.
-
peekString
Peeksuntil the next whitespace is encountered, skipping leading whitespace.- Returns:
- the peeked string
-
readStringSkipWhitespace
Readsuntil the next whitespace is encountered. Any trailing whitespace will be skipped.- Parameters:
preserveSingleSpace- whether a single trailing space should be preserved- Returns:
- the read string
-
readStringSkipWhitespace
Readsuntil the next whitespace is encountered. Any trailing whitespace will be skipped.- Returns:
- the read string
-
readString
Skips initial whitespace andreadsuntil the next whitespace is encountered.- Returns:
- the read string
-
readUntil
Reads until theseparator, and then preserves it.- Parameters:
separator- the separator to read until- Returns:
- the read string
-
readUntilAndSkip
Reads until theseparator, and then skips the separator.- Parameters:
separator- the separator to read until- Returns:
- the read string
-
skipWhitespace
SkipsmaxSpacesof whitespace characters at the head of the input.- Parameters:
maxSpaces- maximum number of spaces of consumepreserveSingleSpace- whether a single whitespace at the tail of the input should be ignored- Returns:
this
-
skipWhitespace
SkipsmaxSpacesof whitespace characters at the head of the input.- Parameters:
maxSpaces- maximum number of spaces of consume- Returns:
this
-
skipWhitespace
Skips any whitespace characters at the head of the input.- Parameters:
preserveSingleSpace- whether a single space should be ignored- Returns:
this
-
skipWhitespace
Skips any whitespace characters at the head of the input.- Returns:
this
-
hasNonWhitespace
default boolean hasNonWhitespace()Returns whether theremaining inputcontains any non-whitespace characters.- Returns:
- whether the remaining input contains any non-whitespace characters
-
isValidByte
Returns whetherpeekString()contain a validBytewithin the given range.- Parameters:
min- the min valuemax- the max value- Returns:
- whether the input until the next whitespace contains a valid
Byte
-
isValidByte
Returns whetherpeekString()contain a validBytewithin the given range.- Parameters:
range- range of accepted numbers- Returns:
- whether the input until the next whitespace contains a valid
Byte
-
readByte
default byte readByte()Reads thestring until the next whitespaceand parses in into aByte.- Returns:
- the parsed byte
- Throws:
NumberFormatException- If the string cannot be parsed into aByte.
-
isValidShort
Returns whetherpeekString()contain a validShortwithin the given range.- Parameters:
min- the min valuemax- the max value- Returns:
- whether the input until the next whitespace contains a valid
Short
-
isValidShort
Returns whetherpeekString()contain a validShortwithin the given range.- Parameters:
range- range of accepted numbers- Returns:
- whether the input until the next whitespace contains a valid
Short
-
readShort
default short readShort()Reads thestring until the next whitespaceand parses in into aShort.- Returns:
- the parsed short
- Throws:
NumberFormatException- If the string cannot be parsed into aShort.
-
isValidInteger
Returns whetherpeekString()contain a validIntegerwithin the given range.- Parameters:
min- the min valuemax- the max value- Returns:
- whether the input until the next whitespace contains a valid
Integer
-
isValidInteger
Returns whetherpeekString()contain a validIntegerwithin the given range.- Parameters:
range- range of accepted numbers- Returns:
- whether the input until the next whitespace contains a valid
Integer
-
readInteger
default int readInteger()Reads thestring until the next whitespaceand parses in into aInteger.- Returns:
- the parsed integer
- Throws:
NumberFormatException- If the string cannot be parsed into aInteger.
-
readInteger
default int readInteger(int radix) Reads thestring until the next whitespaceand parses in into aInteger.- Parameters:
radix- radix- Returns:
- the parsed integer
- Throws:
NumberFormatException- If the string cannot be parsed into aInteger.
-
isValidLong
Returns whetherpeekString()contain a validLongwithin the given range.- Parameters:
min- the min valuemax- the max value- Returns:
- whether the input until the next whitespace contains a valid
Long
-
isValidLong
Returns whetherpeekString()contain a validLongwithin the given range.- Parameters:
range- range of accepted numbers- Returns:
- whether the input until the next whitespace contains a valid
Long
-
readLong
default long readLong()Reads thestring until the next whitespaceand parses in into aLong.- Returns:
- the parsed long
- Throws:
NumberFormatException- If the string cannot be parsed into aLong.
-
isValidDouble
Returns whetherpeekString()contain a validDoublewithin the given range.- Parameters:
min- the min valuemax- the max value- Returns:
- whether the input until the next whitespace contains a valid
Double
-
isValidDouble
Returns whetherpeekString()contain a validDoublewithin the given range.- Parameters:
range- range of accepted numbers- Returns:
- whether the input until the next whitespace contains a valid
Double
-
readDouble
default double readDouble()Reads thestring until the next whitespaceand parses in into aDouble.- Returns:
- the parsed double
- Throws:
NumberFormatException- If the string cannot be parsed into aDouble.
-
isValidFloat
Returns whetherpeekString()contain a validFloatwithin the given range.- Parameters:
min- the min valuemax- the max value- Returns:
- whether the input until the next whitespace contains a valid
Float
-
isValidFloat
Returns whetherpeekString()contain a validFloatwithin the given range.- Parameters:
range- range of accepted numbers- Returns:
- whether the input until the next whitespace contains a valid
Float
-
readFloat
default float readFloat()Reads thestring until the next whitespaceand parses in into aFloat.- Returns:
- the parsed float
- Throws:
NumberFormatException- If the string cannot be parsed into aFloat.
-
isValidBoolean
Returns whetherpeekString()contain a validBooleanwithin the given range.- Parameters:
liberal- whether non-strict boolean values like "yes", "no", "on" and "off" should be allowed- Returns:
- whether the input until the next whitespace contains a valid
Boolean
-
readBoolean
default boolean readBoolean()Reads thestring until the next whitespaceand parses in into aBoolean.- Returns:
- the parsed boolean
- Throws:
IllegalArgumentException- If the string cannot be parsed into aBoolean.
-
lastRemainingToken
Returns the last remaining token.If the string ends with a blank space, then an empty string is returned.
.- Returns:
- the last remaining token, or an empty string if none remains
-
lastRemainingCharacter
default char lastRemainingCharacter()Returns the last remaining character.- Returns:
- the last remaining character
- Throws:
CommandInput.CursorOutOfBoundsException- ifisEmpty()istrue
-
copy
@NonNull CommandInput copy()Returns a copy of this instance.- Returns:
- copy of this instance
-
difference
Returns the input that has been consumed bythatinput that has not been consumed byinput.- Parameters:
that- the input to compare toincludeTrailingWhitespace- whether to include trailing whitespace- Returns:
- the difference in consumed input
-
difference
Returns the input that has been consumed bythatinput that has not been consumed byinput.- Parameters:
that- the input to compare to- Returns:
- the difference in consumed input
-