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 class
AnArgs
implementation for the default argument format. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
getBooleanOrDefault
(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.double
getDoubleOrDefault
(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.float
getFloatOrDefault
(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.int
getIntOrDefault
(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.long
getLongOrDefault
(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, ornull
if 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 Args
Parses the given array of arguments using the default format.abstract void
parseArguments
(String[] args) Parses the given argument array and stores the data in thisArgs
object.protected void
Stores 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 thisArgs
object.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, ornull
if no value with the specified key exists.- Parameters:
key
- The key string- Returns:
- The value or
null
if 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
Args
object representing the parsed data
-