Package au.csiro.pathling.utilities
Class Preconditions
java.lang.Object
au.csiro.pathling.utilities.Preconditions
Static convenience methods for checking the validity of inputs.
- Author:
- John Grimes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheck(boolean expression) Ensures the truth of an expression, throwing anAssertionErrorwith the supplied message if it does not evaluate as true.static voidEnsures the truth of an expression, throwing anAssertionErrorwith the supplied message if it does not evaluate as true.static voidcheckArgument(boolean expression, String errorMessage) Ensures the truth of an expression, throwing anIllegalArgumentExceptionwith the supplied message if it does not evaluate as true.static <T> TcheckPresent(Optional<T> object) Ensures that anOptionalvalue is present, throwing aAssertionErrorif it is not.static <T> TcheckPresent(Optional<T> object, String message) Ensures that anOptionalvalue is present, throwing aAssertionErrorif it is not.static voidcheckResponse(boolean expression, String messageTemplate, Object... params) Ensures the truth of an expression, throwing anUnexpectedResponseExceptionwith the supplied formatted message if it does not evaluate as true.static voidcheckState(boolean expression, String errorMessage) Ensures the truth of an expression, throwing anIllegalStateExceptionwith the supplied message if it does not evaluate as true.static voidcheckUserInput(boolean expression, String errorMessage) Ensures the truth of an expression, throwing anInvalidUserInputErrorwith the supplied message if it does not evaluate as true.static StringrequireNonBlank(String string, String msg) Ensures that anStringvalue is not blank, throwing aIllegalArgumentExceptionif it is.static <T,R> Function<T, R> wrapInUserInputError(Function<T, R> func) Converts a function which throws aFHIRExceptionto a function that throws anInvalidUserInputErrorin the same situation.
-
Constructor Details
-
Preconditions
public Preconditions()
-
-
Method Details
-
check
public static void check(boolean expression) Ensures the truth of an expression, throwing anAssertionErrorwith the supplied message if it does not evaluate as true.- Parameters:
expression- the expression that should be true
-
check
public static void check(boolean expression, @Nonnull String messageTemplate, @Nonnull Object... params) Ensures the truth of an expression, throwing anAssertionErrorwith the supplied message if it does not evaluate as true.- Parameters:
expression- the expression that should be truemessageTemplate- the message template in theString.format(java.lang.String, java.lang.Object...)formatparams- the parameters to the message template
-
checkArgument
Ensures the truth of an expression, throwing anIllegalArgumentExceptionwith the supplied message if it does not evaluate as true.- Parameters:
expression- the expression that should be trueerrorMessage- the message to use if an error is thrown
-
checkPresent
Ensures that anOptionalvalue is present, throwing aAssertionErrorif it is not.- Type Parameters:
T- the type of the object within the Optional- Parameters:
object- the object to check- Returns:
- the unwrapped object
-
checkPresent
Ensures that anOptionalvalue is present, throwing aAssertionErrorif it is not.- Type Parameters:
T- the type of the object within the Optional- Parameters:
object- the object to checkmessage- an error message- Returns:
- the unwrapped object
-
checkUserInput
Ensures the truth of an expression, throwing anInvalidUserInputErrorwith the supplied message if it does not evaluate as true.- Parameters:
expression- the expression that should be trueerrorMessage- the message to use if an error is thrown
-
checkState
Ensures the truth of an expression, throwing anIllegalStateExceptionwith the supplied message if it does not evaluate as true.- Parameters:
expression- the expression that should be trueerrorMessage- the message to use if an error is thrown
-
requireNonBlank
Ensures that anStringvalue is not blank, throwing aIllegalArgumentExceptionif it is.- Parameters:
string- the object to checkmsg- the message to use if an error is thrown- Returns:
- non blank string
-
checkResponse
public static void checkResponse(boolean expression, @Nonnull String messageTemplate, @Nonnull Object... params) Ensures the truth of an expression, throwing anUnexpectedResponseExceptionwith the supplied formatted message if it does not evaluate as true.- Parameters:
expression- the expression that should be truemessageTemplate- the message template in theString.format(java.lang.String, java.lang.Object...)formatparams- the parameters to the message template
-
wrapInUserInputError
Converts a function which throws aFHIRExceptionto a function that throws anInvalidUserInputErrorin the same situation.- Type Parameters:
T- the type of the function argument.R- the type of the function result.- Parameters:
func- the function throwingFHIRException- Returns:
- the wrapped function.
-