Class 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 null arguments, Assert can 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 by org.springframework.util.Assert
    Author:
    Frank Zhang
    • Constructor Detail

      • Assert

        public Assert()
    • Method Detail

      • isTrue

        public static void isTrue​(boolean expression,
                                  String errorCode,
                                  String errMessage)
        Assert a boolean expression, throwing BizException for example
        Assert.isTrue(i != 0, errorCode.B_ORDER_illegalNumber, "The order number can not be zero");
        Parameters:
        expression - a boolean expression
        errorCode -
        errMessage - the exception message to use if the assertion fails
        Throws:
        BizException - if expression is false
      • isFalse

        public static void isFalse​(boolean expression,
                                   String errorCode,
                                   String errMessage)
        Assert a boolean expression, if expression is true, throwing BizException for example
        Assert.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,
                                   String errorCode,
                                   String errMessage)
      • notNull

        public static void notNull​(Object object,
                                   String errMessage)
      • notNull

        public static void notNull​(Object object)
      • notEmpty

        public static void notEmpty​(Collection<?> collection,
                                    String errMessage)
      • notEmpty

        public static void notEmpty​(Collection<?> collection)
      • notEmpty

        public static void notEmpty​(Map<?,​?> map,
                                    String errorCode,
                                    String errMessage)
      • notEmpty

        public static void notEmpty​(Map<?,​?> map,
                                    String errMessage)
      • notEmpty

        public static void notEmpty​(Map<?,​?> map)