Class Assertions

java.lang.Object
org.opentcs.util.Assertions

public class Assertions extends Object
Utility methods for checking preconditions, postconditions etc..
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkArgument(boolean expression, String errorMessage)
    Ensures the given expression is true.
    static void
    checkArgument(boolean expression, String messageTemplate, Object... messageArgs)
    Ensures the given expression is true.
    static int
    checkInRange(int value, int minimum, int maximum)
    Ensures that value is not smaller than minimum and not greater than maximum.
    static int
    checkInRange(int value, int minimum, int maximum, String valueName)
    Ensures that value is not smaller than minimum and not greater than maximum.
    static long
    checkInRange(long value, long minimum, long maximum)
    Ensures that value is not smaller than minimum and not greater than maximum.
    static long
    checkInRange(long value, long minimum, long maximum, String valueName)
    Ensures that value is not smaller than minimum and not greater than maximum.
    static void
    checkState(boolean expression, String errorMessage)
    Ensures the given expression is true.
    static void
    checkState(boolean expression, String messageTemplate, Object... messageArgs)
    Ensures the given expression is true.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • checkArgument

      public static void checkArgument(boolean expression, String errorMessage) throws IllegalArgumentException
      Ensures the given expression is true.
      Parameters:
      expression - The expression to be checked.
      errorMessage - An optional error message.
      Throws:
      IllegalArgumentException - If the given expression is not true.
    • checkArgument

      public static void checkArgument(boolean expression, String messageTemplate, @Nullable Object... messageArgs) throws IllegalArgumentException
      Ensures the given expression is true.
      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:
      IllegalArgumentException - If the given expression is not true.
    • checkState

      public static void checkState(boolean expression, String errorMessage) throws IllegalStateException
      Ensures the given expression is true.
      Parameters:
      expression - The expression to be checked.
      errorMessage - An optional error message.
      Throws:
      IllegalStateException - If the given expression is not true.
    • checkState

      public static void checkState(boolean expression, String messageTemplate, @Nullable Object... messageArgs) throws IllegalStateException
      Ensures the given expression is true.
      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:
      IllegalStateException - If the given expression is not true.
    • checkInRange

      public static int checkInRange(int value, int minimum, int maximum) throws IllegalArgumentException
      Ensures that value is not smaller than minimum and not greater than maximum.
      Parameters:
      value - The value to be checked.
      minimum - The minimum value.
      maximum - The maximum value.
      Returns:
      The given value.
      Throws:
      IllegalArgumentException - If value is not within the given range.
    • checkInRange

      public static int checkInRange(int value, int minimum, int maximum, String valueName) throws IllegalArgumentException
      Ensures that value is not smaller than minimum and not greater than maximum.
      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:
      IllegalArgumentException - If value is not within the given range.
    • checkInRange

      public static long checkInRange(long value, long minimum, long maximum) throws IllegalArgumentException
      Ensures that value is not smaller than minimum and not greater than maximum.
      Parameters:
      value - The value to be checked.
      minimum - The minimum value.
      maximum - The maximum value.
      Returns:
      The given value.
      Throws:
      IllegalArgumentException - If value is not within the given range.
    • checkInRange

      public static long checkInRange(long value, long minimum, long maximum, String valueName) throws IllegalArgumentException
      Ensures that value is not smaller than minimum and not greater than maximum.
      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:
      IllegalArgumentException - If value is not within the given range.