Class ArgUtils


  • public class ArgUtils
    extends Object
    Contains handy methods to deal with command arguments.
    • Constructor Detail

      • ArgUtils

        public ArgUtils()
    • Method Detail

      • requireMinimumArgCount

        public static void requireMinimumArgCount​(Context ctx,
                                                  int count)
        Checks if the arguments of htis context has an argument count greater or equal to the given count. If the condition isn't satisfied, an InvalidSyntaxException is thrown.
        Parameters:
        ctx - the context
        count - the target minimum arg count
        Throws:
        InvalidSyntaxException - if the args of the context don't satify the given count
      • requireMinimumArgCount

        public static void requireMinimumArgCount​(Context ctx,
                                                  int count,
                                                  String errorMessage)
        Checks if the arguments of htis context has an argument count greater or equal to the given count. If the condition isn't satisfied, an CommandFailedException is thrown with a personalized message.
        Parameters:
        ctx - the context
        count - the target minimum arg count
        errorMessage - the error message
        Throws:
        CommandFailedException - if the args of the context dsn't satify the given count
      • concatArgs

        public static String concatArgs​(Context ctx,
                                        int fromIndex)
        Concatenates all arguments from the specified index to the end.
        Parameters:
        ctx - the context
        fromIndex - index from which to start concatenate
        Returns:
        the concatenated args
        Throws:
        IndexOutOfBoundsException - if fromIndex is lower than 0 or is greater or equal to the arg count
      • getArgAsInt

        public static int getArgAsInt​(Context ctx,
                                      int index)
        Gets the value of the argument at the specified index as int.
        Parameters:
        ctx - the context
        index - the argument index
        Returns:
        the value of the argument as int
        Throws:
        IndexOutOfBoundsException - if index is out of bounds
        CommandFailedException - if the value could not be parsed as int
      • getArgAsLong

        public static long getArgAsLong​(Context ctx,
                                        int index)
        Gets the value of the argument at the specified index as long.
        Parameters:
        ctx - the context
        index - the argument index
        Returns:
        the value of the argument as long
        Throws:
        IndexOutOfBoundsException - if index is out of bounds
        CommandFailedException - if the value could not be parsed as long