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
-
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> TcheckArgumentNotNull(T object) Ensures that an object is not null, throwing anIllegalArgumentExceptionif it is null.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 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 <T,R> Function <T, R> wrapInUserInputError(Function<T, R> func) Converts a function which throws aFHIRExceptionto a function that throws anInvalidUserInputErrorin the same situation.
-
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
-
checkArgumentNotNull
@Nonnull public static <T> T checkArgumentNotNull(@Nullable T object) Ensures that an object is not null, throwing anIllegalArgumentExceptionif it is null.- Type Parameters:
T- the type of the object- Parameters:
object- the object to check- Returns:
- the object if it is not null
-
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
-
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.
-