mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 20:27:58 +08:00
fix bug
This commit is contained in:
parent
21881a1609
commit
db20737abb
@ -20,7 +20,8 @@
|
||||
### Bug修复
|
||||
* 【core 】 修复NumberUtil.mul中null的结果错误问题(issue#I17Y4J@Gitee)
|
||||
* 【core 】 修复当金额大于等于1亿时,转换会多出一个万字的bug(pr#715@Github)
|
||||
* 【core 】 修复FileUtil.listFileNames位于jar内导致的文件找不到问题(issue#listFileNames@Gitee)
|
||||
* 【core 】 修复FileUtil.listFileNames位于jar内导致的文件找不到问题
|
||||
* 【core 】 修复TextSimilarity.similar去除字符导致的问题(issue#I17K2A@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -28,6 +28,7 @@ public class TextSimilarity {
|
||||
newStrA = removeSign(strA);
|
||||
newStrB = removeSign(strB);
|
||||
}
|
||||
|
||||
// 用较大的字符串长度作为分母,相似子串作为分子计算出字串相似度
|
||||
int temp = Math.max(newStrA.length(), newStrB.length());
|
||||
if(0 == temp) {
|
||||
@ -65,7 +66,7 @@ public class TextSimilarity {
|
||||
char c;
|
||||
for (int i = 0; i < length; i++) {
|
||||
c = str.charAt(i);
|
||||
if(false == isInvalidChar(c)) {
|
||||
if(isValidChar(c)) {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
@ -79,8 +80,8 @@ public class TextSimilarity {
|
||||
* @param charValue 字符
|
||||
* @return true表示为非汉字,数字和字母,false反之
|
||||
*/
|
||||
private static boolean isInvalidChar(char charValue) {
|
||||
return (charValue >= 0x4E00 && charValue <= 0XFFF) || //
|
||||
private static boolean isValidChar(char charValue) {
|
||||
return (charValue >= 0x4E00 && charValue <= 0X9FFF) || //
|
||||
(charValue >= 'a' && charValue <= 'z') || //
|
||||
(charValue >= 'A' && charValue <= 'Z') || //
|
||||
(charValue >= '0' && charValue <= '9');
|
||||
|
@ -1,10 +1,8 @@
|
||||
package cn.hutool.core.lang;
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.text.TextSimilarity;
|
||||
|
||||
/**
|
||||
* 文本相似度计算工具类单元测试
|
||||
* @author looly
|
||||
@ -21,6 +19,12 @@ public class TextSimilarityTest {
|
||||
Assert.assertEquals(0.8571428571428571D, degree, 16);
|
||||
|
||||
String similarPercent = TextSimilarity.similar(a, b, 2);
|
||||
Assert.assertEquals("85.71%", similarPercent);
|
||||
Assert.assertEquals("84.62%", similarPercent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void similarTest(){
|
||||
final double abd = TextSimilarity.similar("abd", "1111");
|
||||
Assert.assertEquals(0, abd, 1);
|
||||
}
|
||||
}
|
@ -1,15 +1,12 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.func.Func1;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ReUtilTest {
|
||||
final String content = "ZZZaaabbbccc中文1234";
|
||||
@ -52,7 +49,7 @@ public class ReUtilTest {
|
||||
@Test
|
||||
public void findAllTest() {
|
||||
// 查找所有匹配文本
|
||||
List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<String>());
|
||||
List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<>());
|
||||
ArrayList<String> expected = CollectionUtil.newArrayList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
Assert.assertEquals(expected, resultFindAll);
|
||||
}
|
||||
@ -82,13 +79,7 @@ public class ReUtilTest {
|
||||
@Test
|
||||
public void replaceAllTest2() {
|
||||
//此处把1234替换为 ->1234<-
|
||||
String replaceAll = ReUtil.replaceAll(this.content, "(\\d+)", new Func1<Matcher, String>() {
|
||||
|
||||
@Override
|
||||
public String call(Matcher parameters) {
|
||||
return "->" + parameters.group(1) + "<-";
|
||||
}
|
||||
});
|
||||
String replaceAll = ReUtil.replaceAll(this.content, "(\\d+)", parameters -> "->" + parameters.group(1) + "<-");
|
||||
Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user