69 lines
1.7 KiB
Java
69 lines
1.7 KiB
Java
package com.hamburg.common.utils;
|
||
|
||
import org.springframework.util.AntPathMatcher;
|
||
|
||
import java.util.Collection;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* @author DongZl
|
||
* @description: 字符串处理工具类
|
||
*/
|
||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||
|
||
/**
|
||
* * 判断一个对象是否为空
|
||
*
|
||
* @param object Object
|
||
* @return true:为空 false:非空
|
||
*/
|
||
public static boolean isNull(Object object) {
|
||
return object == null;
|
||
}
|
||
|
||
/**
|
||
* * 判断一个Collection是否为空, 包含List,Set,Queue
|
||
*
|
||
* @param coll 要判断的Collection
|
||
* @return true:为空 false:非空
|
||
*/
|
||
public static boolean isEmpty(Collection<?> coll) {
|
||
return isNull(coll) || coll.isEmpty();
|
||
}
|
||
|
||
/**
|
||
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
|
||
*
|
||
* @param str 指定字符串
|
||
* @param strs 需要检查的字符串数组
|
||
* @return 是否匹配
|
||
*/
|
||
public static boolean matches(String str, List<String> strs) {
|
||
if (isEmpty(str) || isEmpty(strs)) {
|
||
return false;
|
||
}
|
||
for (String pattern : strs) {
|
||
if (isMatch(pattern, str))
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* 判断url是否与规则配置:
|
||
* ? 表示单个字符;
|
||
* * 表示一层路径内的任意字符串,不可跨层级;
|
||
* ** 表示任意层路径;
|
||
*
|
||
* @param pattern 匹配规则
|
||
* @param url 需要匹配的url
|
||
* @return
|
||
*/
|
||
public static boolean isMatch(String pattern, String url) {
|
||
AntPathMatcher matcher = new AntPathMatcher();
|
||
return matcher.match(pattern, url);
|
||
}
|
||
}
|