public final class CommandArgs extends Object
Modifier and Type | Class and Description |
---|---|
class |
CommandArgs.Snapshot
A snapshot of a
CommandArgs . |
Constructor and Description |
---|
CommandArgs(String rawInput,
List<SingleArg> args)
Create a new CommandArgs instance with the given raw input and arguments.
|
Modifier and Type | Method and Description |
---|---|
void |
applySnapshot(CommandArgs.Snapshot snapshot)
Resets a
CommandArgs to a previous state using a previously
created CommandArgs.Snapshot . |
void |
applySnapshot(CommandArgs.Snapshot snapshot,
boolean resetArgs)
Resets a
CommandArgs to a previous state using a previously
created CommandArgs.Snapshot . |
ArgumentParseException |
createError(Text message)
Create a parse exception with the provided message which has the position
of the last parsed argument attached.
|
String |
get(int index)
Get an arg at the specified position.
|
List<String> |
getAll()
Gets a list of all arguments as a string.
|
String |
getRaw()
Return the raw string used to provide input to this arguments object.
|
int |
getRawPosition()
Gets the current position in raw input.
|
CommandArgs.Snapshot |
getSnapshot()
Gets a snapshot of the data inside this context to allow it to be
restored later.
|
Object |
getState()
Deprecated.
Use
getSnapshot() and
applySnapshot(Snapshot) instead |
boolean |
hasNext()
Return whether more arguments remain to be read.
|
void |
insertArg(String value)
Insert an arg as the next arg to be returned by
next() . |
String |
next()
Try to read the next argument, advancing the current index if successful.
|
Optional<String> |
nextIfPresent()
Try to read the next argument, advancing the current index if successful
or returning an absent optional if not.
|
String |
peek()
Try to read the next argument without advancing the current index.
|
void |
removeArgs(CommandArgs.Snapshot startSnapshot,
CommandArgs.Snapshot endSnapshot)
Remove the arguments parsed between two snapshots.
|
void |
removeArgs(Object startState,
Object endState)
Deprecated.
Use with
getSnapshot() instead of
getState() with removeArgs(Snapshot, Snapshot) |
void |
setState(Object state)
Deprecated.
Use
getSnapshot() and
applySnapshot(Snapshot) instead |
int |
size()
Returns the number of arguments
|
public boolean hasNext()
public String peek() throws ArgumentParseException
ArgumentParseException
- if not enough arguments are presentpublic String next() throws ArgumentParseException
ArgumentParseException
- if not enough arguments are presentpublic Optional<String> nextIfPresent()
public ArgumentParseException createError(Text message)
message
- The message for the exceptionpublic List<String> getAll()
@Deprecated public Object getState()
getSnapshot()
and
applySnapshot(Snapshot)
insteadsetState(Object)
method.@Deprecated public void setState(Object state)
getSnapshot()
and
applySnapshot(Snapshot)
insteadstate
- the previous statepublic String getRaw()
public String get(int index)
index
- index of the element to returnpublic void insertArg(String value)
next()
.value
- The argument to insert@Deprecated public void removeArgs(Object startState, Object endState)
getSnapshot()
instead of
getState()
with removeArgs(Snapshot, Snapshot)
startState
- The starting stateendState
- The ending statepublic void removeArgs(CommandArgs.Snapshot startSnapshot, CommandArgs.Snapshot endSnapshot)
startSnapshot
- The starting stateendSnapshot
- The ending statepublic int size()
public int getRawPosition()
public CommandArgs.Snapshot getSnapshot()
CommandArgs.Snapshot
containing the current state of the
CommandArgs
public void applySnapshot(CommandArgs.Snapshot snapshot)
CommandArgs
to a previous state using a previously
created CommandArgs.Snapshot
.snapshot
- The CommandArgs.Snapshot
to restore this context
withpublic void applySnapshot(CommandArgs.Snapshot snapshot, boolean resetArgs)
CommandArgs
to a previous state using a previously
created CommandArgs.Snapshot
.
If resetArgs is set to false, this snapshot will not reset the argument list to its previous state, only the index.
snapshot
- The CommandArgs.Snapshot
to restore this context
withresetArgs
- Whether to restore the argument list