Package org.opentcs.util
Class Assertions
java.lang.Object
org.opentcs.util.Assertions
public class Assertions
extends java.lang.Object
Utility methods for checking preconditions, postconditions etc..
-
Method Summary
Modifier and Type Method Description static void
checkArgument(boolean expression, java.lang.String errorMessage)
Ensures the given expression istrue
.static void
checkArgument(boolean expression, java.lang.String messageTemplate, java.lang.Object... messageArgs)
Ensures the given expression istrue
.static int
checkInRange(int value, int minimum, int maximum)
Ensures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.static int
checkInRange(int value, int minimum, int maximum, java.lang.String valueName)
Ensures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.static long
checkInRange(long value, long minimum, long maximum)
Ensures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.static long
checkInRange(long value, long minimum, long maximum, java.lang.String valueName)
Ensures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.static void
checkState(boolean expression, java.lang.String errorMessage)
Ensures the given expression istrue
.static void
checkState(boolean expression, java.lang.String messageTemplate, java.lang.Object... messageArgs)
Ensures the given expression istrue
.
-
Method Details
-
checkArgument
public static void checkArgument(boolean expression, java.lang.String errorMessage) throws java.lang.IllegalArgumentExceptionEnsures the given expression istrue
.- Parameters:
expression
- The expression to be checked.errorMessage
- An optional error message.- Throws:
java.lang.IllegalArgumentException
- If the given expression is not true.
-
checkArgument
public static void checkArgument(boolean expression, java.lang.String messageTemplate, @Nullable java.lang.Object... messageArgs) throws java.lang.IllegalArgumentExceptionEnsures the given expression istrue
.- Parameters:
expression
- The expression to be checked.messageTemplate
- A formatting template for the error message.messageArgs
- The arguments to be formatted into the message template.- Throws:
java.lang.IllegalArgumentException
- If the given expression is not true.
-
checkState
public static void checkState(boolean expression, java.lang.String errorMessage) throws java.lang.IllegalStateExceptionEnsures the given expression istrue
.- Parameters:
expression
- The expression to be checked.errorMessage
- An optional error message.- Throws:
java.lang.IllegalStateException
- If the given expression is not true.
-
checkState
public static void checkState(boolean expression, java.lang.String messageTemplate, @Nullable java.lang.Object... messageArgs) throws java.lang.IllegalStateExceptionEnsures the given expression istrue
.- Parameters:
expression
- The expression to be checked.messageTemplate
- A formatting template for the error message.messageArgs
- The arguments to be formatted into the message template.- Throws:
java.lang.IllegalStateException
- If the given expression is not true.
-
checkInRange
public static int checkInRange(int value, int minimum, int maximum) throws java.lang.IllegalArgumentExceptionEnsures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.- Parameters:
value
- The value to be checked.minimum
- The minimum value.maximum
- The maximum value.- Returns:
- The given value.
- Throws:
java.lang.IllegalArgumentException
- If value is not within the given range.
-
checkInRange
public static int checkInRange(int value, int minimum, int maximum, java.lang.String valueName) throws java.lang.IllegalArgumentExceptionEnsures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.- Parameters:
value
- The value to be checked.minimum
- The minimum value.maximum
- The maximum value.valueName
- An optional name for the value to be used for the exception message.- Returns:
- The given value.
- Throws:
java.lang.IllegalArgumentException
- If value is not within the given range.
-
checkInRange
public static long checkInRange(long value, long minimum, long maximum) throws java.lang.IllegalArgumentExceptionEnsures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.- Parameters:
value
- The value to be checked.minimum
- The minimum value.maximum
- The maximum value.- Returns:
- The given value.
- Throws:
java.lang.IllegalArgumentException
- If value is not within the given range.
-
checkInRange
public static long checkInRange(long value, long minimum, long maximum, java.lang.String valueName) throws java.lang.IllegalArgumentExceptionEnsures thatvalue
is not smaller thanminimum
and not greater thanmaximum
.- Parameters:
value
- The value to be checked.minimum
- The minimum value.maximum
- The maximum value.valueName
- An optional name for the value to be used for the exception message.- Returns:
- The given value.
- Throws:
java.lang.IllegalArgumentException
- If value is not within the given range.
-