WechatGroup

This commit is contained in:
2025-09-22 17:06:47 +08:00
commit 410182ec79
542 changed files with 155561 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package com.ruoyi.cms.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class StringUtil {
public static Boolean isEmptyOrNull(String s){
if(Objects.isNull(s)){return true;}
return s.isEmpty();
}
/**
* 将逗号分隔的数字字符串转换为List<Integer>
*/
public static List<Integer> convertStringToIntegerList(String input) {
if (isEmptyOrNull(input)) {
return new ArrayList<>();
}
return Arrays.stream(input.split(",")) // 按逗号分割字符串
.map(String::trim) // 去除每个部分的前后空格
.map(Integer::parseInt) // 将字符串转换为Integer
.collect(Collectors.toList()); // 收集为List
}
/**
* 将逗号分隔的数字字符串转换为List<Integer>
*/
public static List<Long> convertStringToLongList(String input) {
List<Integer> longs = convertStringToIntegerList(input);
return longs.stream().map(Long::valueOf).collect(Collectors.toList());
}
/**
* 找到List<Integer>中的最大值
*/
public static Integer findMaxValue(String input) {
List<Integer> numbers = convertStringToIntegerList(input);
if (numbers == null || numbers.isEmpty()) {
return null;
}
return numbers.stream()
.mapToInt(Integer::intValue) // 将Integer转换为int
.max() // 找到最大值
.orElseThrow(() -> new RuntimeException("列表为空,无法找到最大值")); // 如果列表为空,抛出异常
}
}