mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add null check
This commit is contained in:
@@ -35,7 +35,7 @@ import java.util.Set;
|
|||||||
* <ul>
|
* <ul>
|
||||||
* <li><a href="https://github.com/venusdrogon/feilong-core/wiki/one-jdk7-bug-thinking">one-jdk7-bug-thinking</a></li>
|
* <li><a href="https://github.com/venusdrogon/feilong-core/wiki/one-jdk7-bug-thinking">one-jdk7-bug-thinking</a></li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
* <p>
|
||||||
* TODO 需整理精简方法,去掉无用的重载方法。
|
* TODO 需整理精简方法,去掉无用的重载方法。
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
@@ -1242,11 +1242,13 @@ public class NumberUtil {
|
|||||||
* @return 是否为整数
|
* @return 是否为整数
|
||||||
*/
|
*/
|
||||||
public static boolean isInteger(final String s) {
|
public static boolean isInteger(final String s) {
|
||||||
|
if(StrUtil.isNotBlank(s)) {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(s);
|
Integer.parseInt(s);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1259,11 +1261,13 @@ public class NumberUtil {
|
|||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
public static boolean isLong(final String s) {
|
public static boolean isLong(final String s) {
|
||||||
|
if (StrUtil.isNotBlank(s)) {
|
||||||
try {
|
try {
|
||||||
Long.parseLong(s);
|
Long.parseLong(s);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1274,12 +1278,14 @@ public class NumberUtil {
|
|||||||
* @return 是否为{@link Double}类型
|
* @return 是否为{@link Double}类型
|
||||||
*/
|
*/
|
||||||
public static boolean isDouble(final String s) {
|
public static boolean isDouble(final String s) {
|
||||||
|
if (StrUtil.isNotBlank(s)) {
|
||||||
try {
|
try {
|
||||||
Double.parseDouble(s);
|
Double.parseDouble(s);
|
||||||
return s.contains(".");
|
return s.contains(".");
|
||||||
} catch (final NumberFormatException ignore) {
|
} catch (final NumberFormatException ignore) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -450,7 +450,15 @@ public class NumberUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void divIntegerTest(){
|
public void divIntegerTest(){
|
||||||
System.out.println(NumberUtil.div(100101300, (Number) 100));
|
final BigDecimal div = NumberUtil.div(100101300, (Number) 100);
|
||||||
|
Assert.assertEquals(1001013, div.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isDoubleTest(){
|
||||||
|
Assert.assertFalse(NumberUtil.isDouble(null));
|
||||||
|
Assert.assertFalse(NumberUtil.isDouble(""));
|
||||||
|
Assert.assertFalse(NumberUtil.isDouble(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user