mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-08 00:49:21 +08:00
修复无法对比boolean
This commit is contained in:
@@ -152,6 +152,11 @@ public abstract class CompareUtils {
|
||||
return compare(Arrays.asList(number), target);
|
||||
}
|
||||
|
||||
public static boolean compare(Boolean bool, Object target) {
|
||||
return bool.equals(target) || String.valueOf(bool).equals(target);
|
||||
}
|
||||
|
||||
|
||||
public static boolean compare(Number number, Object target) {
|
||||
if (number == target) {
|
||||
return true;
|
||||
@@ -178,9 +183,9 @@ public abstract class CompareUtils {
|
||||
DateFormatter dateFormatter = DateFormatter.getFormatter(stringValue);
|
||||
return (dateFormatter.toString(new Date(number.longValue())).equals(stringValue));
|
||||
}
|
||||
try{
|
||||
try {
|
||||
return new BigDecimal(stringValue).doubleValue() == number.doubleValue();
|
||||
}catch (NumberFormatException e){
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,15 @@ public class DiffTest {
|
||||
Map<String, Object> before = new HashMap<>();
|
||||
before.put("name", "name");
|
||||
before.put("age",21);
|
||||
before.put("bool", true);
|
||||
before.put("bool", false);
|
||||
before.put("birthday", DateFormatter.fromString("19910101"));
|
||||
|
||||
Map<String, Object> after = new HashMap<>();
|
||||
after.put("name", "name");
|
||||
after.put("age", "21");
|
||||
after.put("bool", "true");
|
||||
after.put("bool", "false");
|
||||
after.put("birthday", "1991-01-01");
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user