StringUtils.java 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  1. package com.mixsmart.utils;
  2. import com.jfirer.baseutil.encrypt.Md5Util;
  3. import com.mixsmart.constant.IMixConstant;
  4. import com.mixsmart.exception.NullArgumentException;
  5. import java.io.UnsupportedEncodingException;
  6. import java.lang.reflect.Field;
  7. import java.lang.reflect.Modifier;
  8. import java.math.BigDecimal;
  9. import java.text.DecimalFormat;
  10. import java.text.SimpleDateFormat;
  11. import java.util.*;
  12. import java.util.regex.Matcher;
  13. import java.util.regex.Pattern;
  14. import java.util.stream.Collectors;
  15. /**
  16. * @Description:字符串处理工具类
  17. * @author:rock
  18. * @time:2020年4月21日 下午12:05:04
  19. * @version 1.0
  20. */
  21. public class StringUtils {
  22. private StringUtils() {
  23. throw new UnsupportedOperationException("StringUtils类无法实例化");
  24. }
  25. private static final String CHARSET_NAME = "UTF-8";
  26. /**
  27. * 判断是否为空
  28. * @param value 内容
  29. * @return 为空返回:true;否则返回:false
  30. */
  31. public static boolean isEmpty(String value) {
  32. return (null==value || value.trim().length()==0);
  33. }
  34. /**
  35. * @Description 批量判读为空
  36. * @Param [values]
  37. * @return boolean
  38. * @Author yangyj
  39. * @Date 2021.11.05 13:42
  40. **/
  41. public static boolean isEmpty(Object ...values) {
  42. for(Object value:values){
  43. if(!isEmpty(value)){
  44. return false;
  45. }
  46. }
  47. return true;
  48. }
  49. /**
  50. * 判断是否不为空
  51. * @param value 内容
  52. * @return 不为空返回:true;否则返回:false
  53. */
  54. public static boolean isNotEmpty(String value) {
  55. return !isEmpty(value);
  56. }
  57. /**
  58. * 判断参数;如果参数<code>value</code> 为空;
  59. * 则抛出参数为空异常(运行时异常)
  60. * @param value 需要判断的参数
  61. * @param msg 提示信息
  62. */
  63. public static void isAssert(Object value, String msg) {
  64. msg = isEmpty(msg)?"提供的参数为空":msg;
  65. if(null == value) {
  66. throw new NullArgumentException(msg);
  67. }
  68. if(value instanceof String) {
  69. if(isEmpty(value.toString())) {
  70. throw new NullArgumentException(msg);
  71. }
  72. } else if(value instanceof Collection) {
  73. if(CollectionUtils.isEmpty((Collection<?>)value)) {
  74. throw new NullArgumentException(msg);
  75. }
  76. } else if(value.getClass().isArray()) {
  77. if(ArrayUtils.isEmpty((Object[])value)) {
  78. throw new NullArgumentException(msg);
  79. }
  80. }
  81. }
  82. /**
  83. * 判断值是否相等
  84. * @param value1
  85. * @param value2
  86. * @return 相等返回:true;否则返回:false
  87. */
  88. public static boolean isEquals(Object value1, Object value2) {
  89. boolean is = false;
  90. if(null != value1 && null != value2) {
  91. is = value1.toString().equals(value2.toString());
  92. } else if(null == value1 && null == value2) {
  93. is = true;
  94. }
  95. return is;
  96. }
  97. /**
  98. * 判断值是否不相等
  99. * @param value1
  100. * @param value2
  101. * @return 相等返回:true;否则返回:false
  102. */
  103. public static boolean isNotEquals(Object value1, Object value2) {
  104. return !isEquals(value1, value2);
  105. }
  106. /**
  107. * 判断值是否相等(不区分大小写)
  108. * @param value1
  109. * @param value2
  110. * @return 相等返回:true;否则返回:false
  111. */
  112. public static boolean isEqualsIgnoreCase(Object value1, Object value2) {
  113. boolean is = false;
  114. if(null != value1 && null != value1) {
  115. is = value1.toString().equalsIgnoreCase(value2.toString());
  116. } else if(null == value1 && null == value1) {
  117. is = true;
  118. }
  119. return is;
  120. }
  121. /**
  122. * 判断值是否不相等(不区分大小写)
  123. * @param value1
  124. * @param value2
  125. * @return 相等返回:true;否则返回:false
  126. */
  127. public static boolean isNotEqualsIgnoreCase(Object value1, Object value2) {
  128. return !isEqualsIgnoreCase(value1, value2);
  129. }
  130. /**
  131. * null转换为“”
  132. * @param obj
  133. * @return 返回处理后的结果
  134. */
  135. public static String handleNull(Object obj) {
  136. if (null == obj) {
  137. return "";
  138. } else {
  139. return obj.toString().trim();
  140. }
  141. }
  142. /**
  143. * 当值为null转化为“null”
  144. * @param obj
  145. * @return 返回处理后的结果
  146. */
  147. public static String nullToStr(Object obj) {
  148. if (null == obj) {
  149. return "null";
  150. } else {
  151. return obj.toString().trim();
  152. }
  153. }
  154. /**
  155. * 对象转化为整型
  156. * <p>注:该方法已过时,请用{@link #handleObj2Integer(Object)} 代替</p>
  157. * @param obj
  158. * @return 返回转化结果
  159. */
  160. public static Integer handObj2Integer(Object obj) {
  161. return handleObj2Integer(obj);
  162. }
  163. /**
  164. * 对象转化为整型
  165. * @param obj
  166. * @return 返回转化结果
  167. */
  168. public static Integer handleObj2Integer(Object obj) {
  169. if (null == obj) {
  170. return 0;
  171. } else {
  172. double value = 0;
  173. try {
  174. value = Double.parseDouble(obj.toString());
  175. } catch (Exception ex) {
  176. value = 0;
  177. }
  178. return (int)value;
  179. }
  180. }
  181. /**
  182. * @Description 对象转Double
  183. * @Param [obj, scale]
  184. * @return java.lang.Double
  185. * @Author yangyj
  186. * @Date 2022.04.20 14:15
  187. **/
  188. public static Double obj2Double(Object obj,Object scale){
  189. if(StringUtils.isNumber(obj)){
  190. if(StringUtils.isNumber(scale)){
  191. obj=new BigDecimal(StringUtils.number2String(obj,scale));
  192. }
  193. BigDecimal big = new BigDecimal(obj.toString());
  194. return big.doubleValue();
  195. }
  196. return null;
  197. }
  198. public static Double obj2Double(Object obj){
  199. return obj2Double(obj,null);
  200. }
  201. /**
  202. * 数字null转换为“0”
  203. * @param obj
  204. * @return 返回转化结果
  205. */
  206. public static String handleNumNull(Object obj) {
  207. if (null == obj) {
  208. return "0";
  209. } else {
  210. return obj.toString().trim();
  211. }
  212. }
  213. /**
  214. * 判断是否为数字(包括小数)
  215. * @param value
  216. * @return 数字返回:true;否则返回:false
  217. */
  218. public static boolean isNum(Object value) {
  219. boolean is = false;
  220. if(value != null) {
  221. Pattern pattern = Pattern.compile("\\d+|\\d+\\.\\d+");
  222. Matcher matcher = pattern.matcher(value.toString());
  223. if(matcher.matches()) {
  224. is = true;
  225. } else {
  226. is = false;
  227. }
  228. }
  229. return is;
  230. }
  231. /**
  232. * 判断是否数字整数
  233. * @param value
  234. * @return 是返回:true;否则返回:false
  235. */
  236. public static boolean isInteger(String value) {
  237. boolean is = false;
  238. Pattern pattern = Pattern.compile("\\d+");
  239. if(null != value && value.length()>1) {
  240. pattern = Pattern.compile("^[1-9]\\d+");
  241. }
  242. Matcher matcher = pattern.matcher(value);
  243. if(matcher.matches()) {
  244. is = true;
  245. } else {
  246. is = false;
  247. }
  248. return is;
  249. }
  250. /**
  251. * 判断是否小数
  252. * @param value
  253. * @return 是返回:true;否则返回:false
  254. */
  255. public static boolean isDecimal(String value) {
  256. boolean is = false;
  257. Pattern pattern = Pattern.compile("\\d+\\.\\d+");
  258. Matcher matcher = pattern.matcher(value);
  259. if(matcher.matches()) {
  260. is = true;
  261. } else {
  262. is = false;
  263. }
  264. return is;
  265. }
  266. /**
  267. * 随机生成数
  268. * @param num 要生成随机数的个数
  269. * @return 返回随机生成数
  270. */
  271. public static String randomNum(int num) {
  272. Random random = new Random();
  273. String numStr = "";
  274. for (int i = 0; i < num; i++) {
  275. numStr += random.nextInt(10);
  276. }
  277. return numStr;
  278. }
  279. /**
  280. * 按日期格式生成序列号
  281. * @param dateFormaterStr 日期格式
  282. * @return 返回序列号
  283. */
  284. public static String createSerialNum(String dateFormaterStr) {
  285. String serialNum = null;
  286. if(isNotEmpty(dateFormaterStr)) {
  287. SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormaterStr);
  288. serialNum = dateFormatter.format(new Date());
  289. dateFormatter = null;
  290. }
  291. return serialNum;
  292. }
  293. /**
  294. * 生成序列号;
  295. * TODO 改为采用UUID生成序列号
  296. * 生成的序列号;如:U+时间+5位随机序列号
  297. * 如:U141264925197606685
  298. * @return 返回系统自动生成的序列号
  299. */
  300. public static String createSerialNum() {
  301. /*long time = System.currentTimeMillis();
  302. return "U"+time+randomNum(5);*/
  303. return uuid();
  304. }
  305. /**
  306. * 生成UUID序列号
  307. * @return 返回UUID
  308. */
  309. public static String uuid() {
  310. String value = UUID.randomUUID().toString();
  311. value = value.replaceAll("-", "");
  312. return value.substring(0, 28);
  313. }
  314. public static String uuid(int max) {
  315. String value = UUID.randomUUID().toString();
  316. value = value.replaceAll("-", "");
  317. return value.substring(0, max);
  318. }
  319. /**
  320. * 获取文件后缀
  321. * @param fileName
  322. * @return 返回文件后缀
  323. */
  324. public static String getFileSuffix(String fileName) {
  325. int index = fileName.lastIndexOf(".");
  326. if(index != -1) {
  327. return fileName.substring(index + 1);
  328. }
  329. return "";
  330. }
  331. /**
  332. * 去掉文件后缀
  333. * @param fileName
  334. * @return 返回文件后缀
  335. */
  336. public static String trimFileSuffix(String fileName) {
  337. return fileName.substring(0,fileName.lastIndexOf("."));
  338. }
  339. /**
  340. * 大写字母直接用下划线分割,并把大写转换为小写 <br />
  341. * 如:HelloWorld转换为hello_world
  342. * @param value
  343. * @return 返回处理结果
  344. */
  345. public static String upperSeparateUnderline(String value) {
  346. StringBuilder strBuilder = null;
  347. if(isNotEmpty(value)) {
  348. strBuilder = new StringBuilder();
  349. byte[] values = value.getBytes();
  350. for (int i = 0; i < values.length; i++) {
  351. if(values[i]>=65 && values[i]<=90) {
  352. if(i>0 && i<(values.length-1)) {
  353. strBuilder.append("_"+(char)((int)values[i]+32));
  354. } else {
  355. strBuilder.append(String.valueOf((char)((int)values[i]+32)));
  356. }
  357. } else {
  358. strBuilder.append(String.valueOf((char)values[i]));
  359. }
  360. }
  361. values = null;
  362. }
  363. return strBuilder != null ? strBuilder.toString() : null;
  364. }
  365. /**
  366. * 首字母转为大写
  367. * @param value
  368. * @return 返回处理后的结果
  369. */
  370. public static String firstToUppercase(String value) {
  371. if(isNotEmpty(value)) {
  372. String firstChar = value.substring(0, 1);
  373. String otherChar = value.substring(1);
  374. firstChar = firstChar.toUpperCase();
  375. value = firstChar+otherChar;
  376. }
  377. return value;
  378. }
  379. /**
  380. * 过滤HTML标签.
  381. * @param htmlContent
  382. * @return 返回过滤后的结果
  383. */
  384. public static String html2Text(String htmlContent) {
  385. if(isEmpty(htmlContent))
  386. return htmlContent;
  387. Pattern pScript, pStyle, pHtml; //定义规则
  388. Matcher mScript, mStyle, mHtml; //匹配规则
  389. //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script>
  390. String regExScript = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
  391. //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style>
  392. String regExStyle = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
  393. //定义HTML标签的正则表达式
  394. String regExHtml = "<[^>]+>";
  395. //过滤script标签
  396. pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
  397. mScript = pScript.matcher(htmlContent);
  398. htmlContent = mScript.replaceAll("");
  399. //过滤style标签
  400. pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
  401. mStyle = pStyle.matcher(htmlContent);
  402. htmlContent = mStyle.replaceAll("");
  403. //过滤html标签
  404. pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
  405. mHtml = pHtml.matcher(htmlContent);
  406. htmlContent = mHtml.replaceAll("");
  407. return htmlContent;
  408. }
  409. /**
  410. * 验证手机号码
  411. * @param phoneNo
  412. * @return 验证成功返回:true;否则返回:false
  413. */
  414. public static boolean isPhoneNO(String phoneNo){
  415. Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
  416. Matcher m = p.matcher(phoneNo);
  417. return m.matches();
  418. }
  419. /**
  420. * 验证固定电话号码
  421. * @param tel
  422. * @return 验证成功返回:true;否则返回:false
  423. */
  424. public static boolean isFixedTelephone(String tel) {
  425. Pattern p = Pattern.compile("^[0][0-9]{2,3}-[2-9][0-9]{6,7}(-[0-9]{1,4})?");
  426. Matcher m = p.matcher(tel);
  427. return m.matches();
  428. }
  429. /**
  430. * 验证匿名
  431. * @param anonymous
  432. * @return 验证成功返回:true;否则返回:false
  433. */
  434. public static boolean isAnonymous(String anonymous){
  435. Pattern p = Pattern.compile("^[\\u4e00-\\u9fa5|A-Za-z]([\\w|\\u4e00-\\u9fa5]){1,7}$");
  436. Matcher m = p.matcher(anonymous);
  437. return m.matches();
  438. }
  439. /**
  440. * 验证汉字
  441. * @param value
  442. * @return 验证成功返回:true;否则返回:false
  443. */
  444. public static boolean isChinese(String value){
  445. Pattern p = Pattern.compile("^[\\u4E00-\\u9FFF]+$");
  446. Matcher m = p.matcher(value);
  447. boolean is = m.matches();
  448. return is;
  449. }
  450. /**
  451. * 验证正则表达式
  452. * @param value
  453. * @return 验证成功返回:true;否则返回:false
  454. */
  455. public static boolean isCheckRegex(String value,String regex){
  456. Pattern p = Pattern.compile(regex);
  457. Matcher m = p.matcher(value);
  458. boolean is = m.matches();
  459. return is;
  460. }
  461. /**
  462. * 验证QQ号码
  463. * @param value
  464. * @return 验证成功返回:true;否则返回:false
  465. */
  466. public static boolean isQQ(String value) {
  467. Pattern p = Pattern.compile("^[1-9]\\d{6,11}$");
  468. Matcher m = p.matcher(value);
  469. return m.matches();
  470. }
  471. /**
  472. * 验证email
  473. * @param email
  474. * @return 验证成功返回:true;否则返回:false
  475. */
  476. public static boolean isEmail(String email) {
  477. Pattern p = Pattern.compile("^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$");
  478. Matcher m = p.matcher(email);
  479. return m.matches();
  480. }
  481. /**
  482. * 秒转化为:HH:mm:SS格式
  483. * @param second
  484. * @return 返回转化后的结果
  485. */
  486. public static String secondToHHMMSS(long second){
  487. long h=0,m=0,s=0,tmp=0;
  488. if(second>=3600){
  489. h= second/3600;
  490. tmp = second%36000;
  491. if(tmp>=60) {
  492. m = tmp/60;
  493. s = tmp%60;
  494. }else {
  495. s = tmp;
  496. }
  497. }else if(second>=60){
  498. m = second/60;
  499. s = second%60;
  500. }else {
  501. s = second;
  502. }
  503. return (h>9?h:"0"+h)+":"+(m>9?m:"0"+m)+":"+(s>9?s:"0"+s);
  504. }
  505. /**
  506. * 过滤特殊字符
  507. * @param params
  508. * @return 返回过滤后的结果
  509. */
  510. public static String filterSQLParams(String params) {
  511. if(!isEmpty(params)) {
  512. StringBuilder strBuilder = new StringBuilder();
  513. strBuilder.append("'|\"|update|delete|select|drop|insert|=|;|0x|\\(|\\)|\\s|\\*|\\?|\\%|\\$");
  514. strBuilder.append("|and|exec|execute|chr|mid|master|truncate|char|declare|sitename|net user|xp_cmdshell|or");
  515. strBuilder.append("|\\+|,|like'|table|from|grant|use|group_concat|column_name|information_schema.columns");
  516. strBuilder.append("|table_schema|union|where|order|by|count");
  517. strBuilder.append("|--|,|like|//|/|#");
  518. String params1 = params.toLowerCase();
  519. params1 = params1.replaceAll(strBuilder.toString(), "");
  520. if("".equals(params1)&&!"''".equals(params)){
  521. params = params1;
  522. }
  523. params = params.replaceAll("&", "&amp");
  524. params = params.replaceAll("<", "&lt");
  525. params = params.replaceAll(">", "&gt");
  526. }
  527. return params;
  528. }
  529. /**
  530. * 根据regex分隔字符串
  531. * 然后用逗号","重组
  532. * @param ids
  533. * @param regex
  534. * @return 返回处理后的结果
  535. */
  536. public static String splitIds(String ids,String regex){
  537. String newIds = "";
  538. if(isNotEmpty(ids)) {
  539. String[] idsArr = ids.split(regex);
  540. for (int i = 0; i < idsArr.length; i++) {
  541. if(i != (idsArr.length-1)) {
  542. newIds += "'"+idsArr[i]+"',";
  543. } else {
  544. newIds += "'"+idsArr[i]+"'";
  545. }
  546. }
  547. }
  548. return newIds;
  549. }
  550. /**
  551. * 计算出文件大小
  552. * @param size
  553. * @return 返回处理后的结果;<br />
  554. * 格式为:"100 KB"或”100 M“或”100 G“
  555. */
  556. public static String fileSize(long size) {
  557. DecimalFormat df = new DecimalFormat("0.0#");
  558. long KB = 1024;
  559. long MB = KB*1024;
  560. long GB = MB*1024;
  561. String valueStr = null;
  562. if(size<0) {
  563. valueStr = "0 KB";
  564. } else if(size<KB*1024) {
  565. double value = (double)size/KB;
  566. valueStr = df.format(value)+" KB";
  567. } else if(size<MB*1024) {
  568. double value = (double)size/MB;
  569. valueStr = df.format(value)+" M";
  570. } else {
  571. double value = (double)size/GB;
  572. valueStr = df.format(value)+" G";
  573. }
  574. df = null;
  575. return valueStr;
  576. }
  577. /**
  578. * 过滤目录结构(防止参数传递目录结构)
  579. * @param value
  580. * @return 返回过滤后的结果
  581. */
  582. public static String filterFilePath(String value) {
  583. if(!StringUtils.isEmpty(value)) {
  584. value.replaceAll("\\.|/|\\\\\\\\|\\\\|:|%2F|%2E|25%|20%|%5C|60%|27%|%3A|%2A","");
  585. }
  586. return value;
  587. }
  588. /**
  589. * 判断是否含有contain指定的值
  590. * @param value
  591. * @param contain
  592. * @return 包含返回:true;否则返回:false
  593. */
  594. public static boolean isContains(String value,String contain) {
  595. boolean is = false;
  596. if(!isEmpty(value) && null != contain) {
  597. is = value.indexOf(contain)>-1?true:false;
  598. }
  599. return is;
  600. }
  601. /**
  602. * list转换为数组
  603. * @param values
  604. * @return 返回转化结果
  605. */
  606. public static String[] list2Array(Collection<String> values) {
  607. String[] valueArray = null;
  608. if(null != values && values.size()>0) {
  609. valueArray = new String[values.size()];
  610. values.toArray(valueArray);
  611. }
  612. return valueArray;
  613. }
  614. /**
  615. * 验证IP地址
  616. * @param ip
  617. * @return 验证成功返回:true;否则返回:false
  618. */
  619. public static boolean checkIp(String ip) {
  620. boolean is = false;
  621. String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
  622. + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
  623. + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
  624. + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
  625. Pattern pattern = Pattern.compile(regex);
  626. Matcher matcher = pattern.matcher(ip);
  627. if(matcher.matches()) {
  628. is = true;
  629. }
  630. return is;
  631. }
  632. /**
  633. * 集合转换为字符串,字符串之间用separater提供的参数分隔
  634. * @param values
  635. * @param separater
  636. * @return 返回处理后的结果
  637. */
  638. public static <T> String collection2String(Collection<T> values,String separater) {
  639. StringBuilder strBuilder = null;
  640. if(null != values && values.size()>0) {
  641. strBuilder = new StringBuilder();
  642. if(isEmpty(separater)) {
  643. separater = "";
  644. }
  645. for (T value : values) {
  646. strBuilder.append(StringUtils.handleNull(value) + separater);
  647. }
  648. if(isNotEmpty(separater)) {
  649. strBuilder.delete(strBuilder.length()-1, strBuilder.length());
  650. }
  651. }
  652. return strBuilder != null ? strBuilder.toString():null;
  653. }
  654. /**
  655. * 替换多个空格、换行、回车、tab符等为一个空格
  656. * @param value 预处理的字符串
  657. * @return 返回处理后的字符串
  658. */
  659. public static String removeMultiSpace(String value) {
  660. if(StringUtils.isNotEmpty(value)) {
  661. value = value.replaceAll("\\s+|\n|\r|\n|\t", " ");
  662. }
  663. return value;
  664. }
  665. /**
  666. * 替换特殊字符
  667. * @param value 预处理的字符串
  668. * @return 返回处理后的结果
  669. */
  670. public static String repaceSpecialChar(String value) {
  671. if(isNotEmpty(value)) {
  672. value = value.replaceAll("\r|\n|\t", "");
  673. }
  674. return value;
  675. }
  676. public static String changeQuotation (String value) {
  677. if(isNotEmpty(value)) {
  678. value = value.replaceAll("'", "\\\\u0027");
  679. }
  680. return value;
  681. }
  682. /**
  683. * 替换斜杠
  684. * @param value
  685. * @return 返回处理后的结果
  686. */
  687. public static String repaceSlash(String value) {
  688. if(isNotEmpty(value)) {
  689. //value = value.replaceAll("\\\\", "\\\\\\\\\\\\\\\\");
  690. value = value.replaceAll("\\\\", "\\\\\\\\");
  691. value = value.replaceAll("`", "\\\\`");
  692. value = value.replaceAll("'", "\\\\`");
  693. }
  694. return value;
  695. }
  696. /**
  697. * 替换斜杠
  698. * @param value
  699. * @return 返回处理后的结果
  700. */
  701. public static String repaceSlashCopyTable(String value) {
  702. if(isNotEmpty(value)) {
  703. //value = value.replaceAll("\\\\", "\\\\\\\\\\\\\\\\");
  704. //value = value.replaceAll("\\\\", "\\\\\\\\");
  705. value = value.replaceAll("`", "\\\\`");
  706. }
  707. return value;
  708. }
  709. /**
  710. * 去空格
  711. * @param value
  712. * @return 返回处理后的结果
  713. */
  714. public static String repaceBlank(String value) {
  715. if(isNotEmpty(value)) {
  716. value = value.replaceAll("\\s", "");
  717. }
  718. return value;
  719. }
  720. /**
  721. * 字符串转换为list
  722. * @param value 要转换的字符串
  723. * @param separater 分隔符
  724. * @return 返回转换后的List
  725. */
  726. public static List<String> string2List(String value, String separater) {
  727. List<String> lists = null;
  728. if(isNotEmpty(value)) {
  729. separater = isEmpty(separater)?",":separater;
  730. String[] array = value.split(separater);
  731. lists = Arrays.asList(array);
  732. }
  733. return lists;
  734. }
  735. /**
  736. * 字符串转换为Set
  737. * @param value 要转换的字符串
  738. * @param separater 分隔符
  739. * @return 返回转换后的Set
  740. */
  741. public static Set<String> string2Set(String value, String separater) {
  742. Set<String> sets = null;
  743. if(isNotEmpty(value)) {
  744. separater = isEmpty(separater) ? "," : separater;
  745. String[] array = value.split(separater);
  746. sets = new HashSet<String>();
  747. sets.addAll(Arrays.asList(array));
  748. }
  749. return sets;
  750. }
  751. /**
  752. * 处理URL参数;
  753. * 判断 <code>url</code> 中是否有“?”;
  754. * 如果有则会在 <code>url</code> 后面加“&”,没有则加“?”
  755. * @param url URL字符串
  756. * @return 返回处理后的URL
  757. */
  758. public static String handleUrlParam(String url) {
  759. if(isEmpty(url)) {
  760. return url;
  761. }
  762. StringBuilder urlBuilder = new StringBuilder(url);
  763. if(url.indexOf("?") == -1) {
  764. urlBuilder.append("?");
  765. } else {
  766. urlBuilder.append("&");
  767. }
  768. return urlBuilder.toString();
  769. }
  770. /**
  771. * 处理路径;判断路径后是否有"/";如果没有则加上,如果有则不处理
  772. * @param path 路径
  773. * @return 返回处理后的路径
  774. */
  775. public static String handlePath(String path) {
  776. if(isEmpty(path)) {
  777. return path;
  778. }
  779. if(!path.endsWith("/")) {
  780. path = path + "/";
  781. }
  782. return path;
  783. }
  784. /**
  785. * 如果值为空“”转换为NULL
  786. * @param value
  787. * @return
  788. */
  789. public static String empty2Null(String value) {
  790. return isEmpty(value) ? null : value;
  791. }
  792. /**
  793. * 移除多值,只获取第一个值;多值之间通过英文逗号分隔
  794. * @param value 需要处理的值
  795. * @return 返回处理后的值
  796. */
  797. public static String removeMultiValue(String value) {
  798. if(isEmpty(value)) {
  799. return value;
  800. }
  801. int p = value.indexOf(IMixConstant.MULTI_VALUE_SPLIT);
  802. if(p >= 0) {
  803. value = value.substring(0, p);
  804. }
  805. return value;
  806. }
  807. /**
  808. * @author: willSir
  809. * @Date: 2020/8/17 - 13:57
  810. * @Description: 根据分隔符移除多余值
  811. *
  812. */
  813. public static String removeMultiValueBySplit(String value,String removeStr,String split) {
  814. if(isEmpty(value)||isEmpty(removeStr)) {
  815. return value;
  816. }
  817. int p = value.indexOf(split);
  818. if(p >= 0) {
  819. String[] valueAarry = value.split(split);
  820. String[] removeStrAarry = removeStr.split(split);
  821. List<String> asList = Arrays.asList(valueAarry);
  822. List<String> valueAarryList = new ArrayList();
  823. for (String v:asList){valueAarryList.add(v);}
  824. for (int i = 0; i < removeStrAarry.length; i++) {
  825. if(valueAarryList.contains(removeStrAarry[i])){
  826. valueAarryList.remove(removeStrAarry[i]);
  827. }
  828. }
  829. StringBuilder stringBuffer = new StringBuilder();
  830. for (int i = 0; i < valueAarryList.size(); i++) {
  831. stringBuffer.append(valueAarryList.get(i));
  832. if(i!=valueAarryList.size()-1){
  833. stringBuffer.append(split);
  834. }
  835. }
  836. value = stringBuffer.toString();
  837. }
  838. return value;
  839. }
  840. /**
  841. * 数组转化为字符串;
  842. * 如果<code>separate</code>为空,则采用默认值;默认值为:{@link IMixConstant#MULTI_VALUE_SPLIT}
  843. * @param objs 数组
  844. * @param separate 分隔符
  845. * @return 返回数组转化成功后的字符串;失败返回:null
  846. */
  847. public static String arrayToString(Object[] objs,String separate) {
  848. StringBuilder strBuff = null;
  849. if(null == objs || objs.length == 0) {
  850. return null;
  851. }
  852. if(StringUtils.isEmpty(separate)) {
  853. separate = IMixConstant.MULTI_VALUE_SPLIT;
  854. }
  855. strBuff = new StringBuilder();
  856. for (int i=0;i<objs.length;i++) {
  857. if(i < objs.length-1 ) {
  858. strBuff.append(String.valueOf(objs[i]) + separate);
  859. } else {
  860. strBuff.append(String.valueOf(objs[i]));
  861. }
  862. }//for
  863. objs = null;
  864. return (null != strBuff)?strBuff.toString():null;
  865. }
  866. /**
  867. * 字符串转化为数组;
  868. * 如果<code>separate</code>为空,则采用默认值;默认值为:{@link IMixConstant#MULTI_VALUE_SPLIT}
  869. * @param value 原字符串
  870. * @param separate 分隔符
  871. * @return 返回字符串分割成功后的数组
  872. */
  873. public static String[] stringToArray(String value, String separate) {
  874. String[] array = null;
  875. if(isEmpty(separate)) {
  876. separate = IMixConstant.MULTI_VALUE_SPLIT;
  877. }
  878. if(isNotEmpty(value)) {
  879. array = value.split(separate);
  880. }
  881. value = null;
  882. return array;
  883. }
  884. /**
  885. * 按separate分离成数组,判断该数组里面是否包含subStr;
  886. * 如果<code>separate</code>为空,则采用默认值;默认值为:{@link IMixConstant#MULTI_VALUE_SPLIT}
  887. * @param str 字符串
  888. * @param subStr 子字符串
  889. * @param separate 分隔符
  890. * @return 包含返回:true;否则返回:false
  891. */
  892. public static boolean isArrayContains(String str,String subStr,String separate) {
  893. if(isEmpty(str)) {
  894. return isEmpty(subStr);
  895. }
  896. if(null == subStr) {
  897. return true;
  898. }
  899. boolean is = false;
  900. if(isEmpty(separate)) {
  901. separate = IMixConstant.MULTI_VALUE_SPLIT;
  902. }
  903. String[] strArray = str.split(separate);
  904. for (int i = 0; i < strArray.length; i++) {
  905. if(subStr.equals(strArray[i].trim())) {
  906. is = true;
  907. break;
  908. }
  909. }//for
  910. return is;
  911. }
  912. /**
  913. * 填补位数;如果<code>fillText</code>为空,则默认填充内容为“0”
  914. * @param value 需要填补的值
  915. * @param num 需要填补的位数
  916. * @param fillText 填充内容
  917. * @return 返回处理后的值
  918. */
  919. public static String supplementDigit(String value, int num, String fillText) {
  920. if(isEmpty(value)) {
  921. return value;
  922. }
  923. if(value.length() >= num) {
  924. return value;
  925. }
  926. if(isEmpty(fillText)) {
  927. fillText = "0";
  928. }
  929. StringBuilder stringBuilder = new StringBuilder();
  930. int fillNum = num - value.length();
  931. for(int i = 0; i < fillNum; i++) {
  932. stringBuilder.append(fillText);
  933. }
  934. stringBuilder.append(value);
  935. return stringBuilder.toString();
  936. }
  937. /**
  938. * 判断对象是否为空,或转换为字符串后的值是否为空
  939. * @param value 需要判断的值
  940. * @return 为空(null或“”)返回true;否则返回false
  941. */
  942. public static boolean isEmpty(Object value) {
  943. if(null == value) {
  944. return true;
  945. } else {
  946. return isEmpty(handleNull(value));
  947. }
  948. }
  949. /**
  950. * 判断对象是否不为空;
  951. * @param value 需要判断的值
  952. * @return 如果不为空返回true;否则返回false
  953. */
  954. public static boolean isNotEmpty(Object value) {
  955. return !isEmpty(value);
  956. }
  957. /**
  958. * @Description 批量非空校验
  959. * @Param [values]
  960. * @return boolean
  961. * @Author yangyj
  962. * @Date 2021.10.19 17:04
  963. **/
  964. public static boolean isNotEmpty(Object ...values) {
  965. for(Object value:values){
  966. if(isEmpty(value)){
  967. return false;
  968. }
  969. }
  970. return true;
  971. }
  972. /**
  973. * HTML转义(解码) <br />
  974. * 引入了StringEscapeUtils类
  975. * @param value
  976. * @return 返回处理后的结果
  977. */
  978. // public static String unescapeHtml(String value) {
  979. // if(!isEmpty(value)) {
  980. // value = StringEscapeUtils.unescapeHtml4(value);
  981. // }
  982. // return value;
  983. // }
  984. /**
  985. * HTML转义(编码) <br />
  986. * 引入了StringEscapeUtils类
  987. * @param value
  988. * @return 返回处理后的结果
  989. *
  990. */
  991. // public static String escapeHtml(String value) {
  992. // if(!isEmpty(value)) {
  993. // value = StringEscapeUtils.escapeHtml4(value);
  994. // value = value.replaceAll(" ", "&nbsp;");
  995. // value = value.replaceAll("\r\n|\n", "<br />");
  996. // }
  997. // return value;
  998. // }
  999. /**
  1000. * 判断是否为数字,包括小数、负数
  1001. * @param value
  1002. * @return
  1003. * @author:rock
  1004. * @time:2020年4月15日 上午10:46:15
  1005. */
  1006. public static boolean isNumber(Object value) {
  1007. if(isEmpty(value)){
  1008. return false;
  1009. }
  1010. if(value instanceof Number){
  1011. return true;
  1012. }
  1013. String pattern = "^[+-]?\\d+(\\.\\d+)?$";
  1014. Pattern r = Pattern.compile(pattern);
  1015. Matcher m = r.matcher(String.valueOf(value));
  1016. return m.matches();
  1017. }
  1018. /**
  1019. * @Description
  1020. * @Param [obj] 对象转成map集合
  1021. * @return java.util.Map<java.lang.String,java.lang.Object>
  1022. * @Author yangyj
  1023. * @Date 2021.05.27 14:33
  1024. **/
  1025. public static Map<String, Object> objectToMap(Object obj) {
  1026. Map<String, Object> map = new HashMap<String,Object>();
  1027. try {
  1028. Class<?> clazz = obj.getClass();
  1029. for (Field field : clazz.getDeclaredFields()) {
  1030. field.setAccessible(true);
  1031. if(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
  1032. continue;
  1033. }
  1034. String fieldName = field.getName();
  1035. Object data =field.get(obj);
  1036. Object toStrValue = handleNull(data);
  1037. if(isNotEmpty(toStrValue)){
  1038. if(data.getClass().isArray()){
  1039. if(ArrayUtils.isNotEmpty((String[])data)){
  1040. map.put(fieldName,data);
  1041. }
  1042. }else {
  1043. map.put(fieldName,data);
  1044. }
  1045. }
  1046. }
  1047. }catch (Exception e){
  1048. e.printStackTrace();
  1049. }
  1050. return map;
  1051. }
  1052. /**
  1053. * @Description 包含空字段
  1054. * @Param [obj] 对象转成map集合
  1055. * @return java.util.Map<java.lang.String,java.lang.Object>
  1056. * @Author yangyj
  1057. * @Date 2021.05.27 14:33
  1058. **/
  1059. // public static Map<String, Object> objectToMapNull(Object obj) {
  1060. // Map<String, Object> map = new HashMap<String,Object>();
  1061. // try {
  1062. // Class<?> clazz = obj.getClass();
  1063. // for (Field field : clazz.getDeclaredFields()) {
  1064. // field.setAccessible(true);
  1065. // if(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
  1066. // continue;
  1067. // }
  1068. // String fieldName = field.getName();
  1069. // Object data =field.get(obj);
  1070. // Object toStrValue = handleNull(data);
  1071. // if(isNotEmpty(toStrValue)&&data.getClass().isArray()){
  1072. // if(ArrayUtils.isNotEmpty((String[])data)){
  1073. // map.put(fieldName,data);
  1074. // }
  1075. // }else if(isNotEmpty(toStrValue)&&data instanceof Date){
  1076. // map.put(fieldName, DateUtil.dateToStr((Date) data,"yyyy-MM-dd HH:mm:ss"));
  1077. // }else {
  1078. // map.put(fieldName,toStrValue);
  1079. // }
  1080. // }
  1081. // }catch (Exception e){
  1082. // e.printStackTrace();
  1083. // }
  1084. // return map;
  1085. // }
  1086. /**
  1087. * @Description 返回字符串后n个字符
  1088. * @Param [str, n]
  1089. * @return java.lang.String
  1090. * @Author yangyj
  1091. * @Date 2021.08.06 16:31
  1092. **/
  1093. public static String tail(String str,int n){
  1094. if(isNotEmpty(str)&&str.length()>=n){
  1095. return str.substring(str.length()-n);
  1096. }else {
  1097. return str;
  1098. }
  1099. }
  1100. /**
  1101. * @Description list转字符串
  1102. * @Param [list, split:分隔符]
  1103. * @return java.lang.String
  1104. * @Author yangyj
  1105. * @Date 2021.08.06 17:11
  1106. **/
  1107. public static String join(List<String>list,String split){
  1108. StringBuilder sb = new StringBuilder("");
  1109. if(ListUtils.isNotEmpty(list)){
  1110. for(String str:list){
  1111. if(StringUtils.isNotEmpty(str)){
  1112. sb.append(str).append(split);
  1113. }
  1114. }
  1115. if(sb.length()>0&&isNotEmpty(split)){
  1116. sb.delete(sb.length()-split.length(),sb.length());
  1117. }
  1118. }
  1119. return sb.toString();
  1120. }
  1121. public static String join(List<String>list){
  1122. return join(list,null);
  1123. }
  1124. public static String join(Object ...args){
  1125. if(args!=null){
  1126. if(args.length>2){
  1127. List<String> list =Arrays.stream(args).limit(args.length - 1).map(StringUtils::handleNull).collect(Collectors.toList());
  1128. String split=handleNull(args[args.length-1]);
  1129. return join(list,split);
  1130. }else{
  1131. return handleNull(args[0]);
  1132. }
  1133. }else {
  1134. return "";
  1135. }
  1136. }
  1137. /**
  1138. * @Description 获取实体映射所有表字段名
  1139. * @Param [clazz]
  1140. * @return java.util.List<java.lang.String>
  1141. * @Author yangyj
  1142. * @Date 2021.08.18 11:05
  1143. **/
  1144. // public static Map<String,String> getFiledAnnotate(Class<?> clazz) {
  1145. // LinkedHashMap<String,String> names = new LinkedHashMap<>();
  1146. // Field[] fields = clazz.getDeclaredFields();
  1147. // Method[] methods=clazz.getMethods();
  1148. // for (Field field:fields) {
  1149. // field.setAccessible(true);
  1150. // if(field.isAnnotationPresent(Column.class)) {
  1151. // names.put(field.getDeclaredAnnotation(Column.class).name(),isEquals(field.getType().toString(),String.class)?"''":"null");
  1152. // }
  1153. // }
  1154. // for (Method m:methods) {
  1155. // m.setAccessible(true);
  1156. // if(m.isAnnotationPresent(Column.class)) {
  1157. // names.put(m.getDeclaredAnnotation(Column.class).name(),isEquals(m.getReturnType().toString(),String.class)?"''":"null");
  1158. // }
  1159. // }
  1160. // return names;
  1161. // }
  1162. /**
  1163. * @Description 只查询出指定字段内容
  1164. * @Param [clazz, fields]
  1165. * @return java.lang.String
  1166. * @Author yangyj
  1167. * @Date 2021.08.18 11:18
  1168. **/
  1169. // public static String selectFieldsBuilder(Class<?>clazz,String ...fields){
  1170. // StringBuilder sb = new StringBuilder();
  1171. // Map<String,String> fieldsNames=getFiledAnnotate(clazz);
  1172. // if(MapUtils.isNotEmpty(fieldsNames)){
  1173. // if(ArrayUtils.isEmpty(fields)){
  1174. // sb.append(" * ");
  1175. // }else{
  1176. // HashSet<String> keys = new HashSet<>(Arrays.asList(fields));
  1177. // for(Map.Entry<String,String> entry:fieldsNames.entrySet()){
  1178. // if(!keys.contains(entry.getKey())){
  1179. // sb.append(entry.getValue()).append(" as ");
  1180. // }
  1181. // sb.append(entry.getKey()).append(",");
  1182. // }
  1183. // if(sb.lastIndexOf(",")==sb.length()-1){
  1184. // sb.deleteCharAt(sb.length()-1);
  1185. // }
  1186. // }
  1187. // }
  1188. // return sb.toString();
  1189. // }
  1190. public static String toString(byte[] bytes) {
  1191. try {
  1192. return new String(bytes, CHARSET_NAME);
  1193. } catch (UnsupportedEncodingException e) {
  1194. return "";
  1195. }
  1196. }
  1197. /**
  1198. * @Description 返回保留指定小数位数字字符串
  1199. * @Param [number, scale]
  1200. * @return java.lang.String
  1201. * @Author yangyj
  1202. * @Date 2021.10.15 10:35
  1203. **/
  1204. public static String number2String(Object number, Object scale){
  1205. if(isNumber(number)){
  1206. if(isEmpty(scale)){
  1207. scale=0;
  1208. }
  1209. return new BigDecimal(handleNull(number)).setScale(handleObj2Integer(scale),BigDecimal.ROUND_HALF_UP).toString();
  1210. }
  1211. return "";
  1212. }
  1213. /**
  1214. * @Description byte数组转Md5字符串
  1215. * @Param [bytes]
  1216. * @return java.lang.String
  1217. * @Author yangyj
  1218. * @Date 2021.12.20 17:10
  1219. **/
  1220. public static String bytes2Md5(byte[] bytes){
  1221. StringBuffer sb = new StringBuffer("");
  1222. byte b[] = Md5Util.md5(bytes);
  1223. int d;
  1224. for (int i = 0; i < b.length; i++) {
  1225. d = b[i];
  1226. if (d < 0) {
  1227. d = b[i] & 0xff;
  1228. // 与上一行效果等同
  1229. // i += 256;
  1230. }
  1231. if (d < 16)
  1232. sb.append("0");
  1233. sb.append(Integer.toHexString(d));
  1234. }
  1235. return sb.toString();
  1236. }
  1237. /**
  1238. * 转换为字节数组
  1239. * @param str
  1240. * @return
  1241. */
  1242. public static byte[] getBytes(String str){
  1243. if (str != null){
  1244. try {
  1245. return str.getBytes(CHARSET_NAME);
  1246. } catch (UnsupportedEncodingException e) {
  1247. return null;
  1248. }
  1249. }else{
  1250. return null;
  1251. }
  1252. }
  1253. /**
  1254. * @Description 获取最大小数位
  1255. * @Param [number]
  1256. * @return int
  1257. * @Author yangyj
  1258. * @Date 2021.12.23 15:08
  1259. **/
  1260. // public static Integer getScale(Object ...number){
  1261. // int max=0;
  1262. // for(Object n:number){
  1263. // if(StringUtils.isNotEmpty(n)){
  1264. // String[] sa = n.toString().split(",");
  1265. // for(String s:sa){
  1266. // Matcher m = ReportUtils.matcher("(\\d)+.(\\d)+",s);
  1267. // if(m.find()){
  1268. // max=Math.max(new StringBuilder(m.group()).reverse().toString().indexOf("."),max);
  1269. // }
  1270. // }
  1271. // }
  1272. // }
  1273. // return max;
  1274. // }
  1275. /**
  1276. *
  1277. * @param name
  1278. * @param suffix
  1279. * @param splitStr
  1280. * @return
  1281. */
  1282. public static String addSuffixInFirst(String name ,String suffix,String splitStr) {
  1283. String newName = name;
  1284. if (isEmpty(name)) {
  1285. return newName;
  1286. }
  1287. int idx = name.indexOf(splitStr);
  1288. if (idx > 0) {
  1289. String templateName = name.substring(0,idx);
  1290. String templateNameNew = templateName + suffix;
  1291. newName = templateNameNew + name.substring(idx);
  1292. }
  1293. return newName;
  1294. }
  1295. public static String replaceSuffixInFirst(String name ,String suffix,String splitStr){
  1296. String newName = name;
  1297. if (isEmpty(name)) {
  1298. return newName;
  1299. }
  1300. int idx = name.indexOf(splitStr);
  1301. if (idx > 0) {
  1302. String templateName = name.substring(0,idx);
  1303. newName = newName.replace(templateName, suffix);
  1304. }
  1305. return newName;
  1306. }
  1307. /**
  1308. * @Description 匹配度
  1309. * @Param [a, b]
  1310. * @return boolean
  1311. * @Author yangyj
  1312. * @Date 2022.03.24 17:40
  1313. **/
  1314. public static boolean suitability(String a,String b){
  1315. if(StringUtils.isNotEmpty(a,b)){
  1316. char[] bA=b.toCharArray();
  1317. if(a.length()>=bA.length){
  1318. for (char c : bA) {
  1319. if (!a.contains(String.valueOf(c))) {
  1320. return false;
  1321. }
  1322. }
  1323. return true;
  1324. }
  1325. }
  1326. return false;
  1327. }
  1328. /*public static void main(String[] args) {
  1329. Map<String,Object> map = new HashMap<>();
  1330. map.put("yang",10);
  1331. map.put("a",-10);
  1332. List<String> list = Arrays.asList("1","12.6","856");
  1333. System.out.println(Expression.parse("a+6*yang").calculate(map).toString());
  1334. }*/
  1335. }