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

    Fields
    Modifier and Type Field Description
    private java.lang.String[] arguments
    The arguments of the command as an argument
    private java.lang.String command
    The command aka.
  • 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.
    boolean equals​(java.lang.Object obj)  
    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.
    java.lang.String toString()  
    java.lang.String toString​(boolean withQuotes)  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • arguments

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

      private final java.lang.String command
      The command aka. the 0th argument passed in.
  • Constructor Details

    • Command

      public Command​(java.lang.String command, java.lang.String[] arguments)
      default constructor for manual construction.
      Parameters:
      command - the command
      arguments - 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
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
      Returns:
      The command as a string without quotes.
    • toString

      public java.lang.String toString​(boolean withQuotes)
      Parameters:
      withQuotes - If the arguments should be put into quotes.
      Returns:
      The command as a string with(-out) quotes.