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);
            }
        }
    }

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

  • 相关阅读:
    ec20 queclocator V1. 0 test
    javascript JSON.parse and JSON.stringify
    linux command pushd popd
    learning gcc #pragma once
    learning gcc __BEGIN_DECLS and __END_DECLS
    aarch-linux-gnu-g++ install
    启用”开始“菜单中的“运行”功能
    获取本机安装的软件清单
    固定任务栏
    优化菜单显示速度
  • 原文地址:https://www.cnblogs.com/television/p/9394429.html
Copyright © 2011-2022 走看看