java.lang.Object
io.smallrye.common.constraint.Assert

public final class Assert extends Object
A set of assertions and checks.
  • Method Details

    • checkNotNullParam

      @NotNull public static <T> T checkNotNullParam(String name, T value) throws IllegalArgumentException
      Check that the named parameter is not null. Use a standard exception message if it is.
      Type Parameters:
      T - the value type
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is null
    • checkNotNullArrayParam

      @NotNull public static <T> T checkNotNullArrayParam(String name, int index, T value) throws IllegalArgumentException
      Check that a value within the named array parameter is not null. Use a standard exception message if it is.
      Type Parameters:
      T - the element value type
      Parameters:
      name - the parameter name
      index - the array index
      value - the array element value
      Returns:
      the array element value that was passed in
      Throws:
      IllegalArgumentException - if the value is null
    • checkNotEmptyParam

      @NotNull public static String checkNotEmptyParam(String name, String value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static CharSequence checkNotEmptyParam(String name, CharSequence value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static <E, T extends Collection<E>> T checkNotEmptyParam(String name, T value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Type Parameters:
      E - the element type
      T - the collection type
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static <K, V, T extends Map<K, V>> T checkNotEmptyParam(String name, T value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Type Parameters:
      K - the map key type
      V - the map value type
      T - the map type
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static <T> T[] checkNotEmptyParam(String name, T[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Type Parameters:
      T - the element type
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static boolean[] checkNotEmptyParam(String name, boolean[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static byte[] checkNotEmptyParam(String name, byte[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static short[] checkNotEmptyParam(String name, short[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static int[] checkNotEmptyParam(String name, int[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static long[] checkNotEmptyParam(String name, long[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static float[] checkNotEmptyParam(String name, float[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkNotEmptyParam

      @NotNull public static double[] checkNotEmptyParam(String name, double[] value)
      Check that the named parameter is not empty. Use a standard exception message if it is.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the value is empty
    • checkMinimumParameter

      public static <T extends Comparable<T>> T checkMinimumParameter(String name, T min, T actual) throws IllegalArgumentException
      Check that the named parameter is greater than or equal to min.
      Type Parameters:
      T - the parameter type
      Parameters:
      name - the parameter name
      min - the minimum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is less than the minimum value
    • checkMinimumParameter

      public static int checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException
      Check that the named parameter is greater than or equal to min.
      Parameters:
      name - the parameter name
      min - the minimum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is less than the minimum value
    • checkMinimumParameterUnsigned

      public static int checkMinimumParameterUnsigned(String name, int min, int actual) throws IllegalArgumentException
      Check that the named parameter is greater than or equal to min using unsigned comparison.
      Parameters:
      name - the parameter name
      min - the minimum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is less than the minimum value
    • checkMinimumParameter

      public static long checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException
      Check that the named parameter is greater than or equal to min.
      Parameters:
      name - the parameter name
      min - the minimum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is less than the minimum value
    • checkMinimumParameterUnsigned

      public static long checkMinimumParameterUnsigned(String name, long min, long actual) throws IllegalArgumentException
      Check that the named parameter is greater than or equal to min using unsigned comparison.
      Parameters:
      name - the parameter name
      min - the minimum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is less than the minimum value
    • checkMinimumParameter

      public static float checkMinimumParameter(String name, float min, float actual) throws IllegalArgumentException
      Check that the named parameter is greater than or equal to min.
      Parameters:
      name - the parameter name
      min - the minimum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is less than the minimum value
    • checkMinimumParameter

      public static double checkMinimumParameter(String name, double min, double actual) throws IllegalArgumentException
      Check that the named parameter is greater than or equal to min.
      Parameters:
      name - the parameter name
      min - the minimum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is less than the minimum value
    • checkMaximumParameter

      public static <T extends Comparable<T>> T checkMaximumParameter(String name, T max, T actual) throws IllegalArgumentException
      Check that the named parameter is less than or equal to max.
      Type Parameters:
      T - the parameter type
      Parameters:
      name - the parameter name
      max - the maximum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is greater than the maximum value
    • checkMaximumParameter

      public static int checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException
      Check that the named parameter is less than or equal to max.
      Parameters:
      name - the parameter name
      max - the maximum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is greater than the maximum value
    • checkMaximumParameterUnsigned

      public static int checkMaximumParameterUnsigned(String name, int max, int actual) throws IllegalArgumentException
      Check that the named parameter is less than or equal to max using unsigned comparison.
      Parameters:
      name - the parameter name
      max - the maximum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is greater than the maximum value
    • checkMaximumParameter

      public static long checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException
      Check that the named parameter is less than or equal to max.
      Parameters:
      name - the parameter name
      max - the maximum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is greater than the maximum value
    • checkMaximumParameterUnsigned

      public static long checkMaximumParameterUnsigned(String name, long max, long actual) throws IllegalArgumentException
      Check that the named parameter is less than or equal to max using unsigned comparison.
      Parameters:
      name - the parameter name
      max - the maximum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is greater than the maximum value
    • checkMaximumParameter

      public static float checkMaximumParameter(String name, float max, float actual) throws IllegalArgumentException
      Check that the named parameter is less than or equal to max.
      Parameters:
      name - the parameter name
      max - the maximum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is greater than the maximum value
    • checkMaximumParameter

      public static double checkMaximumParameter(String name, double max, double actual) throws IllegalArgumentException
      Check that the named parameter is less than or equal to max.
      Parameters:
      name - the parameter name
      max - the maximum value
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is greater than the maximum value
    • checkPow2Parameter

      public static int checkPow2Parameter(String name, int actual) throws IllegalArgumentException
      Check that the named parameter is zero or a power of two (unsigned). For a signed check, or to eliminate zero values, use checkMinimumParameter(String, int, int).
      Parameters:
      name - the parameter name
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is not zero or a power of two
    • checkPow2Parameter

      public static long checkPow2Parameter(String name, long actual) throws IllegalArgumentException
      Check that the named parameter is zero or a power of two (unsigned). For a signed check, or to eliminate zero values, use checkMinimumParameter(String, long, long).
      Parameters:
      name - the parameter name
      actual - the actual parameter value
      Returns:
      the given actual value
      Throws:
      IllegalArgumentException - if the actual value is not zero or a power of two
    • checkArrayBounds

      public static void checkArrayBounds(Object[] array, int offs, int len) throws ArrayIndexOutOfBoundsException
      Check that the given offset and length fall completely within the bounds of the given array.
      Parameters:
      array - the array to check
      offs - the array offset
      len - the array length
      Throws:
      ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array bounds
    • checkArrayBounds

      public static void checkArrayBounds(byte[] array, int offs, int len) throws ArrayIndexOutOfBoundsException
      Check that the given offset and length fall completely within the bounds of the given array.
      Parameters:
      array - the array to check
      offs - the array offset
      len - the array length
      Throws:
      ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array bounds
    • checkArrayBounds

      public static void checkArrayBounds(char[] array, int offs, int len) throws ArrayIndexOutOfBoundsException
      Check that the given offset and length fall completely within the bounds of the given array.
      Parameters:
      array - the array to check
      offs - the array offset
      len - the array length
      Throws:
      ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array bounds
    • checkArrayBounds

      public static void checkArrayBounds(int[] array, int offs, int len) throws ArrayIndexOutOfBoundsException
      Check that the given offset and length fall completely within the bounds of the given array.
      Parameters:
      array - the array to check
      offs - the array offset
      len - the array length
      Throws:
      ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array bounds
    • checkArrayBounds

      public static void checkArrayBounds(long[] array, int offs, int len) throws ArrayIndexOutOfBoundsException
      Check that the given offset and length fall completely within the bounds of the given array.
      Parameters:
      array - the array to check
      offs - the array offset
      len - the array length
      Throws:
      ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array bounds
    • checkArrayBounds

      public static void checkArrayBounds(int arrayLength, int offs, int len) throws ArrayIndexOutOfBoundsException
      Check that the given offset and length fall completely within the bounds of the given array length.
      Parameters:
      arrayLength - the array length to check against
      offs - the array offset
      len - the array length
      Throws:
      ArrayIndexOutOfBoundsException - if the range of the offset and length do not fall within the array bounds
    • assertNotNull

      @NotNull public static <T> T assertNotNull(T value)
      Assert that the value is not null. Use a standard assertion failure message if it is. Only runs if assert is enabled.
      Type Parameters:
      T - the value type
      Parameters:
      value - the not-null value
      Returns:
      the value that was passed in
    • assertHoldsLock

      @NotNull public static <T> T assertHoldsLock(@NotNull T monitor)
      Assert that the given monitor is held by the current thread. Use a standard assertion failure message if it is not. Only runs if assert is enabled.
      Type Parameters:
      T - the monitor's type
      Parameters:
      monitor - the monitor object
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the monitor is null
    • assertNotHoldsLock

      @NotNull public static <T> T assertNotHoldsLock(@NotNull T monitor)
      Assert that the given monitor is not held by the current thread. Use a standard assertion failure message if it is. Only runs if assert is enabled.
      Type Parameters:
      T - the monitor's type
      Parameters:
      monitor - the monitor object
      Returns:
      the value that was passed in
      Throws:
      IllegalArgumentException - if the monitor is null
    • assertTrue

      public static boolean assertTrue(boolean expr)
      Assert that the given expression is always true.
      Parameters:
      expr - the boolean expression
      Returns:
      the boolean expression
    • assertFalse

      public static boolean assertFalse(boolean expr)
      Assert that the given expression is always false.
      Parameters:
      expr - the boolean expression
      Returns:
      the boolean expression
    • unreachableCode

      public static IllegalStateException unreachableCode()
      Return an exception indicating that the current code was intended to be unreachable.
      Returns:
      the exception which may be immediately thrown
    • impossibleSwitchCase

      @NotNull public static IllegalStateException impossibleSwitchCase(@NotNull Object obj)
      Return an exception indicating that the current switch case was intended to be unreachable.
      Parameters:
      obj - the switch case value
      Returns:
      the exception which may be immediately thrown
    • impossibleSwitchCase

      @NotNull public static IllegalStateException impossibleSwitchCase(char val)
      Return an exception indicating that the current switch case was intended to be unreachable.
      Parameters:
      val - the switch case value
      Returns:
      the exception which may be immediately thrown
    • impossibleSwitchCase

      @NotNull public static IllegalStateException impossibleSwitchCase(int val)
      Return an exception indicating that the current switch case was intended to be unreachable.
      Parameters:
      val - the switch case value
      Returns:
      the exception which may be immediately thrown
    • impossibleSwitchCase

      @NotNull public static IllegalStateException impossibleSwitchCase(long val)
      Return an exception indicating that the current switch case was intended to be unreachable.
      Parameters:
      val - the switch case value
      Returns:
      the exception which may be immediately thrown
    • unsupported

      @NotNull public static UnsupportedOperationException unsupported()
      Return an exception explaining that the caller's method is not supported.
      Returns:
      the exception