public final class Args extends ObjectMap
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
Main arguments are available through numeric string keys (e.g. ObjectMap
API to convert main arguments directly to POJOs, such as an
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
|
boolean |
hasArg(String name)
Returns
|
append, appendAll, appendIf, appendIf, appendSkipEmpty, appendSkipFalse, appendSkipMinusOne, appendSkipNull, cast, cast, containsKey, containsKeyNotEmpty, 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, getObjectList, getObjectMap, getObjectMap, getObjectMap, getString, getString, getStringArray, getStringArray, getSwapped, getWithDefault, getWithDefault, getWithDefault, include, isUnmodifiable, keepAll, keySet, modifiable, postAt, putAt, putIfEmpty, putIfNotExists, putIfNull, putJson, removeAll, removeAll, removeBoolean, removeBoolean, removeInt, removeInt, removeString, removeString, removeWithDefault, serializeTo, setBeanSession, setInner, toString, toString, unmodifiable
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 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 boolean hasArg(String name)
name
- The argument name.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 © 2016–2019 The Apache Software Foundation. All rights reserved.