首页>代码>SSM+bootstrap开发vip客户消费后台管理系统>/vip/src/main/java/com/zout/common/AssertThrowUtil.java
package com.zout.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *@class_name:AssertThrowUtil
 *@param:impl下的验证工具类
 *@return: 
 *@author:Zoutao
 *@createtime:2018年3月14日
 */
public class AssertThrowUtil {
	public static String assertNotBlank(String message,String target){
		if(target==null||(target=target.trim()).length()==0){
			throw new ThisSystemException(message);
		}
		return target; 
	}
	//使用$符号代替throwIfBlank方法,简化表达。
	public static String $(String message,String target){
		return assertNotBlank(message, target);
	}
	//断言用户不是空。是空就抛出异常。
	public static void assertNotNull(String message,Object o){
    	if(o==null){
    		throw new ThisSystemException(message);
    	}
    }
	//断言用户是空。不是空就抛出异常。
	public static void assertNull(String message,Object o){
    	if(o!=null){
    		throw new ThisSystemException(message);
    	}
    }
	//断言用户是相等的,不相等就抛出异常。
    public static void assertEquals(String message,Object a,Object b){
    	if(a==null?a!=b:!a.equals(b)){
    		throw new ThisSystemException(message);
    	}
    }
  //断言新旧密码不一致的,一致就抛出异常。
    public static void assertNotEquals(String message,Object a,Object b){
    	if(a==null?a==b:a.equals(b)){
    		throw new ThisSystemException(message);
    	}
    }
    
    public static void assertTrue(String message,boolean b){
    	if(!b){
    		throw new ThisSystemException(message);
    	}
    	
    }
    public static void assertFalse(String message,boolean b){
    	if(b){
    		throw new ThisSystemException(message);
    	}
    }
    
    public static void assertPatternMatch(String message,String reg,String target){
    	Pattern pattern=Pattern.compile(reg);
    	Matcher matcher = pattern.matcher(target);
    	if(!matcher.matches()){
    		throw new ThisSystemException(message);
    	}
    }
    public static void main(String[] args) {
    	
    	Pattern pattern=Pattern.compile("[\u4e00-\u9fa5]{2,}");
    	Matcher matcher = pattern.matcher("张飞");
    	if(matcher.matches()){
    		System.out.println("ddd");
    		
    	}
	}
}
最近下载更多
723813519  LV2 4月1日
shuangfu  LV25 2023年12月2日
霖先生  LV2 2022年6月1日
17787885952  LV3 2022年5月5日
46546ww  LV1 2022年3月14日
sackaa  LV3 2021年12月18日
543666826  LV33 2021年11月19日
nitama  LV19 2021年5月26日
WaZiN7  LV6 2021年5月17日
最代码-宋家辉  LV61 2021年4月6日
最近浏览更多
723813519  LV2 4月1日
向左走向右走  LV1 4月1日
阿凡达  LV9 1月29日
WBelong  LV7 2023年12月27日
black8angel  LV4 2023年12月22日
bcp0524 2023年12月12日
暂无贡献等级
cyz521213  LV1 2023年12月9日
shuangfu  LV25 2023年12月2日
仙女山的月亮  LV2 2023年11月28日
527301883  LV1 2023年9月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友