|
| static boolean | isFlag (String arg) |
| |
| static boolean | isValue (String arg) |
| |
Parses and stores command-line arguments into simple flag/value pairs.
- Author
- CS 272 Software Development (University of San Francisco)
-
Ravneet Singh Bhatia
- Version
- Spring 2024
◆ ArgumentParser() [1/2]
| edu.usfca.cs272.ArgumentParser.ArgumentParser |
( |
| ) |
|
Initializes this argument map.
◆ ArgumentParser() [2/2]
| edu.usfca.cs272.ArgumentParser.ArgumentParser |
( |
String[] | args | ) |
|
Initializes this argument map and then parsers the arguments into flag/value pairs where possible. Some flags may not have associated values. If a flag is repeated, its value is overwritten.
- Parameters
-
| args | the command line arguments to parse |
◆ getInteger() [1/2]
| int edu.usfca.cs272.ArgumentParser.getInteger |
( |
String | flag | ) |
|
Returns the value the specified flag is mapped as an int value, or 0 if unable to retrieve this mapping (including being unable to convert the value to an int or if no value exists).
- Parameters
-
| flag | the flag whose associated value will be returned |
- Returns
- the value the specified flag is mapped as an int, or 0 if there is no valid mapping
- See also
- #getInteger(String, int)
◆ getInteger() [2/2]
| int edu.usfca.cs272.ArgumentParser.getInteger |
( |
String | flag, |
|
|
int | backup ) |
Returns the value the specified flag is mapped as an int value, or the backup value if unable to retrieve this mapping (including being unable to convert the value to an int or if no value exists).
- Parameters
-
| flag | the flag whose associated value will be returned |
| backup | the backup value to return if there is no valid mapping |
- Returns
- the value the specified flag is mapped as an int, or the backup value if there is no valid mapping
- See also
- Integer::parseInt(String)
◆ getPath() [1/2]
| Path edu.usfca.cs272.ArgumentParser.getPath |
( |
String | flag | ) |
|
Returns the value to which the specified flag is mapped as a Path, or null if unable to retrieve this mapping (including being unable to convert the value to a Path or no value exists).
This method should not throw any exceptions!
- Parameters
-
| flag | the flag whose associated value is to be returned |
- Returns
- the value to which the specified flag is mapped, or
null if unable to retrieve this mapping
- See also
- #getPath(String, Path)
◆ getPath() [2/2]
| Path edu.usfca.cs272.ArgumentParser.getPath |
( |
String | flag, |
|
|
Path | backup ) |
Returns the value the specified flag is mapped as a Path, or the backup value if unable to retrieve this mapping (including being unable to convert the value to a Path or if no value exists).
This method should not throw any exceptions!
- Parameters
-
| flag | the flag whose associated value will be returned |
| backup | the backup value to return if there is no valid mapping |
- Returns
- the value the specified flag is mapped as a
Path, or the backup value if there is no valid mapping
- See also
- Path::of(String, String...)
◆ getString() [1/2]
| String edu.usfca.cs272.ArgumentParser.getString |
( |
String | flag | ) |
|
Returns the value to which the specified flag is mapped as a String or null if there is no mapping.
- Parameters
-
| flag | the flag whose associated value is to be returned |
- Returns
- the value to which the specified flag is mapped or
null if there is no mapping
◆ getString() [2/2]
| String edu.usfca.cs272.ArgumentParser.getString |
( |
String | flag, |
|
|
String | backup ) |
Returns the value to which the specified flag is mapped as a String or the backup value if there is no mapping.
- Parameters
-
| flag | the flag whose associated value is to be returned |
| backup | the backup value to return if there is no mapping |
- Returns
- the value to which the specified flag is mapped, or the backup value if there is no mapping
◆ hasFlag()
| boolean edu.usfca.cs272.ArgumentParser.hasFlag |
( |
String | flag | ) |
|
Determines whether the specified flag exists.
- Parameters
-
- Returns
true if the flag exists
◆ hasValue()
| boolean edu.usfca.cs272.ArgumentParser.hasValue |
( |
String | flag | ) |
|
Determines whether the specified flag is mapped to a non-null value.
- Parameters
-
- Returns
true if the flag is mapped to a non-null value
◆ isFlag()
| static boolean edu.usfca.cs272.ArgumentParser.isFlag |
( |
String | arg | ) |
|
|
static |
Determines whether the argument is a flag. The argument is considered a flag if it is a dash "-" character followed by any character that is not a digit or whitespace. For example, "-hello" and "-@world" are considered flags, but "-10" and "- hello" are not.
- Parameters
-
| arg | the argument to test if it's a flag |
- Returns
true if the argument is a flag
- See also
- String::startsWith(String)
-
String::length()
-
String::codePointAt(int)
-
Character::isDigit(int)
-
Character::isWhitespace(int)
◆ isValue()
| static boolean edu.usfca.cs272.ArgumentParser.isValue |
( |
String | arg | ) |
|
|
static |
Determines whether the argument is a value. Anything that is not a flag is considered a value.
- Parameters
-
| arg | the argument to test if it's a value |
- Returns
true if the argument is a value
◆ numFlags()
| int edu.usfca.cs272.ArgumentParser.numFlags |
( |
| ) |
|
Returns the number of unique flags.
- Returns
- number of unique flags
◆ parse()
| void edu.usfca.cs272.ArgumentParser.parse |
( |
String[] | args | ) |
|
Parses the arguments into flag/value pairs where possible. Some flags may not have associated values. If a flag is repeated, its value will be overwritten.
- Parameters
-
| args | the command line arguments to parse |
The documentation for this class was generated from the following file:
- C:/USFCS/CS272/projects/project-Ravneetsb/src/main/java/edu/usfca/cs272/ArgumentParser.java