1.算法列表
- 拼写inStr
- 去掉字符串后边的0
- 三者最小值
- 计算表达式的值
1.1 拼写inStr
public String getInStr(String stringWithComma) {
String splitSymbolComma = ",";
ArrayList<String> strList = CollectionUtil.toList(stringWithComma.split(splitSymbolComma));
return strList.stream().collect(Collectors.joining("\',\'", "\'", "\'"));
}
1.2 去掉字符串后边的0
public String dealZero(String str) {
String zeroStr = "0";
if (str.endsWith(zeroStr)) {
str = str.substring(0, str.length() - 1);
return dealZero(str);
} else {
return str;
}
}
1.3 三者最小值
public int min(int one, int two, int three) {
return (one = Math.min(one, two)) < three ? one : three;
}
1.4 计算表达式的值
private double calculateScoreByStr(String scoreStr) {
double score = 0.0;
if (StringUtils.isNotBlank(scoreStr)) {
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine se = sem.getEngineByName("js");
try {
score = (double) se.eval(scoreStr + "*1.0");
} catch (ScriptException e) {
log.error("计算[{}]时出现异常", scoreStr);
}
}
return score;
}