Class ArgUtils
- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.utils.ArgUtils
-
public class ArgUtils extends Object
Contains handy methods to deal with command arguments.
-
-
Constructor Summary
Constructors Constructor Description ArgUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
concatArgs(Context ctx, int fromIndex)
Concatenates all arguments from the specified index to the end.static int
getArgAsInt(Context ctx, int index)
Gets the value of the argument at the specified index as int.static long
getArgAsLong(Context ctx, int index)
Gets the value of the argument at the specified index as long.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.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.
-
-
-
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, anInvalidSyntaxException
is thrown.- Parameters:
ctx
- the contextcount
- 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, anCommandFailedException
is thrown with a personalized message.- Parameters:
ctx
- the contextcount
- the target minimum arg counterrorMessage
- 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 contextfromIndex
- 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 contextindex
- the argument index- Returns:
- the value of the argument as int
- Throws:
IndexOutOfBoundsException
- if index is out of boundsCommandFailedException
- 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 contextindex
- the argument index- Returns:
- the value of the argument as long
- Throws:
IndexOutOfBoundsException
- if index is out of boundsCommandFailedException
- if the value could not be parsed as long
-
-