Simplify lambdas.

This commit is contained in:
Gary Gregory 2020-03-29 16:09:33 -04:00
parent 45ea11ad15
commit 991e24da58
6 changed files with 24 additions and 24 deletions

View File

@ -256,7 +256,7 @@ public abstract class AbstractMultiSet<E> extends AbstractCollection<E> implemen
* @return the uniqueSet iterator
*/
protected Iterator<E> createUniqueSetIterator() {
final Transformer<Entry<E>, E> transformer = entry -> entry.getElement();
final Transformer<Entry<E>, E> transformer = Entry::getElement;
return IteratorUtils.transformedIterator(entrySet().iterator(), transformer);
}

View File

@ -939,7 +939,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
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)->{
assertEquals(5.0, MapUtils.getDoubleValue(in, "noKey", key -> {
//sometimes the default value need to be calculated,such as System.currentTimeMillis()
return 5.0D;
}), 0);
@ -947,7 +947,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
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)->{
assertEquals(1.0, MapUtils.getDouble(in, "noKey", key -> {
return 1.0;
}), 0);
@ -967,13 +967,13 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
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) -> {
assertEquals(1.0, MapUtils.getFloatValue(in, "noKey", key -> {
return 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) -> {
assertEquals(1.0, MapUtils.getFloat(in, "noKey", key -> {
return 1.0F;
}), 0);
@ -992,13 +992,13 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals(2.0, MapUtils.getLongValue(in, "key", 0L), 0);
assertEquals(2.0, MapUtils.getLongValue(in, "key"), 0);
assertEquals(1, MapUtils.getLongValue(in, "noKey", 1L), 0);
assertEquals(1, MapUtils.getLongValue(in, "noKey", (key) -> {
assertEquals(1, MapUtils.getLongValue(in, "noKey", key -> {
return 1L;
}), 0);
assertEquals(0, MapUtils.getLongValue(in, "noKey"), 0);
assertEquals(2.0, MapUtils.getLong(in, "key", 0L), 0);
assertEquals(1, MapUtils.getLong(in, "noKey", 1L), 0);
assertEquals(1, MapUtils.getLong(in, "noKey", (key) -> {
assertEquals(1, MapUtils.getLong(in, "noKey", key -> {
return 1L;
}), 0);
@ -1018,13 +1018,13 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
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)->{
assertEquals(0, MapUtils.getIntValue(in, "noKey", key -> {
return 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)->{
assertEquals(0, MapUtils.getInteger(in, "noKey", key -> {
return 0;
}), 0);
@ -1043,13 +1043,13 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
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)->{
assertEquals(val, MapUtils.getShortValue(in, "noKey", key -> {
return 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)->{
assertEquals(val, MapUtils.getShort(in, "noKey", key -> {
return val;
}), 0);
@ -1068,13 +1068,13 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
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) -> {
assertEquals(val, MapUtils.getByteValue(in, "noKey", key -> {
return (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)->{
assertEquals(val, MapUtils.getByte(in, "noKey", key -> {
return val;
}), 0);
@ -1093,7 +1093,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals(val.intValue(), MapUtils.getNumber(in, "key", val).intValue(), 0);
assertEquals(val.intValue(), MapUtils.getNumber(in, "noKey", val).intValue(), 0);
assertEquals(val.intValue(), MapUtils.getNumber(in, "noKey", (key) -> {
assertEquals(val.intValue(), MapUtils.getNumber(in, "noKey", key -> {
if (true) {
return val;
} else {
@ -1112,7 +1112,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertEquals("str", MapUtils.getString(in, "key"));
assertEquals(null, MapUtils.getString(null, "key"));
assertEquals("default", MapUtils.getString(in, "noKey", "default"));
assertEquals("default", MapUtils.getString(in, "noKey", (key)->{
assertEquals("default", MapUtils.getString(in, "noKey", key -> {
if ("noKey".equals(key)) {
return "default";
} else {
@ -1149,22 +1149,22 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest {
assertTrue(MapUtils.getBooleanValue(in, "key", true));
assertTrue(MapUtils.getBooleanValue(in, "key"));
assertTrue(MapUtils.getBooleanValue(in, "noKey", true));
assertTrue(MapUtils.getBooleanValue(in, "noKey", (key) -> {
assertTrue(MapUtils.getBooleanValue(in, "noKey", key -> {
return true;
}));
assertTrue(!MapUtils.getBooleanValue(in, "noKey"));
assertTrue(MapUtils.getBoolean(in, "key", true));
assertTrue(MapUtils.getBoolean(in, "noKey", true));
assertTrue(MapUtils.getBoolean(in, "noKey", (key)->{
assertTrue(MapUtils.getBoolean(in, "noKey", key -> {
if (System.currentTimeMillis() > 0) {
return true;
}
return false;
}));
assertNull(MapUtils.getBoolean(in, "noKey", (key) -> {
assertNull(MapUtils.getBoolean(in, "noKey", key -> {
return null;
}));
assertFalse(MapUtils.getBooleanValue(in, "noKey", (key) -> {
assertFalse(MapUtils.getBooleanValue(in, "noKey", key -> {
return null;
}));
assertEquals(null, MapUtils.getBoolean(null, "noKey"));

View File

@ -41,7 +41,7 @@ public class SplitMapUtilsTest {
private Map<String, Integer> backingMap;
private TransformedSplitMap<String, String, String, Integer> transformedMap;
private final Transformer<String, Integer> stringToInt = input -> Integer.valueOf(input);
private final Transformer<String, Integer> stringToInt = Integer::valueOf;
@Before
public void setUp() throws Exception {

View File

@ -73,7 +73,7 @@ public class TreeBagTest<T> extends AbstractSortedBagTest<T> {
// expected;
}
final Bag<String> bag2 = new TreeBag<>((o1, o2) -> o1.compareTo(o2));
final Bag<String> bag2 = new TreeBag<>(String::compareTo);
try {
// jdk bug: adding null to an empty TreeMap works
// thus ensure that the bag is not empty before adding null

View File

@ -72,7 +72,7 @@ public class LazyMapTest<K, V> extends AbstractIterableMapTest<K, V> {
@Test
public void mapGetWithTransformer() {
final Transformer<Number, Integer> intConverter = input -> input.intValue();
final Transformer<Number, Integer> intConverter = Number::intValue;
final Map<Long, Number> map = lazyMap(new HashMap<Long, Number>(), intConverter);
assertEquals(0, map.size());
final Number i1 = map.get(123L);

View File

@ -35,11 +35,11 @@ import org.apache.commons.collections4.functors.NOPTransformer;
@SuppressWarnings("boxing")
public class TransformedSplitMapTest extends BulkTest {
private final Transformer<Integer, String> intToString = input -> String.valueOf(input);
private final Transformer<Integer, String> intToString = String::valueOf;
private final Transformer<Object, Class<?>> objectToClass = input -> input == null ? null : input.getClass();
private final Transformer<String, Integer> stringToInt = input -> Integer.valueOf(input);
private final Transformer<String, Integer> stringToInt = Integer::valueOf;
public TransformedSplitMapTest(final String testName) {
super(testName);