Use lambdas.

This commit is contained in:
Gary Gregory 2020-10-25 15:27:56 -04:00
parent f51e6c61ed
commit 49701f3545
1 changed files with 13 additions and 40 deletions

View File

@ -1058,17 +1058,12 @@ public class MapUtilsTest {
assertEquals(2.0, MapUtils.getDoubleValue(in, "key", 0.0), 0);
assertEquals(2.0, MapUtils.getDoubleValue(in, "key"), 0);
assertEquals(1.0, MapUtils.getDoubleValue(in, "noKey", 1.0), 0);
assertEquals(5.0, MapUtils.getDoubleValue(in, "noKey", key -> {
//sometimes the default value need to be calculated,such as System.currentTimeMillis()
return 5.0D;
}), 0);
assertEquals(5.0, MapUtils.getDoubleValue(in, "noKey", key -> 5.0D), 0);
assertEquals(0, MapUtils.getDoubleValue(in, "noKey"), 0);
assertEquals(2.0, MapUtils.getDouble(in, "key", 0.0), 0);
assertEquals(1.0, MapUtils.getDouble(in, "noKey", 1.0), 0);
assertEquals(1.0, MapUtils.getDouble(in, "noKey", key -> {
return 1.0;
}), 0);
assertEquals(1.0, MapUtils.getDouble(in, "noKey", key -> 1.0), 0);
final Map<String, String> inStr = new HashMap<>();
@ -1086,15 +1081,11 @@ public class MapUtilsTest {
assertEquals(2.0, MapUtils.getFloatValue(in, "key", 0.0f), 0);
assertEquals(2.0, MapUtils.getFloatValue(in, "key"), 0);
assertEquals(1.0, MapUtils.getFloatValue(in, "noKey", 1.0f), 0);
assertEquals(1.0, MapUtils.getFloatValue(in, "noKey", key -> {
return 1.0F;
}), 0);
assertEquals(1.0, MapUtils.getFloatValue(in, "noKey", key -> 1.0F), 0);
assertEquals(0, MapUtils.getFloatValue(in, "noKey"), 0);
assertEquals(2.0, MapUtils.getFloat(in, "key", 0.0f), 0);
assertEquals(1.0, MapUtils.getFloat(in, "noKey", 1.0f), 0);
assertEquals(1.0, MapUtils.getFloat(in, "noKey", key -> {
return 1.0F;
}), 0);
assertEquals(1.0, MapUtils.getFloat(in, "noKey", key -> 1.0F), 0);
final Map<String, String> inStr = new HashMap<>();
final char decimalSeparator = getDecimalSeparator();
@ -1138,15 +1129,11 @@ public class MapUtilsTest {
assertEquals(2, MapUtils.getIntValue(in, "key", 0), 0);
assertEquals(2, MapUtils.getIntValue(in, "key"), 0);
assertEquals(0, MapUtils.getIntValue(in, "noKey", 0), 0);
assertEquals(0, MapUtils.getIntValue(in, "noKey", key -> {
return 0;
}), 0);
assertEquals(0, MapUtils.getIntValue(in, "noKey", key -> 0), 0);
assertEquals(0, MapUtils.getIntValue(in, "noKey"), 0);
assertEquals(2, MapUtils.getInteger(in, "key", 0), 0);
assertEquals(0, MapUtils.getInteger(in, "noKey", 0), 0);
assertEquals(0, MapUtils.getInteger(in, "noKey", key -> {
return 0;
}), 0);
assertEquals(0, MapUtils.getInteger(in, "noKey", key -> 0), 0);
final Map<String, String> inStr = new HashMap<>();
inStr.put("str1", "2");
@ -1163,15 +1150,11 @@ public class MapUtilsTest {
assertEquals(val, MapUtils.getShortValue(in, "key", val), 0);
assertEquals(val, MapUtils.getShortValue(in, "key"), 0);
assertEquals(val, MapUtils.getShortValue(in, "noKey", val), 0);
assertEquals(val, MapUtils.getShortValue(in, "noKey", key -> {
return val;
}), 0);
assertEquals(val, MapUtils.getShortValue(in, "noKey", key -> val), 0);
assertEquals(0, MapUtils.getShortValue(in, "noKey"), 0);
assertEquals(val, MapUtils.getShort(in, "key", val), 0);
assertEquals(val, MapUtils.getShort(in, "noKey", val), 0);
assertEquals(val, MapUtils.getShort(in, "noKey", key -> {
return val;
}), 0);
assertEquals(val, MapUtils.getShort(in, "noKey", key -> val), 0);
final Map<String, String> inStr = new HashMap<>();
inStr.put("str1", "10");
@ -1188,15 +1171,11 @@ public class MapUtilsTest {
assertEquals(val, MapUtils.getByteValue(in, "key", val), 0);
assertEquals(val, MapUtils.getByteValue(in, "key"), 0);
assertEquals(val, MapUtils.getByteValue(in, "noKey", val), 0);
assertEquals(val, MapUtils.getByteValue(in, "noKey", key -> {
return (byte) 100;
}), 0);
assertEquals(val, MapUtils.getByteValue(in, "noKey", key -> ((byte) 100)), 0);
assertEquals(0, MapUtils.getByteValue(in, "noKey"), 0);
assertEquals(val, MapUtils.getByte(in, "key", val), 0);
assertEquals(val, MapUtils.getByte(in, "noKey", val), 0);
assertEquals(val, MapUtils.getByte(in, "noKey", key -> {
return val;
}), 0);
assertEquals(val, MapUtils.getByte(in, "noKey", key -> val), 0);
final Map<String, String> inStr = new HashMap<>();
@ -1268,9 +1247,7 @@ public class MapUtilsTest {
assertTrue(MapUtils.getBooleanValue(in, "key", true));
assertTrue(MapUtils.getBooleanValue(in, "key"));
assertTrue(MapUtils.getBooleanValue(in, "noKey", true));
assertTrue(MapUtils.getBooleanValue(in, "noKey", key -> {
return true;
}));
assertTrue(MapUtils.getBooleanValue(in, "noKey", key -> true));
assertFalse(MapUtils.getBooleanValue(in, "noKey"));
assertTrue(MapUtils.getBoolean(in, "key", true));
assertTrue(MapUtils.getBoolean(in, "noKey", true));
@ -1280,12 +1257,8 @@ public class MapUtilsTest {
}
return false;
}));
assertNull(MapUtils.getBoolean(in, "noKey", key -> {
return null;
}));
assertFalse(MapUtils.getBooleanValue(in, "noKey", key -> {
return null;
}));
assertNull(MapUtils.getBoolean(in, "noKey", key -> null));
assertFalse(MapUtils.getBooleanValue(in, "noKey", key -> null));
assertNull(MapUtils.getBoolean(null, "noKey"));
// Values are Numbers
assertFalse(MapUtils.getBoolean(in, "keyNumberFalse"));