zoukankan      html  css  js  c++  java
  • 断言类

    public final class Assert {
    
        private Assert() {
        }
    
        public static void notNull(Object object) {
            if (object == null) {
                throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR_IS_NULL);
            }
        }
    
        public static void notNull(Object... object) {
            for (Object obj : object) {
                if (obj == null) {
                    throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR_IS_NULL);
                }
            }
        }
    
        public static void isPositive(Long number) {
            if (number == null || number <= 0) {
                throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR);
            }
        }
    
        public static void isPositive(Long... number) {
            for (Long num : number) {
                if (num == null || num <= 0) {
                    throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR);
                }
            }
        }
    
        public static void isPositive(Integer number) {
            if (number == null || number <= 0) {
                throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR);
            }
        }
    
        public static void isPositive(Integer... number) {
            for (Integer num : number) {
                if (num == null || num <= 0) {
                    throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR);
                }
            }
        }
    
        public static void notEmpty(String str, ErrorCode errorCode) {
            if (StringUtils.isEmpty(str)) {
                throw new ApiRuntimeException(errorCode);
            }
        }
    
        public static void notBlank(String str, ErrorCode errorCode) {
            if (StringUtils.isBlank(str)) {
                throw new ApiRuntimeException(errorCode);
            }
        }
    
        public static void isTrue(boolean condition, ErrorCode errorCode) {
            if (!condition) {
                throw new ApiRuntimeException(errorCode);
            }
        }
    }

    断言类,用来在业务类之前判断参数。

  • 相关阅读:
    linux计划任务格式
    KVO监听数组的变化
    经典题目:输入半径求圆的面积
    /src/applicationContext.xml
    词法分析错题
    正规式与有限自动机
    词法分析程序的设计
    词法分析概述
    windows平台上 搭建 VisualSVN服务器 和 TortoiseSVN客户端
    maven error Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:3.1.0:single
  • 原文地址:https://www.cnblogs.com/television/p/9394429.html
Copyright © 2011-2022 走看看