Conditions
| Type | 🔵 Class |
| Package | io.github.mrtesz.teszcore.util |
| GitHub | Conditions.java |
Description
Utility class for validating arguments, states, and values. Throws descriptive exceptions when conditions are not met, similar to Guava’s Preconditions.
Methods
checkArgument
static void checkArgument(boolean argument) throws IllegalArgumentException;
static void checkArgument(boolean argument, String message) throws IllegalArgumentException;
Check a boolean and throw an exception if argument is false
| Parameter | Type | Annotations | Description |
|---|---|---|---|
argument | boolean | - | Argument |
message | String | @Nullable | Message in the exception, if thrown |
Throws: IllegalArgumentException when argument is false
checkRange
static <T extends Number> T checkRange(T num, T min, T max) throws IllegalNumberRangeException;
static <T extends Number> T checkRange(T num, T min, T max, String message) throws IllegalNumberRangeException;
Check if a number is in a range and throw an exception if it’s not
| Parameter | Type | Annotations | Description |
|---|---|---|---|
num | T | - | Number to check |
min | T | - | Range minimum |
max | T | - | Range maximum |
message | String | @Nullable | Message in the exception, if thrown |
Returns: T - num
Throws: IllegalNumberRangeException when num is not in the provided range
checkState
static void checkState(boolean state) throws IllegalStateException;
static void checkState(boolean state, String message) throws IllegalStateException;
Check a boolean and throw an exception if it is false
| Parameter | Type | Annotations | Description |
|---|---|---|---|
state | boolean | - | State |
message | String | @Nullable | Message in the exception, if thrown |
Throws: IllegalStateException when state is false
checkNonNull
static <T> T checkNonNull(T obj) throws NullPointerException;
static <T> T checkNonNull(T obj, String message) throws NullPointerException;
Check if an object not null
| Parameter | Type | Annotations | Description |
|---|---|---|---|
obj | boolean | - | Object |
message | String | @Nullable | Message in the exception, if thrown |
Returns: T - obj
Throws: NullPointerException when obj is null
checkNull
static <T> void checkNull(T obj) throws NotNullException;
static <T> void checkNull(T obj, String message) throws NotNullException;
Check if an object is not null
| Parameter | Type | Annotations | Description |
|---|---|---|---|
obj | boolean | - | Object |
message | String | @Nullable | Message in the exception, if thrown |
Throws: NotNullException when obj is not null