Package com.github.mafelp.utils
Class Command
java.lang.Object
com.github.mafelp.utils.Command
Class to parse strings to commands.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
argumentIsAvailable(int index)
Checks if the index to get the argument from is present.String[]
Gets the argument array.getBooleanArgument(int index)
Gets the argument at the index as a boolean.Gets the command - the first argument in the parsed string.getIntegerArgument(int index)
Gets the argument at the index as an int.getLongArgument(int index)
Gets the argument at the index as a Long/int.getStringArgument(int index)
Gets the argument at the index as a string.
-
Field Details
-
arguments
The arguments of the command as an argument -
command
The command aka. the first argument passed in.
-
-
Constructor Details
-
Command
default constructor for manual construction.- Parameters:
command
- the commandarguments
- an Array of arguments for the command.
-
-
Method Details
-
getStringArgument
Gets the argument at the index as a string.- Parameters:
index
- the index of the argument.- Returns:
- the value of the index.
-
getBooleanArgument
Gets the argument at the index as a boolean.- Parameters:
index
- index of the argument.- Returns:
- the value.
-
getLongArgument
Gets the argument at the index as a Long/int.- Parameters:
index
- index of the argument.- Returns:
- the value.
-
getIntegerArgument
Gets the argument at the index as an int.- Parameters:
index
- index of the argument.- Returns:
- the value.
-
getArguments
Gets the argument array.- Returns:
- the arguments as a string array
-
getCommand
Gets the command - the first argument in the parsed string.- Returns:
- the command.
-
argumentIsAvailable
private boolean argumentIsAvailable(int index)Checks if the index to get the argument from is present. - checking this before trying to get the value of an index helps preventing an array out of bound exception.- Parameters:
index
- the index to check if it is present- Returns:
- success state - is the index available, yes/no
-