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 is true.
    static void checkArgument​(boolean expression, java.lang.String messageTemplate, java.lang.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, java.lang.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, java.lang.String valueName)
    Ensures that value is not smaller than minimum and not greater than maximum.
    static void checkState​(boolean expression, java.lang.String errorMessage)
    Ensures the given expression is true.
    static void checkState​(boolean expression, java.lang.String messageTemplate, java.lang.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, java.lang.String errorMessage) throws java.lang.IllegalArgumentException
      Ensures the given expression is true.
      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.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:
      java.lang.IllegalArgumentException - If the given expression is not true.
    • checkState

      public static void checkState​(boolean expression, java.lang.String errorMessage) throws java.lang.IllegalStateException
      Ensures the given expression is true.
      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.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:
      java.lang.IllegalStateException - If the given expression is not true.
    • checkInRange

      public static int checkInRange​(int value, int minimum, int maximum) throws java.lang.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:
      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.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:
      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.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:
      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.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:
      java.lang.IllegalArgumentException - If value is not within the given range.