forked from airlift/airline
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- @positive and @Negative - @ExactLength and @LengthRange - Reorganise nav for restriction annotations to be clearer
- Loading branch information
Showing
6 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
layout: page | ||
title: ExactLength Annotation | ||
--- | ||
|
||
## `@ExactLength` | ||
|
||
The `@ExactLength` annotation may be applied to fields annotated with [`@Option`](option.html) and [`@Arguments`](arguments.html) to limit the length of the value provided to a specific length e.g. | ||
|
||
```java | ||
@Option(name = "--reference", arity = 1) | ||
@MaxLength(length = 10) | ||
private String reference; | ||
``` | ||
|
||
Restricts the `--reference` option to values of exactly 10 characters. | ||
|
||
### Related Annotations | ||
|
||
If you want to restrict the minimum/maximum length of a value then use the [`@MinLength`](min-length.html) or [`@MaxLength`](max-length) annotations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
layout: page | ||
title: LengthRange Annotation | ||
--- | ||
|
||
## `@LengthRange` | ||
|
||
The `@LengthRange` annotation may be applied to fields annotated with [`@Option`](option.html) and [`@Arguments`](arguments.html) to limit the length of values that an option may be used with to a range of lengths e.g. | ||
|
||
```java | ||
@Option(name = "--reference", arity = 1) | ||
@LengthRange(min = 5, max = 10) | ||
private String reference; | ||
``` | ||
This specifies that the `--reference` option only allows values with lengths of 5 to 10 characters to be specified by the user. Any other length value will be rejected. | ||
|
||
### Related Annotations | ||
|
||
If you have an exact length to enforce then you should use the [`@ExactLength`](exact-length.html) annotation. If you want to restrict just the minimum/maximum length of a value then use the [`@MinLength`](min-length.html) or [`@MaxLength`](max-length) annotations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
layout: page | ||
title: Positive and Negative Annotations | ||
--- | ||
|
||
## `@Positive` | ||
|
||
The `@Positive` annotation is applied to numerically typed fields to indicate that their values must be a positive number e.g. | ||
|
||
```java | ||
@Option(name = "-i", title = "Integer", arity = 1) | ||
@Positive | ||
public long i; | ||
``` | ||
|
||
Here the `-i` option must take a positive value. | ||
|
||
### Treatment of Zero | ||
|
||
By default zero is considered a positive number, if you do not want this to be the case you can add `includesZero = false` to your annotation e.g. | ||
|
||
```java | ||
@Option(name = "-i", title = "Integer", arity = 1) | ||
@Positive(includesZero = false) | ||
public long i; | ||
``` | ||
|
||
## `@Negative` | ||
|
||
`@Negative` is the opposite of `@Positive`, it is applied to numeric fields to indicate that their values must be a negative number e.g. | ||
|
||
```java | ||
@Option(name = "-i", title = "Integer", arity = 1) | ||
@Negative | ||
public long i; | ||
``` | ||
|
||
Here the `-i` option must take a negative value. | ||
|
||
### Treatment of Zero | ||
|
||
By default zero is considered a positive number, if you want to treat it as a negative number you can add `includesZero = true` to your annotation e.g. | ||
|
||
```java | ||
@Option(name = "-i", title = "Integer", arity = 1) | ||
@Negative(includesZero = true) | ||
public long i; | ||
``` | ||
|
||
### Related Annotations | ||
|
||
For more specific value ranges on numeric fields use the various numeric range annotations - [`@ByteRange`](byte-range.html), [`@ShortRange`](short-range.html), [`@IntegerRange`](integer-range.html), [`@LongRange`](long-range.html), [`@FloatRange`](float-range.html) and [`@DoubleRange`](double-range.html) - to specify desired minimum and maximum values. | ||
|
||
For limiting numeric fields to small sets of values consider the [`@AllowedValues`](allowed-values.html) annotation. |