类 Assertions


  • public final class Assertions
    extends Object
    提供一种断言表达式和属性的断言方法
    作者:
    Li Junchao
    • 方法详细资料

      • checkArgument

        public static void checkArgument​(boolean expression)
        Throws IllegalArgumentException if expression evaluates to false.
        参数:
        expression - The expression to evaluate.
        抛出:
        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.
        参数:
        index - The index to test.
        start - The start of the allowed range (inclusive).
        limit - The end of the allowed range (exclusive).
        返回:
        The index that was validated.
        抛出:
        IndexOutOfBoundsException - If index falls outside the specified bounds.
      • checkState

        public static void checkState​(boolean expression)
        Throws IllegalStateException if expression evaluates to false.
        参数:
        expression - The expression to evaluate.
        抛出:
        IllegalStateException - If expression is false.
      • checkState

        public static void checkState​(boolean expression,
                                      Object errorMessage)
        Throws IllegalStateException if expression evaluates to false.
        参数:
        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).
        抛出:
        IllegalStateException - If expression is false.
      • checkStateNotNull

        public static <T> T checkStateNotNull​(@Nullable
                                              T reference)
        Throws IllegalStateException if reference is null.
        类型参数:
        T - The type of the reference.
        参数:
        reference - The reference.
        返回:
        The non-null reference that was validated.
        抛出:
        IllegalStateException - If reference is null.
      • checkStateNotNull

        public static <T> T checkStateNotNull​(@Nullable
                                              T reference,
                                              Object errorMessage)
        Throws IllegalStateException if reference is null.
        类型参数:
        T - The type of the reference.
        参数:
        reference - The reference.
        errorMessage - The exception message to use if the check fails. The message is converted to a string using String.valueOf(Object).
        返回:
        The non-null reference that was validated.
        抛出:
        IllegalStateException - If reference is null.
      • checkNotNull

        public static <T> T checkNotNull​(@Nullable
                                         T reference)
        Throws NullPointerException if reference is null.
        类型参数:
        T - The type of the reference.
        参数:
        reference - The reference.
        返回:
        The non-null reference that was validated.
        抛出:
        NullPointerException - If reference is null.
      • checkNotNull

        public static <T> T checkNotNull​(@Nullable
                                         T reference,
                                         Object errorMessage)
        Throws NullPointerException if reference is null.
        类型参数:
        T - The type of the reference.
        参数:
        reference - The reference.
        errorMessage - The exception message to use if the check fails. The message is converted to a string using String.valueOf(Object).
        返回:
        The non-null reference that was validated.
        抛出:
        NullPointerException - If reference is null.
      • checkMainThread

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