package com.gkhy.hazmat.common.utils;
|
|
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.StrUtil;
|
import org.springframework.util.AntPathMatcher;
|
|
import java.util.List;
|
|
import static org.apache.commons.lang3.StringUtils.startsWithAny;
|
|
public class StringUtils extends StrUtil {
|
|
/**
|
* 是否为http(s)://开头
|
*
|
* @param link 链接
|
* @return 结果
|
*/
|
public static boolean ishttp(String link)
|
{
|
/**
|
* http请求
|
*/
|
String HTTP = "http://";
|
|
/**
|
* https请求
|
*/
|
String HTTPS = "https://";
|
return startsWithAny(link, HTTP,HTTPS);
|
}
|
|
public static String capitalize(final String str){
|
return org.apache.commons.lang3.StringUtils.capitalize(str);
|
}
|
|
public static String replaceEach(final String text, final String[] searchList, final String[] replacementList){
|
return org.apache.commons.lang3.StringUtils.replaceEach(text, searchList, replacementList);
|
}
|
|
|
/**
|
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
|
*
|
* @param str 指定字符串
|
* @param strs 需要检查的字符串数组
|
* @return 是否匹配
|
*/
|
public static boolean matches(String str, List<String> strs)
|
{
|
if (isBlank(str) || ObjectUtil.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);
|
}
|
|
public static String addZeroForNum(String str, int strLength) {
|
int strLen = str.length();
|
if (strLen < strLength) {
|
while (strLen < strLength) {
|
StringBuffer sb = new StringBuffer();
|
sb.append("0").append(str);// 左补0
|
// sb.append(str).append("0");//右补0
|
str = sb.toString();
|
strLen = str.length();
|
}
|
}
|
|
return str;
|
}
|
|
}
|