Java Checks (or Checks
) is a Java utility that provides a set of static utility methods for performing common checks
and validations throughout your code, improving code readability while also takes a more functional approach to
such validations allowing for more flexibility.
Java 11+ and Java 21+ versions are available.
Checks
can be considered as a (stand-alone) alternative to Google Guava's Preconditions
or Apache Commons Lang's
Validate
that can be used generally everywhere.
- Boolean expression checks (state or argument checks);
- Null/not-null checks;
- Object equality checks;
- Empty/not-empty checks for strings, collections, maps and arrays;
- Provide custom exception types through functional interfaces.
See Javadocs for a full list of available methods.
// This...
if (!expression)
throw new IllegalArgumentException("Expression is false");
// can be replaced with...
Checks.check(expression, "Expression is false");
// And this...
if (obj == null)
throw new IllegalArgumentException("Object is null");
// can be replaced with...
Checks.isNotNull(obj, "Object is null");
// This...
if (object == null)
throw new IllegalStateException("Object is null");
// can be replaced with...
Checks.checkState(object != null, "Object is null");
// or...
Checks.check(object != null, IllegalStateException::new, "Object is null");
<repository>
<id>greenadine-releases</id>
<url>https://repo.greenadine.dev/releases/</url>
</repository>
<dependency>
<groupId>dev.greenadine</groupId>
<artifactId>checks</artifactId>
<version>1.0.0-21</version>
</dependency>
<dependency>
<groupId>dev.greenadine</groupId>
<artifactId>checks</artifactId>
<version>1.0.0-11</version>
</dependency>
This project is licensed under the GNU Lesser General Public License v3.0. See the license file for details.