Package io.github.mrtesz.teszcore.util
Class Conditions
java.lang.Object
io.github.mrtesz.teszcore.util.Conditions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArgument(boolean argument) Throw an error if the provided argument is `false`static voidcheckArgument(boolean argument, @Nullable String message) Throw an error if the provided argument is `false`static <T> TcheckNonNull(T obj) Check if an object is not `null` and throw an exception if it isstatic <T> TcheckNonNull(T obj, @Nullable String message) Check if an object is not `null` and throw an exception if it isstatic <T> voidcheckNull(T obj) Check if an object is `null` and throw an exception if it isstatic <T> voidCheck if an object is `null` and throw an exception if it isstatic <T extends Number>
TcheckRange(T num, T min, T max) Check if a number is in a range and throw an exception if notstatic <T extends Number>
TcheckRange(T num, T min, T max, @Nullable String message) Check if a number is in a range and throw an exception if notstatic voidcheckState(boolean state) Check a `boolean` and throw an exception if it is `false`static voidcheckState(boolean state, @Nullable String message) Check a `boolean` and throw an exception if it is `false`
-
Constructor Details
-
Conditions
public Conditions()
-
-
Method Details
-
checkArgument
Throw an error if the provided argument is `false`- Parameters:
argument- argument- Throws:
IllegalArgumentException- ifargumentis `false`
-
checkArgument
public static void checkArgument(boolean argument, @Nullable @Nullable String message) throws IllegalArgumentException Throw an error if the provided argument is `false`- Parameters:
argument- argumentmessage- message in the exception, when thrown- Throws:
IllegalArgumentException- ifargumentis `false`
-
checkRange
public static <T extends Number> T checkRange(T num, T min, T max) throws IllegalNumberRangeException Check if a number is in a range and throw an exception if not- Parameters:
num- Number to checkmin- Range minimummax- Range maximum- Returns:
- the provided `num`
- Throws:
IllegalNumberRangeException- ifnumis lower thanminor higher thenmax
-
checkRange
public static <T extends Number> T checkRange(T num, T min, T max, @Nullable @Nullable String message) throws IllegalNumberRangeException Check if a number is in a range and throw an exception if not- Parameters:
num- Number to checkmin- Range minimummax- Range maximummessage- message in the exception, if thrown- Returns:
- the provided `num`
- Throws:
IllegalNumberRangeException- ifnumis lower thanminor higher thenmax
-
checkState
Check a `boolean` and throw an exception if it is `false`- Parameters:
state- state- Throws:
IllegalStateException- ifstateis `false`
-
checkState
public static void checkState(boolean state, @Nullable @Nullable String message) throws IllegalStateException Check a `boolean` and throw an exception if it is `false`- Parameters:
state- statemessage- message in the exception, if thrown- Throws:
IllegalStateException- ifstateis `false`
-
checkNonNull
@Contract("null -> fail; !null -> param1") public static <T> T checkNonNull(@Nullable T obj) throws NullPointerException Check if an object is not `null` and throw an exception if it is- Parameters:
obj- object- Throws:
NullPointerException- ifobjis null
-
checkNonNull
@Contract("null, _ -> fail; !null, _ -> param1") public static <T> T checkNonNull(@Nullable T obj, @Nullable @Nullable String message) throws NullPointerException Check if an object is not `null` and throw an exception if it is- Parameters:
obj- objectmessage- message in the exception, when thrown- Throws:
NullPointerException- ifobjis null
-
checkNull
@Contract("!null -> fail") public static <T> void checkNull(@Nullable T obj) throws NotNullException Check if an object is `null` and throw an exception if it is- Parameters:
obj- object- Throws:
NotNullException- ifobjis not null
-
checkNull
@Contract("!null, _ -> fail") public static <T> void checkNull(@Nullable T obj, @Nullable @Nullable String message) throws NotNullException Check if an object is `null` and throw an exception if it is- Parameters:
obj- objectmessage- message in the exception, when thrown- Throws:
NotNullException- ifobjis not null
-