mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
Merge pull request #692 from tellmenow/v5-master
Object的equals方法容易抛空指针异常,用java8的Objects.equals替换
This commit is contained in:
@@ -2,6 +2,8 @@ package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 将浮点数类型的number转换成英语的表达方式 <br>
|
||||
* 参考博客:http://blog.csdn.net/eric_sunah/article/details/8713226
|
||||
@@ -68,7 +70,7 @@ public class NumberWordFormater {
|
||||
StringBuilder lm = new StringBuilder(); // 用来存放转换後的整数部分
|
||||
for (int i = 0; i < lstrrev.length() / 3; i++) {
|
||||
a[i] = StrUtil.reverse(lstrrev.substring(3 * i, 3 * i + 3)); // 截取第一个叁位
|
||||
if (!a[i].equals("000")) { // 用来避免这种情况:1000000 = one million
|
||||
if (!Objects.equals(a[i],"000")) { // 用来避免这种情况:1000000 = one million
|
||||
// thousand only
|
||||
if (i != 0) {
|
||||
lm.insert(0, transThree(a[i]) + " " + parseMore(i) + " "); // 加:
|
||||
@@ -134,7 +136,7 @@ public class NumberWordFormater {
|
||||
String value;
|
||||
if (s.startsWith("0")) {// 是否小於100
|
||||
value = transTwo(s.substring(1));
|
||||
} else if (s.substring(1).equals("00")) {// 是否被100整除
|
||||
} else if (Objects.equals(s.substring(1),"00")) {// 是否被100整除
|
||||
value = parseFirst(s.substring(0, 1)) + " HUNDRED";
|
||||
} else {
|
||||
value = parseFirst(s.substring(0, 1)) + " HUNDRED AND " + transTwo(s.substring(1));
|
||||
|
@@ -5,18 +5,7 @@ import java.io.ObjectInputStream;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -688,7 +677,7 @@ class FastDateParser extends AbstractDateBasic implements DateParser {
|
||||
for (final String[] zoneNames : zones) {
|
||||
// offset 0 is the time zone ID and is not localized
|
||||
final String tzId = zoneNames[ID];
|
||||
if (tzId.equalsIgnoreCase("GMT")) {
|
||||
if ("GMT".equalsIgnoreCase(tzId)) {
|
||||
continue;
|
||||
}
|
||||
final TimeZone tz = TimeZone.getTimeZone(tzId);
|
||||
@@ -761,7 +750,7 @@ class FastDateParser extends AbstractDateBasic implements DateParser {
|
||||
*/
|
||||
@Override
|
||||
void setCalendar(final FastDateParser parser, final Calendar cal, final String value) {
|
||||
if (value.equals("Z")) {
|
||||
if (Objects.equals(value,"Z")) {
|
||||
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
} else {
|
||||
cal.setTimeZone(TimeZone.getTimeZone("GMT" + value));
|
||||
|
@@ -175,7 +175,7 @@ public class IdcardUtil {
|
||||
return isValidCard15(idCard);
|
||||
case 10: {// 10位身份证,港澳台地区
|
||||
String[] cardval = isValidCard10(idCard);
|
||||
return null != cardval && cardval[2].equals("true");
|
||||
return null != cardval && Objects.equals(cardval[2],"true");
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
@@ -280,9 +280,9 @@ public class IdcardUtil {
|
||||
if (idCard.matches("^[a-zA-Z][0-9]{9}$")) { // 台湾
|
||||
info[0] = "台湾";
|
||||
String char2 = idCard.substring(1, 2);
|
||||
if (char2.equals("1")) {
|
||||
if (Objects.equals(char2,"1")) {
|
||||
info[1] = "M";
|
||||
} else if (char2.equals("2")) {
|
||||
} else if (Objects.equals(char2,"2")) {
|
||||
info[1] = "F";
|
||||
} else {
|
||||
info[1] = "N";
|
||||
|
@@ -12,12 +12,7 @@ import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 反射工具类
|
||||
@@ -652,7 +647,7 @@ public class ReflectUtil {
|
||||
* @return 是否为equals方法
|
||||
*/
|
||||
public static boolean isEqualsMethod(Method method) {
|
||||
if (method == null || false == method.getName().equals("equals")) {
|
||||
if (method == null || false == Objects.equals(method.getName(),"equals")) {
|
||||
return false;
|
||||
}
|
||||
final Class<?>[] paramTypes = method.getParameterTypes();
|
||||
@@ -666,7 +661,7 @@ public class ReflectUtil {
|
||||
* @return 是否为hashCode方法
|
||||
*/
|
||||
public static boolean isHashCodeMethod(Method method) {
|
||||
return (method != null && method.getName().equals("hashCode") && method.getParameterTypes().length == 0);
|
||||
return (method != null && Objects.equals(method.getName(),"hashCode") && method.getParameterTypes().length == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,7 +671,7 @@ public class ReflectUtil {
|
||||
* @return 是否为toString方法
|
||||
*/
|
||||
public static boolean isToStringMethod(Method method) {
|
||||
return (method != null && method.getName().equals("toString") && method.getParameterTypes().length == 0);
|
||||
return (method != null && Objects.equals(method.getName(),"toString") && method.getParameterTypes().length == 0);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------- newInstance
|
||||
|
Reference in New Issue
Block a user