现场调度修改
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.schedule.util;
|
package com.ruoyi.schedule.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -37,7 +38,39 @@ public class CheckWeight {
|
|||||||
}
|
}
|
||||||
return zhi;
|
return zhi;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 用 Hutool 找出数组中出现次数最多的字符串
|
||||||
|
* @param strArray 目标字符串数组
|
||||||
|
* @return 出现次数最多的字符串(空数组返回 null,多最大值返回第一个)
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 兼容所有 Hutool 版本:找出数组中出现次数最多的字符串
|
||||||
|
* @param strArray 目标字符串数组
|
||||||
|
* @return 出现次数最多的字符串(空数组返回 null,多最大值返回第一个)
|
||||||
|
*/
|
||||||
|
public static String getMostFrequentByHutool(String[] strArray) {
|
||||||
|
// 1. 空值校验 + 数组转 List
|
||||||
|
if (strArray == null || strArray.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<String> strList = CollUtil.newArrayList(strArray);
|
||||||
|
|
||||||
|
// 2. 用 Hutool 统计频次(所有版本都支持)
|
||||||
|
Map<String, Integer> countMap = CollUtil.countMap(strList);
|
||||||
|
|
||||||
|
// 3. 手动遍历找最大值(替代不存在的 getMaxKey 方法)
|
||||||
|
String mostFrequent = null;
|
||||||
|
int maxCount = 0;
|
||||||
|
// 遍历 Map 条目,Hutool 5.x 及以上都支持 entrySet 遍历
|
||||||
|
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
|
||||||
|
if (entry.getValue() > maxCount) {
|
||||||
|
maxCount = entry.getValue();
|
||||||
|
mostFrequent = entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mostFrequent;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 将byte数组按指定编码转为char数组
|
* 将byte数组按指定编码转为char数组
|
||||||
* @param byteArr 输入的byte数组
|
* @param byteArr 输入的byte数组
|
||||||
|
|||||||
Reference in New Issue
Block a user