https://github.com/ilubenets/require
Lightweight assertion library with predefined messages
https://github.com/ilubenets/require
assert java-8 precondition
Last synced: 10 months ago
JSON representation
Lightweight assertion library with predefined messages
- Host: GitHub
- URL: https://github.com/ilubenets/require
- Owner: iLubenets
- License: apache-2.0
- Created: 2018-02-21T16:43:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T09:38:52.000Z (almost 4 years ago)
- Last Synced: 2024-04-14T19:19:45.440Z (over 1 year ago)
- Topics: assert, java-8, precondition
- Language: Java
- Homepage:
- Size: 99.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# require
Lightweight assertion library with predefined messages.
[CHANGELOG.md](/CHANGELOG.md)
## Methods
All methods produce exception **IllegalArgumentException** in the case if statement false. All methods return given
value back without any modifications.
| Method | Description |
|---------------------------|-----------------------------|
| Require.nonNull | Check if value is not null. |
| Require.nonBlank | Check if value is not null and not blank, contains any character different from whitespace |
| Require.nonEmpty | Check if string or collection is not null and not empty |
| Require.length | Check if value is not null and has length between minLength and maxLength |
| Require.maxLength | Check if value is not null and has length between 0 and maxLength |
| Require.minLength | Check if value is not null and has length more then minLength |
| Require.nonBlankMaxLength | Check if value is not blank and has length between 1 and maxLength |
| Require.format | Check if value is not null and has match regexp pattern format |
| Require.positive | Check if numeric value is not null and positive |
| Require.negative | Check if numeric value is not null and negative |
| Require.gtThanZero | Check if numeric is not null and grate than 0 |
| Require.lsThanZero | Check if numeric is not null and less than 0 |
## Example
```
public final class RequestId {
private final String value;
public RequestId(@Nullable final String value) {
this.value = Require.nonBlank(value, "requestId");
}
@Nonnull
public String value() {
return value;
}
}
```
## Usage
Library is available on [MavenCentral](https://search.maven.org/artifact/com.github.ilubenets/require).
Apache Maven:
```
com.github.ilubenets
require
1.3
```
Gradle Groovy DSL:
```
dependencies {
implementation 'com.github.ilubenets:require:1.3'
}
```