Package com.alibaba.cola.exception
Class Assert
- java.lang.Object
-
- com.alibaba.cola.exception.Assert
-
public abstract class Assert extends Object
Assertion utility class that assists in validating arguments.Useful for identifying programmer errors early and clearly at runtime.
For example, if the contract of a public method states it does not allow
nullarguments,Assertcan be used to validate that contract. For example:Assert.notNull(clazz, "The class must not be null"); Assert.isTrue(i > 0, "The value must be greater than zero");
This class is empowered byorg.springframework.util.Assert- Author:
- Frank Zhang
-
-
Constructor Summary
Constructors Constructor Description Assert()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidisFalse(boolean expression)static voidisFalse(boolean expression, String errMessage)static voidisFalse(boolean expression, String errorCode, String errMessage)Assert a boolean expression, if expression is true, throwingBizExceptionfor examplestatic voidisTrue(boolean expression)static voidisTrue(boolean expression, String errMessage)static voidisTrue(boolean expression, String errorCode, String errMessage)Assert a boolean expression, throwingBizExceptionfor examplestatic voidnotEmpty(Collection<?> collection)static voidnotEmpty(Collection<?> collection, String errMessage)static voidnotEmpty(Collection<?> collection, String errorCode, String errMessage)static voidnotEmpty(Map<?,?> map)static voidnotEmpty(Map<?,?> map, String errMessage)static voidnotEmpty(Map<?,?> map, String errorCode, String errMessage)static voidnotNull(Object object)static voidnotNull(Object object, String errMessage)static voidnotNull(Object object, String errorCode, String errMessage)
-
-
-
Method Detail
-
isTrue
public static void isTrue(boolean expression, String errorCode, String errMessage)Assert a boolean expression, throwingBizExceptionfor exampleAssert.isTrue(i != 0, errorCode.B_ORDER_illegalNumber, "The order number can not be zero");
- Parameters:
expression- a boolean expressionerrorCode-errMessage- the exception message to use if the assertion fails- Throws:
BizException- if expression isfalse
-
isFalse
public static void isFalse(boolean expression, String errorCode, String errMessage)Assert a boolean expression, if expression is true, throwingBizExceptionfor exampleAssert.isFalse(i == 0, errorCode.B_ORDER_illegalNumber, "The order number can not be zero");
This is more intuitive than isTure.
-
isTrue
public static void isTrue(boolean expression, String errMessage)
-
isFalse
public static void isFalse(boolean expression, String errMessage)
-
isTrue
public static void isTrue(boolean expression)
-
isFalse
public static void isFalse(boolean expression)
-
notNull
public static void notNull(Object object)
-
notEmpty
public static void notEmpty(Collection<?> collection, String errorCode, String errMessage)
-
notEmpty
public static void notEmpty(Collection<?> collection, String errMessage)
-
notEmpty
public static void notEmpty(Collection<?> collection)
-
notEmpty
public static void notEmpty(Map<?,?> map)
-
-