Package javax0.repl
Class ParameterParser
- java.lang.Object
-
- javax0.repl.ParameterParser
-
public class ParameterParser extends java.lang.Object
A parameter parser that is to parse the command line and after that to query the command parameters.
-
-
Constructor Summary
Constructors Constructor Description ParameterParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<java.lang.String>
get(int i)
Get thei
-th parameter (starting with 0) from the parsed line.java.util.Optional<java.lang.String>
get(java.lang.String key)
Get the value that was associated with the key on the parsed line.java.util.Optional<java.lang.String>
get(java.lang.String key, java.util.Set<java.lang.String> values)
Get the value associated with the key using a set of predefined values.java.lang.String
getOrDefault(java.lang.String key, java.lang.String def)
Get the value associated with the key or the default in case the key was not present on the command line.java.lang.String
getOrDefault(java.lang.String key, java.lang.String def, java.util.Set<java.lang.String> values)
The same asget(String, Set)
but if the key was not defined it will return the default value instead ofnull
.
-
-
-
Method Detail
-
get
public java.util.Optional<java.lang.String> get(java.lang.String key, java.util.Set<java.lang.String> values)
Get the value associated with the key using a set of predefined values. The actual value that was parsed from the line may be an unambiguous prefix of the possible values. In that case the value listed in the set will be the one that is defined in the set. If the value cannot be found in the setIllegalArgumentException
will be thrown.- Parameters:
key
- for which we want to retrieve the valuevalues
- the possible values- Returns:
- the optional value found from the set or
Optional.empty()
if the parameter was not present on the command
-
get
public java.util.Optional<java.lang.String> get(java.lang.String key)
Get the value that was associated with the key on the parsed line.- Parameters:
key
- the full key as it was defined in the possible keys set- Returns:
- the optional value as it was on the line or
Optional.empty()
in case the key was not present on the line
-
get
public java.util.Optional<java.lang.String> get(int i)
Get thei
-th parameter (starting with 0) from the parsed line. In casei
is larger than the index of the last parameterOptional.empty()
is returned.- Parameters:
i
- index of the parameter- Returns:
- the parameter from the line or
Optional.empty()
ifi
is too large
-
getOrDefault
public java.lang.String getOrDefault(java.lang.String key, java.lang.String def)
Get the value associated with the key or the default in case the key was not present on the command line.- Parameters:
key
- we look fordef
- the default value for the key- Returns:
- the value for the key
-
getOrDefault
public java.lang.String getOrDefault(java.lang.String key, java.lang.String def, java.util.Set<java.lang.String> values)
The same asget(String, Set)
but if the key was not defined it will return the default value instead ofnull
.- Parameters:
key
- for which we want to retrieve the valuedef
- the default value to be returned in case the key was not present on the linevalues
- the possible values- Returns:
- the value for the key
-
-