Package com.github.mafelp.utils
Class Command
java.lang.Object
com.github.mafelp.utils.Command
public class Command
extends java.lang.Object
Class to parse strings to commands.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Command(java.lang.String command, java.lang.String[] arguments)
default constructor for manual construction. -
Method Summary
Modifier and Type Method Description private boolean
argumentIsAvailable(int index)
Checks if the index to get the argument from is present.java.lang.String[]
getArguments()
Gets the argument array.java.util.Optional<java.lang.Boolean>
getBooleanArgument(int index)
Gets the argument at the index as a boolean.java.lang.String
getCommand()
Gets the command - the first argument in the parsed string.java.util.Optional<java.lang.Long>
getLongArgument(int index)
Gets the argument at the index as a Long/int.java.util.Optional<java.lang.String>
getStringArgument(int index)
Gets the argument at the index as a string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
arguments
private final java.lang.String[] argumentsThe arguments of the command as an argument -
command
private final java.lang.String commandThe command aka. the first argument passed in.
-
-
Constructor Details
-
Command
public Command(java.lang.String command, java.lang.String[] arguments)default constructor for manual construction.- Parameters:
command
- the commandarguments
- an Array of arguments for the command.
-
-
Method Details
-
getStringArgument
public java.util.Optional<java.lang.String> getStringArgument(int index)Gets the argument at the index as a string.- Parameters:
index
- the index of the argument.- Returns:
- the value of the index.
-
getBooleanArgument
public java.util.Optional<java.lang.Boolean> getBooleanArgument(int index)Gets the argument at the index as a boolean.- Parameters:
index
- index of the argument.- Returns:
- the value.
-
getLongArgument
public java.util.Optional<java.lang.Long> getLongArgument(int index)Gets the argument at the index as a Long/int.- Parameters:
index
- index of the argument.- Returns:
- the value.
-
getArguments
public java.lang.String[] getArguments()Gets the argument array.- Returns:
- the arguments as a string array
-
getCommand
public java.lang.String 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
-