public final class Args extends ObjectMap
main(String[] args)
method.
Used to parse command-line arguments of the form
The format of a main argument is a token that does not start with
The format of an optional argument is
java com.sample.MyClass mainArg1
java com.sample.MyClass mainArg1 mainArg2
java com.sample.MyClass mainArg1 -optArg1
java com.sample.MyClass -optArg1
java com.sample.MyClass mainArg1 -optArg1 optArg1Val
java com.sample.MyClass mainArg1 -optArg1 optArg1Val1 optArg1Val2
java com.sample.MyClass mainArg1 -optArg1 optArg1Val1 -optArg1 optArg1Val2
Main arguments are available through numeric string keys (e.g. ObjectMap
API to convert main arguments directly to POJOs, such as an Enum
Equivalent operations are available on optional arguments through the getArg(Class, String)
method.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
Args(String args)
Constructor.
|
Args(String[] args)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
getArg(Class<T> c,
String name)
Returns the optional argument value converted to the specified object type.
|
String |
getArg(int i)
Returns main argument at the specified index, or
|
String |
getArg(String name)
Returns the optional argument value, or blank if the optional argument was not specified.
|
List<String> |
getArgs(String name)
Returns the optional argument values as a list of strings.
|
boolean |
hasArg(int i)
Returns
|
append, appendAll, cast, cast, containsKey, containsOuterKey, deleteAt, entrySet, exclude, find, find, findBoolean, findInt, findKeyIgnoreCase, findList, findLong, findMap, findObjectList, findObjectMap, findString, get, get, get, getAt, getAt, getBeanSession, getBoolean, getBoolean, getClassMeta, getFirstKey, getInt, getInt, getList, getList, getList, getLong, getLong, getMap, getMap, getMap, getObjectList, getObjectList, getObjectMap, getObjectMap, getString, getString, getStringArray, getStringArray, getSwapped, getWithDefault, getWithDefault, getWithDefault, include, keySet, postAt, putAt, putIfEmpty, putIfNull, putJson, removeAll, removeAll, removeWithDefault, serializeTo, setBeanSession, setInner, toString, toString
clear, containsValue, forEach, getOrDefault, removeEldestEntry, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
equals, hashCode
public Args(String[] args)
args
- Arguments passed in through a main(String[] args)
method.public String getArg(int i)
Can be used in conjunction with hasArg(int)
to check for existence of arg.
Since main arguments are stored as numeric keys, this method is essentially equivalent to...
i
- The index position of the main argument (zero-indexed).public boolean hasArg(int i)
i
- The zero-indexed position of the argument.public String getArg(String name)
If the optional arg has multiple values, returns values as a comma-delimited list.
name
- The optional argument name.public <T> T getArg(Class<T> c, String name)
If the optional arg has multiple values, returns only the first converted value.
T
- The class type to convert the value to.c
- The class type to convert the value to.name
- The optional argument name.public List<String> getArgs(String name)
name
- The optional argument name.Copyright © 2018 Apache. All rights reserved.