mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
enhance I42A6V
This commit is contained in:
parent
6468a0446d
commit
fd6885441e
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.6 (2021-07-23)
|
||||
# 5.7.6 (2021-07-26)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 增加FieldsComparator(pr#374@Gitee)
|
||||
@ -13,6 +13,8 @@
|
||||
* 【core 】 改进NetUtil.getLocalHost逻辑(issue#1717@Github)
|
||||
* 【core 】 UseragentUtil增加QQ、alipay、taobao、uc等浏览器识别支持(issue#1719@Github)
|
||||
* 【http 】 HttpRequest.form方法判断集合增强(pr#381@Gitee)
|
||||
* 【core 】 NumberUtil增加calculate方法
|
||||
* 【core 】 优化TextSimilarity.longestCommonSubstring性能(issue#I42A6V@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复RobotUtil双击右键问题(pr#1721@Github)
|
||||
|
@ -95,16 +95,15 @@ public class TextSimilarity {
|
||||
* @return 公共子串
|
||||
*/
|
||||
private static String longestCommonSubstring(String strA, String strB) {
|
||||
char[] chars_strA = strA.toCharArray();
|
||||
char[] chars_strB = strB.toCharArray();
|
||||
int m = chars_strA.length;
|
||||
int n = chars_strB.length;
|
||||
int m = strA.length();
|
||||
int n = strB.length();
|
||||
|
||||
// 初始化矩阵数据,matrix[0][0]的值为0, 如果字符数组chars_strA和chars_strB的对应位相同,则matrix[i][j]的值为左上角的值加1, 否则,matrix[i][j]的值等于左上方最近两个位置的较大值, 矩阵中其余各点的值为0.
|
||||
int[][] matrix = new int[m + 1][n + 1];
|
||||
// 初始化矩阵数据,matrix[0][0]的值为0, 如果字符数组chars_strA和chars_strB的对应位相同,则matrix[i][j]的值为左上角的值加1,
|
||||
// 否则,matrix[i][j]的值等于左上方最近两个位置的较大值, 矩阵中其余各点的值为0.
|
||||
final int[][] matrix = new int[m + 1][n + 1];
|
||||
for (int i = 1; i <= m; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (chars_strA[i - 1] == chars_strB[j - 1]) {
|
||||
if (strA.charAt(i - 1) == strB.charAt(j - 1)) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1] + 1;
|
||||
} else {
|
||||
matrix[i][j] = Math.max(matrix[i][j - 1], matrix[i - 1][j]);
|
||||
@ -112,7 +111,8 @@ public class TextSimilarity {
|
||||
}
|
||||
}
|
||||
|
||||
// 矩阵中,如果matrix[m][n]的值不等于matrix[m-1][n]的值也不等于matrix[m][n-1]的值, 则matrix[m][n]对应的字符为相似字符元,并将其存入result数组中。
|
||||
// 矩阵中,如果matrix[m][n]的值不等于matrix[m-1][n]的值也不等于matrix[m][n-1]的值,
|
||||
// 则matrix[m][n]对应的字符为相似字符元,并将其存入result数组中。
|
||||
char[] result = new char[matrix[m][n]];
|
||||
int currentIndex = result.length - 1;
|
||||
while (matrix[m][n] != 0) {
|
||||
@ -121,7 +121,7 @@ public class TextSimilarity {
|
||||
} else if (matrix[m][n] == matrix[m - 1][n]) {
|
||||
m--;
|
||||
} else {
|
||||
result[currentIndex] = chars_strA[m - 1];
|
||||
result[currentIndex] = strA.charAt(m - 1);
|
||||
currentIndex--;
|
||||
n--;
|
||||
m--;
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.math.Calculator;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
@ -2657,6 +2658,21 @@ public class NumberUtil {
|
||||
return false == (Float.isNaN(number) || Float.isInfinite(number));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算数学表达式的值,只支持加减乘除和取余<br>
|
||||
* 如:
|
||||
* <pre class="code">
|
||||
* calculate("(0*1--3)-5/-4-(3*(-2.13))") -》 10.64
|
||||
* </pre>
|
||||
*
|
||||
* @param expression 数学表达式
|
||||
* @return 结果
|
||||
* @since 5.7.6
|
||||
*/
|
||||
public static double calculate(String expression){
|
||||
return Calculator.conversion(expression);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------- Private method start
|
||||
private static int mathSubNode(int selectNum, int minNum) {
|
||||
if (selectNum == minNum) {
|
||||
|
Loading…
Reference in New Issue
Block a user