Class Command

java.lang.Object
com.github.mafelp.utils.Command

public class Command extends Object
Class to parse strings to commands.
  • Field Details

    • arguments

      private final String[] arguments
      The arguments of the command as an argument
    • command

      private final String command
      The command aka. the first argument passed in.
  • Constructor Details

    • Command

      public Command(String command, String[] arguments)
      default constructor for manual construction.
      Parameters:
      command - the command
      arguments - an Array of arguments for the command.
  • Method Details

    • getStringArgument

      public Optional<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 Optional<Boolean> getBooleanArgument(int index)
      Gets the argument at the index as a boolean.
      Parameters:
      index - index of the argument.
      Returns:
      the value.
    • getLongArgument

      public Optional<Long> getLongArgument(int index)
      Gets the argument at the index as a Long/int.
      Parameters:
      index - index of the argument.
      Returns:
      the value.
    • getIntegerArgument

      public Optional<Integer> getIntegerArgument(int index)
      Gets the argument at the index as an int.
      Parameters:
      index - index of the argument.
      Returns:
      the value.
    • getArguments

      public String[] getArguments()
      Gets the argument array.
      Returns:
      the arguments as a string array
    • getCommand

      public 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