类 Assertions
- java.lang.Object
-
- com.ts.lib.common.util.Assertions
-
public final class Assertions extends Object
提供一种断言表达式和属性的断言方法- 作者:
- Li Junchao
-
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static voidcheckArgument(boolean expression)ThrowsIllegalArgumentExceptionifexpressionevaluates to false.static voidcheckArgument(boolean expression, Object errorMessage)ThrowsIllegalArgumentExceptionifexpressionevaluates to false.static intcheckIndex(int index, int start, int limit)ThrowsIndexOutOfBoundsExceptionifindexfalls outside the specified bounds.static voidcheckMainThread()ThrowsIllegalStateExceptionif the calling thread is not the application's main thread.static StringcheckNotEmpty(String string)ThrowsIllegalArgumentExceptionifstringis null or zero length.static StringcheckNotEmpty(String string, Object errorMessage)ThrowsIllegalArgumentExceptionifstringis null or zero length.static <T> TcheckNotNull(T reference)ThrowsNullPointerExceptionifreferenceis null.static <T> TcheckNotNull(T reference, Object errorMessage)ThrowsNullPointerExceptionifreferenceis null.static voidcheckState(boolean expression)ThrowsIllegalStateExceptionifexpressionevaluates to false.static voidcheckState(boolean expression, Object errorMessage)ThrowsIllegalStateExceptionifexpressionevaluates to false.static <T> TcheckStateNotNull(T reference)ThrowsIllegalStateExceptionifreferenceis null.static <T> TcheckStateNotNull(T reference, Object errorMessage)ThrowsIllegalStateExceptionifreferenceis null.
-
-
-
方法详细资料
-
checkArgument
public static void checkArgument(boolean expression)
ThrowsIllegalArgumentExceptionifexpressionevaluates to false.- 参数:
expression- The expression to evaluate.- 抛出:
IllegalArgumentException- Ifexpressionis false.
-
checkArgument
public static void checkArgument(boolean expression, Object errorMessage)ThrowsIllegalArgumentExceptionifexpressionevaluates to false.- 参数:
expression- The expression to evaluate.errorMessage- The exception message if an exception is thrown. The message is converted to aStringusingString.valueOf(Object).- 抛出:
IllegalArgumentException- Ifexpressionis false.
-
checkIndex
public static int checkIndex(int index, int start, int limit)ThrowsIndexOutOfBoundsExceptionifindexfalls 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
indexthat was validated. - 抛出:
IndexOutOfBoundsException- Ifindexfalls outside the specified bounds.
-
checkState
public static void checkState(boolean expression)
ThrowsIllegalStateExceptionifexpressionevaluates to false.- 参数:
expression- The expression to evaluate.- 抛出:
IllegalStateException- Ifexpressionis false.
-
checkState
public static void checkState(boolean expression, Object errorMessage)ThrowsIllegalStateExceptionifexpressionevaluates to false.- 参数:
expression- The expression to evaluate.errorMessage- The exception message if an exception is thrown. The message is converted to aStringusingString.valueOf(Object).- 抛出:
IllegalStateException- Ifexpressionis false.
-
checkStateNotNull
public static <T> T checkStateNotNull(@Nullable T reference)
ThrowsIllegalStateExceptionifreferenceis null.- 类型参数:
T- The type of the reference.- 参数:
reference- The reference.- 返回:
- The non-null reference that was validated.
- 抛出:
IllegalStateException- Ifreferenceis null.
-
checkStateNotNull
public static <T> T checkStateNotNull(@Nullable T reference, Object errorMessage)
ThrowsIllegalStateExceptionifreferenceis 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 usingString.valueOf(Object).- 返回:
- The non-null reference that was validated.
- 抛出:
IllegalStateException- Ifreferenceis null.
-
checkNotNull
public static <T> T checkNotNull(@Nullable T reference)
ThrowsNullPointerExceptionifreferenceis null.- 类型参数:
T- The type of the reference.- 参数:
reference- The reference.- 返回:
- The non-null reference that was validated.
- 抛出:
NullPointerException- Ifreferenceis null.
-
checkNotNull
public static <T> T checkNotNull(@Nullable T reference, Object errorMessage)
ThrowsNullPointerExceptionifreferenceis 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 usingString.valueOf(Object).- 返回:
- The non-null reference that was validated.
- 抛出:
NullPointerException- Ifreferenceis null.
-
checkNotEmpty
public static String checkNotEmpty(@Nullable String string)
ThrowsIllegalArgumentExceptionifstringis null or zero length.- 参数:
string- The string to check.- 返回:
- The non-null, non-empty string that was validated.
- 抛出:
IllegalArgumentException- Ifstringis null or 0-length.
-
checkNotEmpty
public static String checkNotEmpty(@Nullable String string, Object errorMessage)
ThrowsIllegalArgumentExceptionifstringis null or zero length.- 参数:
string- The string to check.errorMessage- The exception message to use if the check fails. The message is converted to a string usingString.valueOf(Object).- 返回:
- The non-null, non-empty string that was validated.
- 抛出:
IllegalArgumentException- Ifstringis null or 0-length.
-
checkMainThread
public static void checkMainThread()
ThrowsIllegalStateExceptionif the calling thread is not the application's main thread.- 抛出:
IllegalStateException- If the calling thread is not the application's main thread.
-
-