Package org.omegazero.common.util
Class Args
java.lang.Object
org.omegazero.common.util.Args
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Args.DefaultFormat
Class used for parsing command line arguments.
- Since:
- 2.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAnArgsimplementation for the default argument format. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBooleanOrDefault(String key, boolean def) Returns the boolean value identified by the given key, or def if no value with the specified key exists or is not a boolean.doublegetDoubleOrDefault(String key, double def) Returns the double-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.floatgetFloatOrDefault(String key, float def) Returns the single-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.intgetIntOrDefault(String key, int def) Returns the integer value identified by the given key, or def if no value with the specified key exists or is not a number.longgetLongOrDefault(String key, long def) Returns the long integer value identified by the given key, or def if no value with the specified key exists or is not a number.Returns the string value identified by the given key, ornullif no value with the specified key exists.getValueOrDefault(String key, String def) Returns the string value identified by the given key, or def if no value with the specified key exists.static ArgsParses the given array of arguments using the default format.abstract voidparseArguments(String[] args) Parses the given argument array and stores the data in thisArgsobject.protected voidStores the given value identified by the key in this object.
-
Field Details
-
arguments
The argument data.
-
-
Constructor Details
-
Args
public Args()
-
-
Method Details
-
parseArguments
Parses the given argument array and stores the data in thisArgsobject.Values identified as integers, booleans ("
true" and "false") or floating-point numbers are automatically converted to the respective type.- Parameters:
args- The argument array- Implementation Note:
- Use
put(String, String)to store values
-
getValue
Returns the string value identified by the given key, ornullif no value with the specified key exists.- Parameters:
key- The key string- Returns:
- The value or
nullif it does not exist
-
getValueOrDefault
Returns the string value identified by the given key, or def if no value with the specified key exists.- Parameters:
key- The key stringdef- The default value to return if no value with the given key exists- Returns:
- The value or def if it does not exist
-
getIntOrDefault
Returns the integer value identified by the given key, or def if no value with the specified key exists or is not a number.- Parameters:
key- The key stringdef- The default value to return if no value with the given key exists- Returns:
- The value or def if it does not exist
-
getLongOrDefault
Returns the long integer value identified by the given key, or def if no value with the specified key exists or is not a number.- Parameters:
key- The key stringdef- The default value to return if no value with the given key exists- Returns:
- The value or def if it does not exist
-
getFloatOrDefault
Returns the single-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.- Parameters:
key- The key stringdef- The default value to return if no value with the given key exists- Returns:
- The value or def if it does not exist
-
getDoubleOrDefault
Returns the double-precision floating-point number value identified by the given key, or def if no value with the specified key exists or is not a number.- Parameters:
key- The key stringdef- The default value to return if no value with the given key exists- Returns:
- The value or def if it does not exist
-
getBooleanOrDefault
Returns the boolean value identified by the given key, or def if no value with the specified key exists or is not a boolean.- Parameters:
key- The key stringdef- The default value to return if no value with the given key exists- Returns:
- The value or def if it does not exist
-
put
Stores the given value identified by the key in this object. The value is automatically converted to the appropriate type, if applicable (for example, strings consisting only of digits are converted to a number).- Parameters:
key- The keyvalue- The value
-
parse
Parses the given array of arguments using the default format. SeeArgs.DefaultFormat.parseArguments(String[]).- Parameters:
args- The argument array- Returns:
- The
Argsobject representing the parsed data
-