Class Preconditions
java.lang.Object
tools.refinery.interpreter.matchers.util.Preconditions
This class was motivated by the similar Preconditions class from Guava to provide simple precondition checking
functionality. However, as starting with version 2.0 the runtime of VIATRA Query should not depend on Guava, the
relevant functionality of the Preconditions checking functionality will be implemented here.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArgument(boolean expression) Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckArgument(boolean expression, String errorMessage) Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckArgument(boolean expression, Supplier<String> messageSupplier) Ensures the truth of an expression involving one or more parameters to the calling method.static voidcheckElementIndex(int index, int size) Ensures that an index is appropriate for a list or array of given size.static voidcheckElementIndex(int index, int size, String errorMessageTemplate, Object... errorMessageArgs) Ensures that an index is appropriate for a list or array of given size.static voidcheckElementIndex(int index, int size, Supplier<String> messageSupplier) Ensures that an index is appropriate for a list or array of given size.static voidcheckState(boolean expression) Ensures the truth of an expression involving one or more fields of a class.static voidcheckState(boolean expression, String errorMessage) Ensures the truth of an expression involving one or more fields of a class.static voidcheckState(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more fields of a class.static voidcheckState(boolean expression, Supplier<String> messageSupplier) Ensures the truth of an expression involving one or more fields of a class.
-
Method Details
-
checkArgument
public static void checkArgument(boolean expression) Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression- a boolean expression- Throws:
IllegalArgumentException- ifexpressionis false
-
checkArgument
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression- a boolean expressionerrorMessage- the exception message to use if the check fails- Throws:
IllegalArgumentException- ifexpressionis false
-
checkArgument
public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression- a boolean expressionerrorMessageTemplate- a template for the exception message should the check fail using the Java Formatter syntax; the same as used byString.format(String, Object...).errorMessageArgs- the arguments to be substituted into the message template.- Throws:
IllegalArgumentException- ifexpressionis falseNullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
checkArgument
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression- a boolean expressionmessageSupplier- a supplier that is called to calculate the error message if necessary- Throws:
IllegalArgumentException- ifexpressionis false
-
checkState
public static void checkState(boolean expression) Ensures the truth of an expression involving one or more fields of a class.- Parameters:
expression- a boolean expression- Throws:
IllegalStateException- ifexpressionis false
-
checkState
Ensures the truth of an expression involving one or more fields of a class.- Parameters:
expression- a boolean expressionerrorMessage- the exception message to use if the check fails- Throws:
IllegalStateException- ifexpressionis false
-
checkState
public static void checkState(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Ensures the truth of an expression involving one or more fields of a class.- Parameters:
expression- a boolean expressionerrorMessageTemplate- a template for the exception message should the check fail using the Java Formatter syntax; the same as used byString.format(String, Object...).errorMessageArgs- the arguments to be substituted into the message template.- Throws:
IllegalStateException- ifexpressionis falseNullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
checkState
Ensures the truth of an expression involving one or more fields of a class.- Parameters:
expression- a boolean expressionmessageSupplier- a supplier that is called to calculate the error message if necessary- Throws:
IllegalStateException- ifexpressionis false
-
checkElementIndex
public static void checkElementIndex(int index, int size) Ensures that an index is appropriate for a list or array of given size.- Parameters:
index-size-- Throws:
IndexOutOfBoundsException- if index is negative or is greater or equal to size
-
checkElementIndex
public static void checkElementIndex(int index, int size, String errorMessageTemplate, Object... errorMessageArgs) Ensures that an index is appropriate for a list or array of given size.- Parameters:
index-size-errorMessageTemplate- a template for the exception message should the check fail using the Java Formatter syntax; the same as used byString.format(String, Object...).errorMessageArgs- the arguments to be substituted into the message template.- Throws:
IndexOutOfBoundsException- if index is negative or is greater or equal to size
-
checkElementIndex
Ensures that an index is appropriate for a list or array of given size.- Parameters:
index-size-messageSupplier- a supplier that is called to calculate the error message if necessary- Throws:
IndexOutOfBoundsException- if index is negative or is greater or equal to size
-