Class Args
- All Implemented Interfaces:
- Serializable,- Cloneable,- Map<String,- Object> 
 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 
Command-line examples
- 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 
Example:
   
 Main arguments are available through numeric string keys (e.g. JsonMap API to convert main arguments directly to POJOs, such as an 
   
 Equivalent operations are available on optional arguments through the getArg(Class, String) method.
 
Notes:
- This class is not thread safe.
See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> 
- 
Field Summary
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptiongetArg(int i) Returns main argument at the specified index, ornull if the index is out of range.<T> TReturns the optional argument value converted to the specified object type.Returns the optional argument value, or blank if the optional argument was not specified.Returns the optional argument values as a list of strings.booleanhasArg(int i) Returnstrue if argument exists at specified index.booleanReturnstrue if the named argument exists.Methods inherited from class org.apache.juneau.collections.JsonMapappend, append, appendFirst, appendIf, appendIf, appendIfAbsent, appendIfAbsentIf, asJson, asReadableString, asString, asString, cast, cast, containsKey, containsKeyNotEmpty, containsOuterKey, create, deleteAt, entrySet, exclude, filtered, filtered, filteredMap, filteredMap, find, find, findBoolean, findInt, findKeyIgnoreCase, findList, findLong, findMap, findString, get, get, get, getAt, getAt, getBeanSession, getBoolean, getBoolean, getClassMeta, getFirstKey, getInt, getInt, getList, getList, getList, getList, getLong, getLong, getMap, getMap, getMap, getMap, getString, getString, getStringArray, getStringArray, getSwapped, getWithDefault, getWithDefault, getWithDefault, include, inner, isUnmodifiable, keepAll, keySet, modifiable, of, of, ofJson, ofJson, ofText, ofText, postAt, put, putAt, putJson, removeAll, removeAll, removeBoolean, removeBoolean, removeInt, removeInt, removeString, removeString, removeWithDefault, session, setBeanSession, toString, unmodifiable, writeToMethods inherited from class java.util.LinkedHashMapclear, containsValue, forEach, getOrDefault, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.HashMapclone, compute, computeIfAbsent, computeIfPresent, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMapequals, hashCodeMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
- 
Constructor Details- 
ArgsConstructor.- Parameters:
- args- Arguments passed in through a- main(String[] args) method.
 
- 
ArgsConstructor.- Parameters:
- args- Arguments passed in as a raw command line.
 
 
- 
- 
Method Details- 
getArgReturns main argument at the specified index, ornull if the index is out of range.Can be used in conjunction with hasArg(int)to check for existence of arg.// Check for no arguments if (!args .hasArg(0))printUsageAndExit ();// Get the first argument StringfirstArg =args .getArg(0);Since main arguments are stored as numeric keys, this method is essentially equivalent to... // Check for no arguments if (!args .containsKey("0" ))printUsageAndExit ();// Get the first argument StringfirstArg =args .getString("0" );- Parameters:
- i- The index position of the main argument (zero-indexed).
- Returns:
- The main argument value, or "" if argument doesn't exist at that position.
 
- 
hasArgReturnstrue if argument exists at specified index.- Parameters:
- i- The zero-indexed position of the argument.
- Returns:
- true if argument exists at specified index.
 
- 
hasArgReturnstrue if the named argument exists.- Parameters:
- name- The argument name.
- Returns:
- true if the named argument exists.
 
- 
getArgReturns the optional argument value, or blank if the optional argument was not specified.If the optional arg has multiple values, returns values as a comma-delimited list. - Parameters:
- name- The optional argument name.
- Returns:
- The optional argument value, or blank if the optional argument was not specified.
 
- 
getArgReturns the optional argument value converted to the specified object type.If the optional arg has multiple values, returns only the first converted value. Example:// Command: java com.sample.MyClass -verbose true -debug 5 boolean bool =args .getArg(boolean .class ,"verbose" );int _int =args .getArg(int .class ,"debug" );- Type Parameters:
- T- The class type to convert the value to.
- Parameters:
- c- The class type to convert the value to.
- name- The optional argument name.
- Returns:
- The optional argument value, or blank if the optional argument was not specified.
 
- 
getArgsReturns the optional argument values as a list of strings.Example:// Command: java com.sample.MyClass -extraArgs foo bar baz List<String>list1 =args .getArgs("extraArgs" );// ['foo','bar','baz'] List<String>list2 =args .getArgs("nonExistentArgs" );// An empty list - Parameters:
- name- The optional argument name.
- Returns:
- The optional argument values, or an empty list if the optional argument was not specified.
 
 
-