Package picocli
Class CommandLine.Range
- java.lang.Object
-
- 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 intanchorprivate booleanisUnspecifiedbooleanisVariableDeprecated.useisVariable()insteadintmaxDeprecated.usemax()insteadintminDeprecated.usemin()insteadprivate java.lang.StringoriginalValueprivate booleanrelative
-
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 Deprecated Methods Modifier and Type Method Description (package private) static CommandLine.RangeadjustForType(CommandLine.Range result, CommandLine.Model.IAnnotatedElement member)(package private) intanchor()intcompareTo(CommandLine.Range other)booleancontains(int value)Returnstrueif this Range includes the specified value,falseotherwise.static CommandLine.RangedefaultArity(java.lang.Class<?> type)Deprecated.usedefaultArity(Field)insteadstatic CommandLine.RangedefaultArity(java.lang.reflect.Field field)Returns the default arityRange: for interactive options/positional parameters, this is 0; foroptionsthis is 0 for booleans and 1 for other types, forparametersbooleans have arity 0, arrays or Collections have arity "0..*", and other types have arity 1.private static CommandLine.RangedefaultArity(CommandLine.Model.IAnnotatedElement member)private static CommandLine.RangedefaultParameterIndex(CommandLine.Model.ITypeInfo typeInfo)booleanequals(java.lang.Object object)inthashCode()(package private) java.lang.StringinternalToString()Returns equivalent offormat("%s (%s)", originalValue, toString()).booleanisRelative()Returnstrueif this Range contains a relative index like"1+", orfalseif this Range does not contain any relative indices.(package private) booleanisRelativeToAnchor()booleanisUnresolved()Returnstrueif this range contains a relative index like"1+", or variables that have not been expanded yet,falseif this Range does not contain any variables or relative indices.booleanisUnspecified()Returnstrueif this Range is a default value,falseif the user specified this value.(package private) booleanisValidForInteractiveArgs()Returns true for these ranges: 0 and 0..1.booleanisVariable()Returnstrueif this range has no fixed upper bound.intmax()Returns the upper bound of this range (inclusive), orInteger.MAX_VALUEif this range has no upper bound.CommandLine.Rangemax(int newMax)Returns a new Range object with themaxvalue replaced by the specified value.intmin()Returns the lower bound of this range (inclusive).CommandLine.Rangemin(int newMin)Returns a new Range object with theminvalue replaced by the specified value.static CommandLine.RangeoptionArity(java.lang.reflect.Field field)Returns a newRangebased on theCommandLine.Option.arity()annotation on the specified field, or the field type's default arity if no arity was specified.private static CommandLine.RangeoptionArity(CommandLine.Model.IAnnotatedElement member)java.lang.StringoriginalValue()Returns the original String value that this range was constructed with.(package private) booleanoverlaps(CommandLine.Range index)static CommandLine.RangeparameterArity(java.lang.reflect.Field field)Returns a newRangebased on theCommandLine.Parameters.arity()annotation on the specified field, or the field type's default arity if no arity was specified.private static CommandLine.RangeparameterArity(CommandLine.Model.IAnnotatedElement member)(package private) static CommandLine.RangeparameterCapacity(CommandLine.Model.IAnnotatedElement member)private static CommandLine.RangeparameterCapacity(CommandLine.Range arity, CommandLine.Range index)static CommandLine.RangeparameterIndex(java.lang.reflect.Field field)Returns a newRangebased on theCommandLine.Parameters.index()annotation on the specified field.private static CommandLine.RangeparameterIndex(CommandLine.Model.IAnnotatedElement member)private static intparseInt(java.lang.String str, int defaultValue)private intsize()java.lang.StringtoString()CommandLine.Rangeunspecified(boolean unspecified)Returns a new Range object with theisUnspecifiedvalue replaced by the specified value.static CommandLine.RangevalueOf(java.lang.String range)Leniently parses the specified String as aRangevalue and return the result.
-
-
-
Field Detail
-
min
@Deprecated public final int min
Deprecated.usemin()instead
-
max
@Deprecated public final int max
Deprecated.usemax()instead
-
isVariable
@Deprecated public final boolean isVariable
Deprecated.useisVariable()instead
-
isUnspecified
private final boolean isUnspecified
-
originalValue
private final java.lang.String originalValue
-
relative
private final boolean relative
-
anchor
private final int anchor
-
-
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-trueif any number or parameters is allowed,falseotherwiseunspecified-trueif 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 newRangebased 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
Rangebased on the Option arity annotation on the specified field
-
optionArity
private static CommandLine.Range optionArity(CommandLine.Model.IAnnotatedElement member)
-
parameterArity
public static CommandLine.Range parameterArity(java.lang.reflect.Field field)
Returns a newRangebased 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
Rangebased on the Parameters arity annotation on the specified field
-
parameterArity
private static CommandLine.Range parameterArity(CommandLine.Model.IAnnotatedElement member)
-
parameterIndex
public static CommandLine.Range parameterIndex(java.lang.reflect.Field field)
Returns a newRangebased on theCommandLine.Parameters.index()annotation on the specified field.- Parameters:
field- the field whose Parameters annotation to inspect- Returns:
- a new
Rangebased on the Parameters index annotation on the specified field
-
parameterIndex
private static CommandLine.Range parameterIndex(CommandLine.Model.IAnnotatedElement member)
-
defaultParameterIndex
private static CommandLine.Range defaultParameterIndex(CommandLine.Model.ITypeInfo typeInfo)
-
adjustForType
static CommandLine.Range adjustForType(CommandLine.Range result, CommandLine.Model.IAnnotatedElement member)
-
defaultArity
public static CommandLine.Range defaultArity(java.lang.reflect.Field field)
Returns the default arityRange: for interactive options/positional parameters, this is 0; foroptionsthis is 0 for booleans and 1 for other types, forparametersbooleans 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
Rangeindicating the default arity of the specified field - Since:
- 2.0
-
defaultArity
private static CommandLine.Range defaultArity(CommandLine.Model.IAnnotatedElement member)
-
defaultArity
@Deprecated public static CommandLine.Range defaultArity(java.lang.Class<?> type)
Deprecated.usedefaultArity(Field)insteadReturns the default arityRangeforoptions: booleans have arity 0, other types have arity 1.- Parameters:
type- the type whose default arity to return- Returns:
- a new
Rangeindicating the default arity of the specified type
-
size
private int size()
-
parameterCapacity
static CommandLine.Range parameterCapacity(CommandLine.Model.IAnnotatedElement member)
-
parameterCapacity
private static CommandLine.Range parameterCapacity(CommandLine.Range arity, CommandLine.Range index)
-
valueOf
public static CommandLine.Range valueOf(java.lang.String range)
Leniently parses the specified String as aRangevalue and return the result. A range string can be a fixed integer value or a range of the formMIN_VALUE + ".." + MAX_VALUE. If theMIN_VALUEstring is not numeric, the minimum is zero. If theMAX_VALUEis 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
Rangevalue
-
parseInt
private static int parseInt(java.lang.String str, int defaultValue)
-
min
public CommandLine.Range min(int newMin)
Returns a new Range object with theminvalue replaced by the specified value. Themaxof the returned Range is guaranteed not to be less than the newminvalue.- Parameters:
newMin- theminvalue of the returned Range object- Returns:
- a new Range object with the specified
minvalue
-
max
public CommandLine.Range max(int newMax)
Returns a new Range object with themaxvalue replaced by the specified value. Theminof the returned Range is guaranteed not to be greater than the newmaxvalue.- Parameters:
newMax- themaxvalue of the returned Range object- Returns:
- a new Range object with the specified
maxvalue
-
unspecified
public CommandLine.Range unspecified(boolean unspecified)
Returns a new Range object with theisUnspecifiedvalue replaced by the specified value.- Parameters:
unspecified- theunspecifiedvalue of the returned Range object- Returns:
- a new Range object with the specified
unspecifiedvalue
-
isUnspecified
public boolean isUnspecified()
Returnstrueif this Range is a default value,falseif the user specified this value.- Since:
- 4.0
-
isUnresolved
public boolean isUnresolved()
Returnstrueif this range contains a relative index like"1+", or variables that have not been expanded yet,falseif this Range does not contain any variables or relative indices.- Since:
- 4.0
-
isRelative
public boolean isRelative()
Returnstrueif this Range contains a relative index like"1+", orfalseif this Range does not contain any relative indices.- Since:
- 4.3
-
anchor
int anchor()
- Returns:
1for a relative index like"1+", orInteger.MAX_VALUEfor a relative index without an anchor, like"+"- Since:
- 4.3
-
isRelativeToAnchor
boolean isRelativeToAnchor()
-
originalValue
public java.lang.String 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_VALUEif this range has no upper bound.- Since:
- 4.0
-
isVariable
public boolean isVariable()
Returnstrueif this range has no fixed upper bound.- Since:
- 4.0
-
contains
public boolean contains(int value)
Returnstrueif this Range includes the specified value,falseotherwise.- Parameters:
value- the value to check- Returns:
trueif 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
internalToString
java.lang.String internalToString()
Returns equivalent offormat("%s (%s)", originalValue, toString()).
-
compareTo
public int compareTo(CommandLine.Range other)
- Specified by:
compareToin interfacejava.lang.Comparable<CommandLine.Range>
-
isValidForInteractiveArgs
boolean isValidForInteractiveArgs()
Returns true for these ranges: 0 and 0..1.
-
overlaps
boolean overlaps(CommandLine.Range index)
-
-