package com.nationalelectric.greenH5.identityAuth.util.devon; import java.io.Serializable; /** * 断言便捷方法,断言失败抛出相应的异常 * * @author ZhengDaHong@fzfx * @since 2017/8/7 13:42 */ public abstract class Assertion { //--------------------------------------------------------------------- // Null/Empty checks //--------------------------------------------------------------------- public static void notNull(Object object, String message) { if (object == null) { throw new IllegalArgumentException(message); } } public static void notNull(Object object) { notNull(object, "[Assertion failed] - this argument is required; it must not be null"); } public static void notEmpty(String string, String message) { if (StringUtils.isEmpty(string)) { throw new IllegalArgumentException(message); } } public static void notEmpty(String string) { notNull(string, "[Assertion failed] - this argument is required; it must not be empty"); } //--------------------------------------------------------------------- // Serializations //--------------------------------------------------------------------- public static void serializable(Object object, String message) { if(!(object instanceof Serializable)){ throw new IllegalArgumentException(message); } } public static void serializable(Object object) { serializable(object, "[Assertion failed] - this argument should implements interface Serializable"); } }