Require assertions

Lightweight assertion library for different java types and structures checks with predefined human friendly messages

License

License

Categories

Categories

Net
GroupId

GroupId

com.github.ilubenets
ArtifactId

ArtifactId

require
Last Version

Last Version

1.4
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Require assertions
Lightweight assertion library for different java types and structures checks with predefined human friendly messages
Project URL

Project URL

https://github.com/iLubenets/require/
Source Code Management

Source Code Management

https://github.com/iLubenets/require/

Download require

Dependencies

runtime (1)

Group / Artifact Type Version
com.google.code.findbugs : jsr305 jar 3.0.2

Project Modules

There are no modules declared in this project.

require

Lightweight assertion library with predefined messages.

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.

Apache Maven:

<dependency>
  <groupId>com.github.ilubenets</groupId>
  <artifactId>require</artifactId>
  <version>1.3</version>
</dependency>

Gradle Groovy DSL:

dependencies {
    implementation 'com.github.ilubenets:require:1.3'
}

Versions

Version
1.4
1.3