Class CommandLine.Range
- java.lang.Object
-
- org.apache.logging.log4j.core.tools.picocli.CommandLine.Range
-
- All Implemented Interfaces:
java.lang.Comparable<CommandLine.Range>
- Enclosing class:
- CommandLine
public static class CommandLine.Range extends java.lang.Object implements java.lang.Comparable<CommandLine.Range>
Describes the number of parameters required and accepted by an option or a positional parameter.- Since:
- 0.9.7
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
isUnspecified
boolean
isVariable
int
max
Maximum accepted number of parameters for an option or positional parameter.int
min
Required number of parameters for an option or positional parameter.private java.lang.String
originalValue
-
Constructor Summary
Constructors Constructor Description Range(int min, int max, boolean variable, boolean unspecified, java.lang.String originalValue)
Constructs a new Range object with the specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static CommandLine.Range
adjustForType(CommandLine.Range result, java.lang.reflect.Field field)
int
compareTo(CommandLine.Range other)
boolean
contains(int value)
Returnstrue
if this Range includes the specified value,false
otherwise.static CommandLine.Range
defaultArity(java.lang.Class<?> type)
Returns the default arityRange
foroptions
: booleans have arity 0, other types have arity 1.static CommandLine.Range
defaultArity(java.lang.reflect.Field field)
Returns the default arityRange
: foroptions
this is 0 for booleans and 1 for other types, forparameters
booleans have arity 0, arrays or Collections have arity "0..*", and other types have arity 1.boolean
equals(java.lang.Object object)
int
hashCode()
CommandLine.Range
max(int newMax)
Returns a new Range object with themax
value replaced by the specified value.CommandLine.Range
min(int newMin)
Returns a new Range object with themin
value replaced by the specified value.static CommandLine.Range
optionArity(java.lang.reflect.Field field)
Returns a newRange
based on theCommandLine.Option.arity()
annotation on the specified field, or the field type's default arity if no arity was specified.static CommandLine.Range
parameterArity(java.lang.reflect.Field field)
Returns a newRange
based on theCommandLine.Parameters.arity()
annotation on the specified field, or the field type's default arity if no arity was specified.(package private) static CommandLine.Range
parameterCapacity(java.lang.reflect.Field field)
static CommandLine.Range
parameterIndex(java.lang.reflect.Field field)
Returns a newRange
based on theCommandLine.Parameters.index()
annotation on the specified field.private static int
parseInt(java.lang.String str, int defaultValue)
private int
size()
java.lang.String
toString()
static CommandLine.Range
valueOf(java.lang.String range)
Leniently parses the specified String as anRange
value and return the result.
-
-
-
Field Detail
-
min
public final int min
Required number of parameters for an option or positional parameter.
-
max
public final int max
Maximum accepted number of parameters for an option or positional parameter.
-
isVariable
public final boolean isVariable
-
isUnspecified
private final boolean isUnspecified
-
originalValue
private final java.lang.String originalValue
-
-
Constructor Detail
-
Range
public Range(int min, int max, boolean variable, boolean unspecified, java.lang.String originalValue)
Constructs a new Range object with the specified parameters.- Parameters:
min
- minimum number of required parametersmax
- maximum number of allowed parameters (or Integer.MAX_VALUE if variable)variable
-true
if any number or parameters is allowed,false
otherwiseunspecified
-true
if no arity was specified on the option/parameter (value is based on type)originalValue
- the original value that was specified on the option or parameter
-
-
Method Detail
-
optionArity
public static CommandLine.Range optionArity(java.lang.reflect.Field field)
Returns a newRange
based on theCommandLine.Option.arity()
annotation on the specified field, or the field type's default arity if no arity was specified.- Parameters:
field
- the field whose Option annotation to inspect- Returns:
- a new
Range
based on the Option arity annotation on the specified field
-
parameterArity
public static CommandLine.Range parameterArity(java.lang.reflect.Field field)
Returns a newRange
based on theCommandLine.Parameters.arity()
annotation on the specified field, or the field type's default arity if no arity was specified.- Parameters:
field
- the field whose Parameters annotation to inspect- Returns:
- a new
Range
based on the Parameters arity annotation on the specified field
-
parameterIndex
public static CommandLine.Range parameterIndex(java.lang.reflect.Field field)
Returns a newRange
based on theCommandLine.Parameters.index()
annotation on the specified field.- Parameters:
field
- the field whose Parameters annotation to inspect- Returns:
- a new
Range
based on the Parameters index annotation on the specified field
-
adjustForType
static CommandLine.Range adjustForType(CommandLine.Range result, java.lang.reflect.Field field)
-
defaultArity
public static CommandLine.Range defaultArity(java.lang.reflect.Field field)
Returns the default arityRange
: foroptions
this is 0 for booleans and 1 for other types, forparameters
booleans have arity 0, arrays or Collections have arity "0..*", and other types have arity 1.- Parameters:
field
- the field whose default arity to return- Returns:
- a new
Range
indicating the default arity of the specified field - Since:
- 2.0
-
defaultArity
public static CommandLine.Range defaultArity(java.lang.Class<?> type)
Returns the default arityRange
foroptions
: booleans have arity 0, other types have arity 1.- Parameters:
type
- the type whose default arity to return- Returns:
- a new
Range
indicating the default arity of the specified type
-
size
private int size()
-
parameterCapacity
static CommandLine.Range parameterCapacity(java.lang.reflect.Field field)
-
valueOf
public static CommandLine.Range valueOf(java.lang.String range)
Leniently parses the specified String as anRange
value and return the result. A range string can be a fixed integer value or a range of the formMIN_VALUE + ".." + MAX_VALUE
. If theMIN_VALUE
string is not numeric, the minimum is zero. If theMAX_VALUE
is not numeric, the range is taken to be variable and the maximum isInteger.MAX_VALUE
.- Parameters:
range
- the value range string to parse- Returns:
- a new
Range
value
-
parseInt
private static int parseInt(java.lang.String str, int defaultValue)
-
min
public CommandLine.Range min(int newMin)
Returns a new Range object with themin
value replaced by the specified value. Themax
of the returned Range is guaranteed not to be less than the newmin
value.- Parameters:
newMin
- themin
value of the returned Range object- Returns:
- a new Range object with the specified
min
value
-
max
public CommandLine.Range max(int newMax)
Returns a new Range object with themax
value replaced by the specified value. Themin
of the returned Range is guaranteed not to be greater than the newmax
value.- Parameters:
newMax
- themax
value of the returned Range object- Returns:
- a new Range object with the specified
max
value
-
contains
public boolean contains(int value)
Returnstrue
if this Range includes the specified value,false
otherwise.- Parameters:
value
- the value to check- Returns:
true
if the specified value is not less than the minimum and not greater than the maximum of this Range
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
compareTo
public int compareTo(CommandLine.Range other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<CommandLine.Range>
-
-