You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-java/src/main/java/com/glxp/api/util/DimaUtil.java

52 lines
1.4 KiB
Java

package com.glxp.api.util;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author AnthonyYwj
* @date 2024/11/12
*/
public class DimaUtil {
public static List<Integer> calculateLevels(String ratio) {
// 分割比例字符串并转成整数数组
String[] parts = ratio.split(":");
int[] levels = new int[parts.length];
for (int i = 0; i < parts.length; i++) {
levels[i] = Integer.parseInt(parts[i]);
}
// 存储每层级的倍数关系
List<Integer> calculatedLevels = new ArrayList<>();
for (int i = levels.length - 1; i > 0; i--) {
calculatedLevels.add(levels[i] / levels[i - 1]);
}
// 最后加上最小单位(第一层级为 1
calculatedLevels.add(1);
// 结果倒序
List<Integer> reversed = new ArrayList<>();
for (int i = calculatedLevels.size() - 1; i >= 0; i--) {
reversed.add(calculatedLevels.get(i));
}
return reversed;
}
public static Integer trMinCount(String bzgg) {
// 定义正则表达式模式,用于匹配数字
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(bzgg);
if (matcher.find()) {
return Integer.parseInt(matcher.group());
}
return null;
}
}