Asserrt.java 1.08 KB
package com.huaheng.common.exception.base;

import com.huaheng.common.exception.service.ServiceException;
import org.springframework.lang.Nullable;

import java.util.List;

/**
 * @ClassName Assert
 * @Description TODO
 * @Author Administrator
 * @Date 2020/5/6 09:51
 */
public abstract class Asserrt {

    public Asserrt(){

    }

    //实体为空,抛异常
    public static void notNull(@Nullable Object object, String message){
        if(object == null || object == ""){
            throw new ServiceException(message);
        }
    }

    //实体为空,抛异常
    public static void notListNull(@Nullable List<?> list, String message){
        if(list.isEmpty()){
            throw new ServiceException(message);
        }
    }

    //修改失败抛异常
    public static void update(Integer number,String message){
        if(number < 1){
            throw new ServiceException(message);
        }
    }

    //false抛异常
    public static void isFalse(Boolean result,String message){
        if(!result){
            throw new ServiceException(message);
        }
    }
}