Class Arguments
java.lang.Object
edu.uky.cs.nil.tt.Arguments
A list of command line arguments and various utility methods to parse keys
and values.
This list assumes that keys begin with a "-" (dash) character and the
values to keys do not. For example, if the command line arguments are:
-k1 value -k2 -k3Then they contain three keys (starting with dashed). The first key has one value,
"value", and the second two keys do not have values.- Author:
- Stephen G. Ware
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThrows an exception if any command line arguments have not yet been marked as used by the other methods provided by this list.booleanTests whether a given key appears in the list of arguments.Returns the value immediately after a given key, or a default value if the key has no value, or null if the key does not appear.
-
Constructor Details
-
Arguments
Constructs a new command line argument lists.- Parameters:
args- the array of string passed to the Java main method
-
-
Method Details
-
contains
Tests whether a given key appears in the list of arguments. The key should be given without its preceding dash. Case is ignored. For example, if this method is called with"key", it will return true if"-KEY"appears in the list of arguments. If the key is found, it is marked as used.- Parameters:
arg- the key, without a dash as its first character- Returns:
- true if the key appears in the list of arguments, ignoring case and with a dash prepended as its first character
-
getValue
Returns the value immediately after a given key, or a default value if the key has no value, or null if the key does not appear. The key should be given without its preceding dash, and case is ignored when searching for the key. For example, if this method is called with"key"and"value", it will return"value"if"-KEY"appears in the list of arguments. If the key is found, it (and its value, if found) are marked as used.- Parameters:
key- the key whose value is desired, without a dash as its first characterdef- a default value to return if the key appears but has no value- Returns:
- the value immediately after the key, or the default value if there is no value after the key, or null if the key does not appear
-
checkUnused
public void checkUnused()Throws an exception if any command line arguments have not yet been marked as used by the other methods provided by this list.- Throws:
IllegalArgumentException- if any arguments have not yet been marked as used
-