public class ComLineArgs extends Object implements Serializable
Utility class to parse command line arguments passed to main method.
For example, say these arguments are given:
-verbose -out fileOut -in fileIn1 fileIn2
containsTag("-verbose")
returns true and consumes -verbosegetArg("-verbose")
returns -out and consumes -verbose and -outgetArg("-verbose", 1)
returns fileOut and consumes -verbose and fileoutgetArg("-out")
returns fileOut and consumes -out and fileOutgetArg("-in")
returns fileIn1 and consumes -in and fileIn1getArg("-in",1)
returns fileIn2 and consumes -in and fileIn2getArg("-in", 2)
throws NoSuchElementExceptionConstructor and Description |
---|
ComLineArgs(String[] args)
Creates a new ComLineArgs.
|
ComLineArgs(String[] args,
int offset)
Creates a new ComLineArgs.
|
ComLineArgs(String[] args,
int offset,
int length)
Creates a new ComLineArgs.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsArg(String tag)
Returns true if contains given tag.
|
String |
getArg(int index)
returns index'th argument
|
String |
getArg(String tag)
Returns first argument for tag.
|
String |
getArg(String tag,
int index)
Returns index'th argument for tag.
|
String[] |
getArgs()
returns the original arguments.
|
List<String> |
getUnconsumed()
returns the unconsumed arguments
|
boolean |
isEmpty()
Returns true if empty.
|
boolean |
isUnconsumed()
returns true still exist any unconsumed argument
|
public ComLineArgs(String[] args, int offset, int length)
args
- the argumentsoffset
- offsetlength
- lengthpublic ComLineArgs(String[] args)
args
- the arguments. all of them will be usedpublic ComLineArgs(String[] args, int offset)
args
- the arguments. last (args.length - offset) arguments will be usedoffset
- offsetpublic boolean isEmpty()
public boolean containsArg(String tag)
public String getArg(int index) throws NoSuchElementException
NoSuchElementException
public String getArg(String tag, int index) throws NoSuchElementException
NoSuchElementException
- if tag or index'th element does not existpublic String getArg(String tag) throws NoSuchElementException
getArg(tag, 0).
This method consumes the first element of tag.NoSuchElementException
public boolean isUnconsumed()
public String[] getArgs()