Class Preconditions
java.lang.Object
be.imgn.gaia.core.base.Preconditions
Checks that a method is called correctly, and throws the matching exception if not.
Preconditions.checkArgument(count >= 0, "count must not be negative: %d", count);
Preconditions.checkState(!closed, "Already closed");
A message is only built if the check fails. A message format follows the syntax of String.format(Locale, String, Object...) and is formatted in Locale.ROOT, so that messages do not depend on the default locale.
Use Objects.requireNonNull(Object, String) to check that a value is not null.
- Since:
- 0.1.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArgument(boolean expression) Checks an expression about the arguments of the calling method.static voidcheckArgument(boolean expression, @Nullable Object message) Checks an expression about the arguments of the calling method.static voidcheckArgument(boolean expression, String messageFormat, @Nullable Object... params) Checks an expression about the arguments of the calling method.static voidcheckState(boolean expression) Checks an expression about the state of the object the calling method is called on.static voidcheckState(boolean expression, @Nullable Object message) Checks an expression about the state of the object the calling method is called on.static voidcheckState(boolean expression, String messageFormat, @Nullable Object... params) Checks an expression about the state of the object the calling method is called on.
-
Method Details
-
checkArgument
public static void checkArgument(boolean expression) Checks an expression about the arguments of the calling method.- Parameters:
expression- the expression to check- Throws:
IllegalArgumentException- ifexpressionis false
-
checkArgument
Checks an expression about the arguments of the calling method.- Parameters:
expression- the expression to checkmessage- the message of the exception, converted withString.valueOf(Object)- Throws:
IllegalArgumentException- ifexpressionis false
-
checkArgument
@FormatMethod public static void checkArgument(boolean expression, @FormatString String messageFormat, @Nullable Object... params) Checks an expression about the arguments of the calling method.- Parameters:
expression- the expression to checkmessageFormat- the format of the message of the exceptionparams- the values the format refers to- Throws:
IllegalArgumentException- ifexpressionis falseIllegalFormatException- ifexpressionis false andmessageFormatis not a valid format forparams
-
checkState
public static void checkState(boolean expression) Checks an expression about the state of the object the calling method is called on.- Parameters:
expression- the expression to check- Throws:
IllegalStateException- ifexpressionis false
-
checkState
Checks an expression about the state of the object the calling method is called on.- Parameters:
expression- the expression to checkmessage- the message of the exception, converted withString.valueOf(Object)- Throws:
IllegalStateException- ifexpressionis false
-
checkState
@FormatMethod public static void checkState(boolean expression, @FormatString String messageFormat, @Nullable Object... params) Checks an expression about the state of the object the calling method is called on.- Parameters:
expression- the expression to checkmessageFormat- the format of the message of the exceptionparams- the values the format refers to- Throws:
IllegalStateException- ifexpressionis falseIllegalFormatException- ifexpressionis false andmessageFormatis not a valid format forparams
-