Skip to content

Commit

Permalink
Document new annotations (#73,#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvesse committed Oct 22, 2018
1 parent 618e1de commit 54a3eec
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/_includes/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/min-length.html">@MinLength</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/not-blank.html">@NotBlank</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/not-empty.html">@NotEmpty</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/path.html">@Path</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/pattern.html">@Pattern</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/starts-with.html">@StartsWith</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/ends-with.html">@EndsWith</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/path.html">@Path, @File and @Directory</a></li>
<li><a class="sidebar-nav-item" href="{{ site.baseurl }}/guide/annotations/port.html">@Port and @PortRange</a></li>
</ul>
</li>
Expand Down
32 changes: 32 additions & 0 deletions docs/guide/annotations/ends-with.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: page
title: EndsWith Annotation
---

## `@EndsWith`

The `@EndsWith` annotation can be used to require that values given end with a given suffix. For example:

```java
@Option(name = "--images")
@EndsWith(suffixes = { ".jpg", ".png", ".gif" })
public List<String> images = new ArrayList<>();
```

Here the `--images` option requires that any image given ends with one of the file extensions `.jpg`, `.png` or `.gif`

### Case Sensitivity

Optionally you can make the prefixes case insensitive by setting the `ignoreCase` field to `true` and also specifying a `locale` if needed:

```java
@Option(name = "--images")
@EndsWith(ignoreCase = true, locale = "en", suffixes = { ".jpg", ".png", ".gif" })
public List<String> images = new ArrayList<>();
```

When declared like this the suffixes and any values given for the option will first be lower cased in the given locale before being compared.

### Related Annotations

If you have a prefixes you need to enforce then use the [`@StartsWith`](starts-with.html) annotation. For more complex string value enforcement you can also use the regular expression based [`@Pattern`](pattern.html) annotation.
12 changes: 11 additions & 1 deletion docs/guide/annotations/path.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: page
title: Path Annotation
title: Path, File and Directory Annotations
---

## `@Path`
Expand Down Expand Up @@ -49,3 +49,13 @@ public String writable;
public String executable;
```
In the above examples we use the `readable`, `writable` and `executable` fields of the annotation to specify the access modes that the path must support.

## `@File` and `@Directory`

These annotations function the same as the above described `@Path` annotation except that the `kind` field is not available since it is implied by the name of the annotation.

So `@File` functions the same as `@Path(kind = PathKind.FILE)` and `@Directory` the same as `@Path(kind = PathKind.DIRECTORY)`

### Related Annotations

For enforcing certain file extensions the [`@EndsWith`](ends-with.html) annotation may be useful.
4 changes: 3 additions & 1 deletion docs/guide/annotations/pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ Requires that the option meet the regular expression case insensitively i.e. `FO

To restrict values to specific sets of values it is likely more efficient to use the [`@AllowedRawValues`](allowed-raw-values.html) or [`@AllowedValues`](allowed-values.html) annotations.

To place simple string related restrictions some combination of [`@NotBlank`](not-blank.html), [`@NotEmpty`](not-empty.html), [`@MaxLength`](max-length.html) and [`@MinLength`](min-length.html) may also be useful.
To place simple string related restrictions some combination of [`@NotBlank`](not-blank.html), [`@NotEmpty`](not-empty.html), [`@MaxLength`](max-length.html) and [`@MinLength`](min-length.html) may also be useful.

For simple prefix/suffix constraints you can use the [`@StartsWith`](starts-with.html) and [`@EndsWith`](ends-with.html) annotations.
31 changes: 31 additions & 0 deletions docs/guide/annotations/starts-with.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
layout: page
title: StartsWith Annotation
---

## `@StartsWith`

The `@StartsWith` annotation can be used to require that values given start with a given prefix. For example:

```java
@Option(name = "--urls")
@StartsWith(prefixes = { "http", "https", "ftp" })
public List<String> urls = new ArrayList<>();
```
Here the `--urls` option requires that any URL given starts with one of `http`, `https` or `ftp`

### Case Sensitivity

Optionally you can make the prefixes case insensitive by setting the `ignoreCase` field to `true` and also specifying a `locale` if needed:

```java
@Option(name = "--urls")
@StartsWith(ignoreCase = true, locale = "en", prefixes = { "http", "https", "ftp" })
public List<String> urls = new ArrayList<>();
```

When declared like this the prefixes and any values given for the option will first be lower cased in the given locale before being compared.

### Related Annotations

If you have a suffixes you need to enforce then use the [`@EndsWith`](ends-with.html) annotation. For more complex string value enforcement you can also use the regular expression based [`@Pattern`](pattern.html) annotation.

0 comments on commit 54a3eec

Please sign in to comment.