Package picocli
Class CommandLine.Range
java.lang.Object
picocli.CommandLine.Range
- All Implemented Interfaces:
Comparable<CommandLine.Range>
- Enclosing class:
CommandLine
Describes the number of parameters required and accepted by an option or a positional parameter.
- Since:
- 0.9.7
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static CommandLine.Range
adjustForType
(CommandLine.Range result, CommandLine.Model.IAnnotatedElement member) (package private) int
anchor()
int
compareTo
(CommandLine.Range other) boolean
contains
(int value) Returnstrue
if this Range includes the specified value,false
otherwise.static CommandLine.Range
defaultArity
(Class<?> type) Deprecated.usedefaultArity(Field)
insteadstatic CommandLine.Range
defaultArity
(Field field) Returns the default arityRange
: for interactive options/positional parameters, this is 0; foroptions
this is effectively "0..1" for booleans and 1 for other types, forparameters
booleans have arity 1, arrays or Collections have arity "0..*", and other types have arity 1.private static CommandLine.Range
private static CommandLine.Range
boolean
int
hashCode()
(package private) String
Returns equivalent offormat("%s (%s)", originalValue, toString())
.boolean
Returnstrue
if this Range contains a relative index like"1+"
, orfalse
if this Range does not contain any relative indices.(package private) boolean
boolean
Returnstrue
if this range contains a relative index like"1+"
, or variables that have not been expanded yet,false
if this Range does not contain any variables or relative indices.boolean
Returnstrue
if this Range is a default value,false
if the user specified this value.(package private) boolean
Returns true for these ranges: 0 and 0..1.boolean
Returnstrue
if this range has no fixed upper bound.int
max()
Returns the upper bound of this range (inclusive), orInteger.MAX_VALUE
if this range has no upper bound.max
(int newMax) Returns a new Range object with themax
value replaced by the specified value.int
min()
Returns the lower bound of this range (inclusive).min
(int newMin) Returns a new Range object with themin
value replaced by the specified value.static CommandLine.Range
optionArity
(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.private static CommandLine.Range
Returns the original String value that this range was constructed with.(package private) boolean
overlaps
(CommandLine.Range index) static CommandLine.Range
parameterArity
(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.private static CommandLine.Range
(package private) static CommandLine.Range
private static CommandLine.Range
parameterCapacity
(CommandLine.Range arity, CommandLine.Range index) static CommandLine.Range
parameterIndex
(Field field) Returns a newRange
based on theCommandLine.Parameters.index()
annotation on the specified field.private static CommandLine.Range
private static int
private int
size()
toString()
unspecified
(boolean unspecified) Returns a new Range object with theisUnspecified
value replaced by the specified value.static CommandLine.Range
Leniently parses the specified String as aRange
value and return the result.
-
Field Details
-
min
Deprecated.usemin()
instead -
max
Deprecated.usemax()
instead -
isVariable
Deprecated.useisVariable()
instead -
isUnspecified
private final boolean isUnspecified -
originalValue
-
relative
private final boolean relative -
anchor
private final int anchor
-
-
Constructor Details
-
Range
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 Details
-
optionArity
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
-
optionArity
-
parameterArity
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
-
parameterArity
-
parameterIndex
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
-
parameterIndex
-
defaultParameterIndex
-
adjustForType
static CommandLine.Range adjustForType(CommandLine.Range result, CommandLine.Model.IAnnotatedElement member) -
defaultArity
Returns the default arityRange
: for interactive options/positional parameters, this is 0; foroptions
this is effectively "0..1" for booleans and 1 for other types, forparameters
booleans have arity 1, arrays or Collections have arity "0..*", and other types have arity 1.Implementation Notes
The returned
Range
for boolean options has an effective arity of "0..1". This is implemented by returning aRange
with arity "0", and itsunspecified
property set totrue
. This implementation may change in the future.- 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
-
defaultArity
Deprecated.usedefaultArity(Field)
insteadReturns 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
-
parameterCapacity
private static CommandLine.Range parameterCapacity(CommandLine.Range arity, CommandLine.Range index) -
valueOf
Leniently parses the specified String as aRange
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
-
min
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
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
-
unspecified
Returns a new Range object with theisUnspecified
value replaced by the specified value.- Parameters:
unspecified
- theunspecified
value of the returned Range object- Returns:
- a new Range object with the specified
unspecified
value
-
isUnspecified
public boolean isUnspecified()Returnstrue
if this Range is a default value,false
if the user specified this value.- Since:
- 4.0
-
isUnresolved
public boolean isUnresolved()Returnstrue
if this range contains a relative index like"1+"
, or variables that have not been expanded yet,false
if this Range does not contain any variables or relative indices.- Since:
- 4.0
-
isRelative
public boolean isRelative()Returnstrue
if this Range contains a relative index like"1+"
, orfalse
if this Range does not contain any relative indices.- Since:
- 4.3
-
anchor
int anchor()- Returns:
1
for a relative index like"1+"
, orInteger.MAX_VALUE
for a relative index without an anchor, like"+"
- Since:
- 4.3
-
isRelativeToAnchor
boolean isRelativeToAnchor() -
originalValue
Returns the original String value that this range was constructed with.- Since:
- 4.3
-
min
public int min()Returns the lower bound of this range (inclusive).- Since:
- 4.0
-
max
public int max()Returns the upper bound of this range (inclusive), orInteger.MAX_VALUE
if this range has no upper bound.- Since:
- 4.0
-
isVariable
public boolean isVariable()Returnstrue
if this range has no fixed upper bound.- Since:
- 4.0
-
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
-
hashCode
public int hashCode() -
toString
-
internalToString
String internalToString()Returns equivalent offormat("%s (%s)", originalValue, toString())
. -
compareTo
- Specified by:
compareTo
in interfaceComparable<CommandLine.Range>
-
isValidForInteractiveArgs
boolean isValidForInteractiveArgs()Returns true for these ranges: 0 and 0..1. -
overlaps
-
isVariable()
instead