Skip to content

Package io.github.qishr.cascara.common.util

Class Range

java.lang.Object
        io.github.qishr.cascara.common.util.CommandLine.Range

All Implemented Interfaces:
    Comparable<Range>

Enclosing Class:
    io.github.qishr.cascara.common.util.CommandLine


public static class Range

Describes the number of parameters required and accepted by an option or a positional parameter.

Field Summary

Modifier and Type Field Description
public final boolean isVariable
public final int max
public final int min

Constructor Summary

Constructor Description
Range(int min, int max, boolean variable, boolean unspecified, String originalValue) Constructs a new Range object with the specified parameters.

Method Summary

Modifier and Type Method Description
public static Range optionArity(Field field) Returns a new Range based on the Option#arity() annotation on the specified field, or the field type's default arity if no arity was specified.
public static Range parameterArity(Field field) Returns a new Range based on the Parameters#arity() annotation on the specified field, or the field type's default arity if no arity was specified.
public static Range parameterIndex(Field field) Returns a new Range based on the Parameters#index() annotation on the specified field.
public static Range defaultArity(Field field) Returns the default arity Range: for interactive options/positional parameters, this is 0; for Option this is effectively "0..1" for booleans and 1 for other types, for Parameters booleans have arity 1, arrays or Collections have arity "0..*", and other types have arity 1.
public static Range defaultArity(Class<?> type) Returns the default arity Range for Option: booleans have arity 0, other types have arity 1.
public static Range valueOf(String range) Leniently parses the specified String as a Range value and return the result.
public Range min(int newMin) Returns a new Range object with the min value replaced by the specified value.
public Range max(int newMax) Returns a new Range object with the max value replaced by the specified value.
public Range unspecified(boolean unspecified) Returns a new Range object with the isUnspecified value replaced by the specified value.
public boolean isUnspecified() Returns true if this Range is a default value, false if the user specified this value.
public boolean isUnresolved() Returns true 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.
public boolean isRelative() Returns true if this Range contains a relative index like "1+", or false if this Range does not contain any relative indices.
public String originalValue() Returns the original String value that this range was constructed with.
public int min() Returns the lower bound of this range (inclusive).
public int max() Returns the upper bound of this range (inclusive), or Integer.MAX_VALUE if this range has isVariable.isVariable.
public boolean isVariable() Returns true if this range has no fixed upper bound.
public boolean contains(int value) Returns true if this Range includes the specified value, false otherwise.
public boolean equals(Object object)
public int hashCode()
public String toString()
public int compareTo(Range other)

Field Details

isVariable

public final boolean isVariable

Deprecation

use isVariable.isVariable instead


max

public final int max

Deprecation

use max.max instead


min

public final int min

Deprecation

use min.min instead


Method Details

optionArity

public static Range optionArity(Field field)

Returns a new Range based on the 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 Range parameterArity(Field field)

Returns a new Range based on the 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 Range parameterIndex(Field field)

Returns a new Range based on the 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


defaultArity

public static Range defaultArity(Field field)

Returns the default arity Range: for interactive options/positional parameters, this is 0; for Option this is effectively "0..1" for booleans and 1 for other types, for Parameters 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 a Range with arity "0", and its unspecified property set to true. 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

public static Range defaultArity(Class<?> type)

Returns the default arity Range for Option: booleans have arity 0, other types have arity 1.

Deprecation

use defaultArity.defaultArity instead

Parameters:

type - the type whose default arity to return

Returns:

a new Range indicating the default arity of the specified type


valueOf

public static Range valueOf(String range)

Leniently parses the specified String as a Range value and return the result.A range string can be a fixed integer value or a range of the form MIN_VALUE + ".." + MAX_VALUE. If the MIN_VALUE string is not numeric, the minimum is zero. If the MAX_VALUE is not numeric, the range is taken to be variable and the maximum is Integer.MAX_VALUE.

Parameters:

range - the value range string to parse

Returns:

a new Range value


min

public Range min(int newMin)

Returns a new Range object with the min value replaced by the specified value.The max of the returned Range is guaranteed not to be less than the new min value.

Parameters:

newMin - the min value of the returned Range object

Returns:

a new Range object with the specified min value


max

public Range max(int newMax)

Returns a new Range object with the max value replaced by the specified value.The min of the returned Range is guaranteed not to be greater than the new max value.

Parameters:

newMax - the max value of the returned Range object

Returns:

a new Range object with the specified max value


unspecified

public Range unspecified(boolean unspecified)

Returns a new Range object with the isUnspecified value replaced by the specified value.

Parameters:

unspecified - the unspecified value of the returned Range object

Returns:

a new Range object with the specified unspecified value


isUnspecified

public boolean isUnspecified()

Returns true if this Range is a default value, false if the user specified this value.

Since:

4.0


isUnresolved

public boolean isUnresolved()

Returns true 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()

Returns true if this Range contains a relative index like "1+", or false if this Range does not contain any relative indices.

Since:

4.3


originalValue

public 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), or Integer.MAX_VALUE if this range has isVariable.isVariable.

Since:

4.0


isVariable

public boolean isVariable()

Returns true if this range has no fixed upper bound.

Since:

4.0


contains

public boolean contains(int value)

Returns true 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(Object object)


hashCode

public int hashCode()


toString

public String toString()


compareTo

public int compareTo(Range other)