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

70 lines
2.1 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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--) {
if(levels[i - 1] > 0){
calculatedLevels.add(levels[i] / levels[i - 1]);
}
}
// 最后加上最小单位(第一层级为 1
calculatedLevels.add(0,1);
// 结果倒序
// List<Integer> reversed = new ArrayList<>();
// for (int i = calculatedLevels.size() - 1; i >= 0; i--) {
// reversed.add(calculatedLevels.get(i));
// }
return calculatedLevels;
}
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;
}
public static List<String> extractNumbers(String input) {
List<String> result = new ArrayList<>();
// 定义匹配小数和整数的正则表达式
String patternStr = "\\d+\\.\\d+|\\d+";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
String match = matcher.group();
if (match.contains(".")) {
result.add(Double.parseDouble(match)+"");
} else {
result.add(Integer.parseInt(match)+"");
}
}
return result;
}
}