@FloatRange
The @FloatRange
annotation may be applied to fields annotated with @Option
and @Arguments
to limit the set of values that an option may be used with to a range of float
values e.g.
@Option(name = "--opacity", title = "Opacity", description = "Desired opacity")
@FloatRange(min = 0.0, minInclusive = true, max = 1.0, maxInclusive = true)
public float opacity;
This specifies that the --opacity
option only allows values in the range 0.0
through 1.0
to be specified by the user. Any other value will be rejected.
The minInclusive
and maxInclusive
fields of the annotation specify whether the given min
and max
are included in the range or not.
The min
and max
automatically default to the minimum and maximum for the corresponding type e.g. Float.MAX_VALUE
so there is no need to specify these explicitly if you simply wish to specify a minimum or maximum value only.
For other numeric types there are equivalent range restriction annotations: @ByteRange
, @DoubleRange
, @IntegerRange
, @LongRange
and @ShortRange
. There is also a @LexicalRange
for string ranges.
If there is a set of non-contiguous values that should be considered acceptable then use the @AllowedValues
annotation instead.
For more complex value restrictions a regular expression based restriction using @Pattern
might be appropriate.
This documentation is itself open source and lives in GitHub under the docs/ directory.
I am not a professional technical writer and as the developer of this software I can often make assumptions of
knowledge that you as a user reading this may not have. Improvements to the documentation are always welcome, if you
have suggestions for the documentation please submit pull requests to the main
branch.