Class Assertions

java.lang.Object
com.castlabs.sdk.base.subtitles.utilities.Assertions

public final class Assertions extends Object
Provides methods for asserting the truth of expressions and properties.
  • Method Details

    • checkArgument

      public static void checkArgument(boolean expression)
      Throws IllegalArgumentException if expression evaluates to false.
      Parameters:
      expression - The expression to evaluate.
      Throws:
      IllegalArgumentException - If expression is false.
    • checkArgument

      public static void checkArgument(boolean expression, Object errorMessage)
      Throws IllegalArgumentException if expression evaluates to false.
      Parameters:
      expression - The expression to evaluate.
      errorMessage - The exception message if an exception is thrown. The message is converted to a String using String.valueOf(Object).
      Throws:
      IllegalArgumentException - If expression is false.
    • checkIndex

      public static int checkIndex(int index, int start, int limit)
      Throws IndexOutOfBoundsException if index falls outside the specified bounds.
      Parameters:
      index - The index to test.
      start - The start of the allowed range (inclusive).
      limit - The end of the allowed range (exclusive).
      Returns:
      The index that was validated.
      Throws:
      IndexOutOfBoundsException - If index falls outside the specified bounds.
    • checkState

      public static void checkState(boolean expression)
      Throws IllegalStateException if expression evaluates to false.
      Parameters:
      expression - The expression to evaluate.
      Throws:
      IllegalStateException - If expression is false.
    • checkState

      public static void checkState(boolean expression, Object errorMessage)
      Throws IllegalStateException if expression evaluates to false.
      Parameters:
      expression - The expression to evaluate.
      errorMessage - The exception message if an exception is thrown. The message is converted to a String using String.valueOf(Object).
      Throws:
      IllegalStateException - If expression is false.
    • checkStateNotNull

      @EnsuresNonNull("#1") public static <T> T checkStateNotNull(@Nullable T reference)
      Throws IllegalStateException if reference is null.
      Type Parameters:
      T - The type of the reference.
      Parameters:
      reference - The reference.
      Returns:
      The non-null reference that was validated.
      Throws:
      IllegalStateException - If reference is null.
    • checkStateNotNull

      @EnsuresNonNull("#1") public static <T> T checkStateNotNull(@Nullable T reference, Object errorMessage)
      Throws IllegalStateException if reference is null.
      Type Parameters:
      T - The type of the reference.
      Parameters:
      reference - The reference.
      errorMessage - The exception message to use if the check fails. The message is converted to a string using String.valueOf(Object).
      Returns:
      The non-null reference that was validated.
      Throws:
      IllegalStateException - If reference is null.
    • checkNotNull

      @EnsuresNonNull("#1") public static <T> T checkNotNull(@Nullable T reference)
      Throws NullPointerException if reference is null.
      Type Parameters:
      T - The type of the reference.
      Parameters:
      reference - The reference.
      Returns:
      The non-null reference that was validated.
      Throws:
      NullPointerException - If reference is null.
    • checkNotNull

      @EnsuresNonNull("#1") public static <T> T checkNotNull(@Nullable T reference, Object errorMessage)
      Throws NullPointerException if reference is null.
      Type Parameters:
      T - The type of the reference.
      Parameters:
      reference - The reference.
      errorMessage - The exception message to use if the check fails. The message is converted to a string using String.valueOf(Object).
      Returns:
      The non-null reference that was validated.
      Throws:
      NullPointerException - If reference is null.
    • checkNotEmpty

      @EnsuresNonNull("#1") public static String checkNotEmpty(@Nullable String string)
      Throws IllegalArgumentException if string is null or zero length.
      Parameters:
      string - The string to check.
      Returns:
      The non-null, non-empty string that was validated.
      Throws:
      IllegalArgumentException - If string is null or 0-length.
    • checkNotEmpty

      @EnsuresNonNull("#1") public static String checkNotEmpty(@Nullable String string, Object errorMessage)
      Throws IllegalArgumentException if string is null or zero length.
      Parameters:
      string - The string to check.
      errorMessage - The exception message to use if the check fails. The message is converted to a string using String.valueOf(Object).
      Returns:
      The non-null, non-empty string that was validated.
      Throws:
      IllegalArgumentException - If string is null or 0-length.
    • checkMainThread

      public static void checkMainThread()
      Throws IllegalStateException if the calling thread is not the application's main thread.
      Throws:
      IllegalStateException - If the calling thread is not the application's main thread.