LongRange Annotation

@LongRange

The @LongRange 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 long values e.g.

@Option(name = "--birth-year", title = "Birth Year", description = "Year of Birth")
@IntegerRange(min = 1900, minInclusive = true, max = 2018, maxInclusive = true)
public long birthYear;

This specifies that the --birth-year option only allows values in the range 1900 through 2018 to be specified by the user. Any other value will be rejected.

Advanced Ranges

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. Long.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, @FloatRange, @IntegerRange 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.


Improving this Documentation

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.