fix bug and add timeout

This commit is contained in:
Looly
2022-05-30 07:44:45 +08:00
parent 30692987ff
commit 60a068db3f
5 changed files with 57 additions and 23 deletions

View File

@@ -1238,12 +1238,13 @@ public class NumberUtil {
* @return 是否为整数
*/
public static boolean isInteger(String s) {
if(StrUtil.isNotBlank(s)) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
}
if(StrUtil.isBlank(s)) {
return false;
}
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
@@ -1257,12 +1258,13 @@ public class NumberUtil {
* @since 4.0.0
*/
public static boolean isLong(String s) {
if(StrUtil.isNotBlank(s)) {
try {
Long.parseLong(s);
} catch (NumberFormatException e) {
return false;
}
if(StrUtil.isBlank(s)) {
return false;
}
try {
Long.parseLong(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
@@ -1274,15 +1276,16 @@ public class NumberUtil {
* @return 是否为{@link Double}类型
*/
public static boolean isDouble(String s) {
if(StrUtil.isNotBlank(s)) {
try {
Double.parseDouble(s);
return s.contains(".");
} catch (NumberFormatException ignore) {
// ignore
}
if(StrUtil.isBlank(s)) {
return false;
}
return false;
try {
Double.parseDouble(s);
return s.contains(".");
} catch (NumberFormatException ignore) {
// ignore
}
return true;
}
/**

View File

@@ -61,6 +61,9 @@ public class NumberUtilTest {
Assert.assertTrue(NumberUtil.isInteger("0256"));
Assert.assertTrue(NumberUtil.isInteger("0"));
Assert.assertFalse(NumberUtil.isInteger("23.4"));
Assert.assertFalse(NumberUtil.isInteger(null));
Assert.assertFalse(NumberUtil.isInteger(""));
Assert.assertFalse(NumberUtil.isInteger(" "));
}
@Test
@@ -70,6 +73,9 @@ public class NumberUtilTest {
Assert.assertTrue(NumberUtil.isLong("0256"));
Assert.assertTrue(NumberUtil.isLong("0"));
Assert.assertFalse(NumberUtil.isLong("23.4"));
Assert.assertFalse(NumberUtil.isLong(null));
Assert.assertFalse(NumberUtil.isLong(""));
Assert.assertFalse(NumberUtil.isLong(" "));
}
@Test