diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java index 0ac25d34f..2e6a79fe1 100644 --- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java +++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java @@ -604,12 +604,7 @@ public class CollectionUtils { } @SuppressWarnings({ "unchecked", "rawtypes" }) - final Transformer transformer = new Transformer() { - @Override - public EquatorWrapper transform(final Object input) { - return new EquatorWrapper(equator, input); - } - }; + final Transformer transformer = input -> new EquatorWrapper(equator, input); return isEqualCollection(collect(a, transformer), collect(b, transformer)); } @@ -1782,12 +1777,7 @@ public class CollectionUtils { final Iterable retain, final Equator equator) { - final Transformer> transformer = new Transformer>() { - @Override - public EquatorWrapper transform(final E input) { - return new EquatorWrapper<>(equator, input); - } - }; + final Transformer> transformer = input -> new EquatorWrapper<>(equator, input); final Set> retainSet = collect(retain, transformer, new HashSet>()); @@ -1860,12 +1850,7 @@ public class CollectionUtils { final Iterable remove, final Equator equator) { - final Transformer> transformer = new Transformer>() { - @Override - public EquatorWrapper transform(final E input) { - return new EquatorWrapper<>(equator, input); - } - }; + final Transformer> transformer = input -> new EquatorWrapper<>(equator, input); final Set> removeSet = collect(remove, transformer, new HashSet>()); diff --git a/src/main/java/org/apache/commons/collections4/SetUtils.java b/src/main/java/org/apache/commons/collections4/SetUtils.java index 61a3a429f..6d0bdc275 100644 --- a/src/main/java/org/apache/commons/collections4/SetUtils.java +++ b/src/main/java/org/apache/commons/collections4/SetUtils.java @@ -125,12 +125,7 @@ public class SetUtils { throw new NullPointerException("Sets must not be null."); } - final Predicate notContainedInB = new Predicate() { - @Override - public boolean evaluate(final E object) { - return !b.contains(object); - } - }; + final Predicate notContainedInB = object -> !b.contains(object); return new SetView() { @Override @@ -285,12 +280,7 @@ public class SetUtils { throw new NullPointerException("Sets must not be null."); } - final Predicate containedInB = new Predicate() { - @Override - public boolean evaluate(final E object) { - return b.contains(object); - } - }; + final Predicate containedInB = object -> b.contains(object); return new SetView() { @Override diff --git a/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java b/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java index bfdfdd47d..0b8c05cb9 100644 --- a/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java +++ b/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java @@ -438,23 +438,18 @@ public class MultiValueMap extends AbstractMapDecorator impleme return null; } final K key = keyIterator.next(); - final Transformer> transformer = new Transformer>() { + final Transformer> transformer = input -> new Entry() { @Override - public Entry transform(final V input) { - return new Entry() { - @Override - public K getKey() { - return key; - } - @Override - public V getValue() { - return input; - } - @Override - public V setValue(final V value) { - throw new UnsupportedOperationException(); - } - }; + public K getKey() { + return key; + } + @Override + public V getValue() { + return input; + } + @Override + public V setValue(final V value) { + throw new UnsupportedOperationException(); } }; return new TransformIterator<>(new ValuesIterator(key), transformer); diff --git a/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java b/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java index 201d11d36..2beda5ae6 100644 --- a/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java +++ b/src/main/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMap.java @@ -626,14 +626,7 @@ public abstract class AbstractMultiValuedMap implements MultiValuedMap> entryTransformer = new Transformer>() { - - @Override - public Entry transform(final V input) { - return new MultiValuedMapEntry(key, input); - } - - }; + final Transformer> entryTransformer = input -> new MultiValuedMapEntry(key, input); return new TransformIterator<>(new ValuesIterator(key), entryTransformer); } }; diff --git a/src/main/java/org/apache/commons/collections4/multiset/AbstractMultiSet.java b/src/main/java/org/apache/commons/collections4/multiset/AbstractMultiSet.java index 8a5f53223..1c4248c39 100644 --- a/src/main/java/org/apache/commons/collections4/multiset/AbstractMultiSet.java +++ b/src/main/java/org/apache/commons/collections4/multiset/AbstractMultiSet.java @@ -256,12 +256,7 @@ public abstract class AbstractMultiSet extends AbstractCollection implemen * @return the uniqueSet iterator */ protected Iterator createUniqueSetIterator() { - final Transformer, E> transformer = new Transformer, E>() { - @Override - public E transform(final Entry entry) { - return entry.getElement(); - } - }; + final Transformer, E> transformer = entry -> entry.getElement(); return IteratorUtils.transformedIterator(entrySet().iterator(), transformer); } diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index 0ea3ebf4d..2ef303047 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -476,12 +476,7 @@ public class CollectionUtilsTest extends MockTestCase { @Test public void testSubtractWithPredicate() { // greater than 3 - final Predicate predicate = new Predicate() { - @Override - public boolean evaluate(final Number n) { - return n.longValue() > 3L; - } - }; + final Predicate predicate = n -> n.longValue() > 3L; final Collection col = CollectionUtils.subtract(iterableA, collectionC, predicate); final Map freq2 = CollectionUtils.getCardinalityMap(col); @@ -733,22 +728,12 @@ public class CollectionUtilsTest extends MockTestCase { final Collection strings = Arrays.asList("a", "b", "c"); final StringBuffer result = new StringBuffer(); - result.append(CollectionUtils.forAllButLastDo(strings, new Closure() { - @Override - public void execute(final String input) { - result.append(input+";"); - } - })); + result.append(CollectionUtils.forAllButLastDo(strings, (Closure) input -> result.append(input+";"))); assertEquals("a;b;c", result.toString()); final Collection oneString = Arrays.asList("a"); final StringBuffer resultOne = new StringBuffer(); - resultOne.append(CollectionUtils.forAllButLastDo(oneString, new Closure() { - @Override - public void execute(final String input) { - resultOne.append(input+";"); - } - })); + resultOne.append(CollectionUtils.forAllButLastDo(oneString, (Closure) input -> resultOne.append(input+";"))); assertEquals("a", resultOne.toString()); assertNull(CollectionUtils.forAllButLastDo(strings, (Closure) null)); // do not remove cast assertNull(CollectionUtils.forAllButLastDo((Collection) null, (Closure) null)); // do not remove cast @@ -1108,12 +1093,7 @@ public class CollectionUtilsTest extends MockTestCase { } // ----------------------------------------------------------------------- - private static Predicate EQUALS_TWO = new Predicate() { - @Override - public boolean evaluate(final Number input) { - return input.intValue() == 2; - } - }; + private static Predicate EQUALS_TWO = input -> input.intValue() == 2; //Up to here @Test @@ -1296,12 +1276,7 @@ public class CollectionUtilsTest extends MockTestCase { assertTrue(collection.contains(2L) && !collection.contains(1)); } - Transformer TRANSFORM_TO_INTEGER = new Transformer() { - @Override - public Integer transform(final Object input) { - return Integer.valueOf(((Long)input).intValue()); - } - }; + Transformer TRANSFORM_TO_INTEGER = input -> Integer.valueOf(((Long)input).intValue()); @Test public void transform1() { @@ -1333,12 +1308,7 @@ public class CollectionUtilsTest extends MockTestCase { set.add(1L); set.add(2L); set.add(3L); - CollectionUtils.transform(set, new Transformer() { - @Override - public Integer transform(final Object input) { - return 4; - } - }); + CollectionUtils.transform(set, input -> 4); assertEquals(1, set.size()); assertEquals(4, set.iterator().next()); } @@ -1831,20 +1801,10 @@ public class CollectionUtilsTest extends MockTestCase { assertFalse(CollectionUtils.matchesAll(null, null)); assertFalse(CollectionUtils.matchesAll(collectionA, null)); - final Predicate lessThanFive = new Predicate() { - @Override - public boolean evaluate(final Integer object) { - return object < 5; - } - }; + final Predicate lessThanFive = object -> object < 5; assertTrue(CollectionUtils.matchesAll(collectionA, lessThanFive)); - final Predicate lessThanFour = new Predicate() { - @Override - public boolean evaluate(final Integer object) { - return object < 4; - } - }; + final Predicate lessThanFour = object -> object < 4; assertFalse(CollectionUtils.matchesAll(collectionA, lessThanFour)); assertTrue(CollectionUtils.matchesAll(null, lessThanFour)); diff --git a/src/test/java/org/apache/commons/collections4/FluentIterableTest.java b/src/test/java/org/apache/commons/collections4/FluentIterableTest.java index aca8d7007..6c38914f5 100644 --- a/src/test/java/org/apache/commons/collections4/FluentIterableTest.java +++ b/src/test/java/org/apache/commons/collections4/FluentIterableTest.java @@ -103,12 +103,7 @@ public class FluentIterableTest { emptyIterable = Collections.emptyList(); } - private static Predicate EVEN = new Predicate() { - @Override - public boolean evaluate(final Number input) { - return input.intValue() % 2 == 0; - } - }; + private static Predicate EVEN = input -> input.intValue() % 2 == 0; // ----------------------------------------------------------------------- @Test @@ -198,12 +193,7 @@ public class FluentIterableTest { @Test public void filter() { - final Predicate smallerThan3 = new Predicate() { - @Override - public boolean evaluate(final Integer object) { - return object.intValue() < 3; - } - }; + final Predicate smallerThan3 = object -> object.intValue() < 3; List result = FluentIterable.of(iterableA).filter(smallerThan3).toList(); assertEquals(3, result.size()); assertEquals(Arrays.asList(1, 2, 2), result); @@ -223,12 +213,7 @@ public class FluentIterableTest { @Test public void forEach() { final AtomicInteger sum = new AtomicInteger(0); - final Closure closure = new Closure() { - @Override - public void execute(final Integer input) { - sum.addAndGet(input); - } - }; + final Closure closure = input -> sum.addAndGet(input); FluentIterable.of(iterableA).forEach(closure); int expectedSum = 0; @@ -315,12 +300,7 @@ public class FluentIterableTest { @Test public void transform() { - final Transformer squared = new Transformer() { - @Override - public Integer transform(final Integer object) { - return object * object; - } - }; + final Transformer squared = object -> object * object; List result = FluentIterable.of(iterableA).transform(squared).toList(); assertEquals(10, result.size()); assertEquals(Arrays.asList(1, 4, 4, 9, 9, 9, 16, 16, 16, 16), result); diff --git a/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java b/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java index 564193bf4..3cfb0e910 100644 --- a/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java @@ -91,19 +91,9 @@ public class IterableUtilsTest { emptyIterable = Collections.emptyList(); } - private static Predicate EQUALS_TWO = new Predicate() { - @Override - public boolean evaluate(final Number input) { - return input.intValue() == 2; - } - }; + private static Predicate EQUALS_TWO = input -> input.intValue() == 2; - private static Predicate EVEN = new Predicate() { - @Override - public boolean evaluate(final Number input) { - return input.intValue() % 2 == 0; - } - }; + private static Predicate EVEN = input -> input.intValue() % 2 == 0; // ----------------------------------------------------------------------- @Test @@ -373,20 +363,10 @@ public class IterableUtilsTest { // expected } - final Predicate lessThanFive = new Predicate() { - @Override - public boolean evaluate(final Integer object) { - return object < 5; - } - }; + final Predicate lessThanFive = object -> object < 5; assertTrue(IterableUtils.matchesAll(iterableA, lessThanFive)); - final Predicate lessThanFour = new Predicate() { - @Override - public boolean evaluate(final Integer object) { - return object < 4; - } - }; + final Predicate lessThanFour = object -> object < 4; assertFalse(IterableUtils.matchesAll(iterableA, lessThanFour)); assertTrue(IterableUtils.matchesAll(null, lessThanFour)); @@ -505,29 +485,18 @@ public class IterableUtilsTest { result = IterableUtils.toString(null); assertEquals("[]", result); - result = IterableUtils.toString(iterableA, new Transformer() { - @Override - public String transform(final Integer input) { - return new Integer(input * 2).toString(); - } - }); + result = IterableUtils.toString(iterableA, input -> new Integer(input * 2).toString()); assertEquals("[2, 4, 4, 6, 6, 6, 8, 8, 8, 8]", result); - result = IterableUtils.toString(new ArrayList(), new Transformer() { - @Override - public String transform(final Integer input) { - fail("not supposed to reach here"); - return ""; - } + result = IterableUtils.toString(new ArrayList(), input -> { + fail("not supposed to reach here"); + return ""; }); assertEquals("[]", result); - result = IterableUtils.toString(null, new Transformer() { - @Override - public String transform(final Integer input) { - fail("not supposed to reach here"); - return ""; - } + result = IterableUtils.toString(null, input -> { + fail("not supposed to reach here"); + return ""; }); assertEquals("[]", result); } @@ -535,12 +504,7 @@ public class IterableUtilsTest { @Test public void testToStringDelimiter() { - final Transformer transformer = new Transformer() { - @Override - public String transform(final Integer input) { - return new Integer(input * 2).toString(); - } - }; + final Transformer transformer = input -> new Integer(input * 2).toString(); String result = IterableUtils.toString(iterableA, transformer, "", "", ""); assertEquals("2446668888", result); @@ -572,12 +536,9 @@ public class IterableUtilsTest { @Test public void testToStringWithNullArguments() { - final String result = IterableUtils.toString(null, new Transformer() { - @Override - public String transform(final Integer input) { - fail("not supposed to reach here"); - return ""; - } + final String result = IterableUtils.toString(null, input -> { + fail("not supposed to reach here"); + return ""; }, "", "(", ")"); assertEquals("()", result); @@ -589,12 +550,9 @@ public class IterableUtilsTest { } try { - IterableUtils.toString(new ArrayList(), new Transformer() { - @Override - public String transform(final Integer input) { - fail("not supposed to reach here"); - return ""; - } + IterableUtils.toString(new ArrayList(), input -> { + fail("not supposed to reach here"); + return ""; }, null, "(", ")"); fail("expecting NullPointerException"); } catch (final NullPointerException ex) { @@ -602,12 +560,9 @@ public class IterableUtilsTest { } try { - IterableUtils.toString(new ArrayList(), new Transformer() { - @Override - public String transform(final Integer input) { - fail("not supposed to reach here"); - return ""; - } + IterableUtils.toString(new ArrayList(), input -> { + fail("not supposed to reach here"); + return ""; }, "", null, ")"); fail("expecting NullPointerException"); } catch (final NullPointerException ex) { @@ -615,12 +570,9 @@ public class IterableUtilsTest { } try { - IterableUtils.toString(new ArrayList(), new Transformer() { - @Override - public String transform(final Integer input) { - fail("not supposed to reach here"); - return ""; - } + IterableUtils.toString(new ArrayList(), input -> { + fail("not supposed to reach here"); + return ""; }, "", "(", null); fail("expecting NullPointerException"); } catch (final NullPointerException ex) { diff --git a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java index 9a3be4c7b..c8ec12d58 100644 --- a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java @@ -122,12 +122,7 @@ public class ListUtilsTest { @Test public void testPredicatedList() { - final Predicate predicate = new Predicate() { - @Override - public boolean evaluate(final Object o) { - return o instanceof String; - } - }; + final Predicate predicate = o -> o instanceof String; final List list = ListUtils.predicatedList(new ArrayList<>(), predicate); assertTrue("returned object should be a PredicatedList", list instanceof PredicatedList); try { @@ -452,12 +447,7 @@ public class ListUtilsTest { assertEquals(strings, partitionMax.get(0)); } - private static Predicate EQUALS_TWO = new Predicate() { - @Override - public boolean evaluate(final Number input) { - return input.intValue() == 2; - } - }; + private static Predicate EQUALS_TWO = input -> input.intValue() == 2; @Test @SuppressWarnings("boxing") // OK in test code diff --git a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java index 6c72d78ff..0b670da53 100644 --- a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java @@ -65,12 +65,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest { } public Predicate getPredicate() { - return new Predicate() { - @Override - public boolean evaluate(final Object o) { - return o instanceof String; - } - }; + return o -> o instanceof String; } @Test @@ -122,14 +117,11 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest { @Test public void testLazyMapTransformer() { - final Map map = MapUtils.lazyMap(new HashMap<>(), new Transformer() { - @Override - public Object transform(final Object mapKey) { - if (mapKey instanceof String) { - return Integer.valueOf((String) mapKey); - } - return null; + final Map map = MapUtils.lazyMap(new HashMap<>(), (Transformer) mapKey -> { + if (mapKey instanceof String) { + return Integer.valueOf((String) mapKey); } + return null; }); assertEquals(0, map.size()); @@ -859,12 +851,7 @@ public class MapUtilsTest extends AbstractAvailableLocalesTest { // Now test key transform population final MultiValueMap map = MultiValueMap.multiValueMap(new TreeMap>()); - MapUtils.populateMap(map, list, new Transformer() { - @Override - public Integer transform(final X input) { - return input.key; - } - }, TransformerUtils. nopTransformer()); + MapUtils.populateMap(map, list, (Transformer) input -> input.key, TransformerUtils. nopTransformer()); assertEquals(list.size(), map.totalSize()); for (int i = 0; i < list.size(); i++) { diff --git a/src/test/java/org/apache/commons/collections4/MultiSetUtilsTest.java b/src/test/java/org/apache/commons/collections4/MultiSetUtilsTest.java index 24c1759fc..56be2fb42 100644 --- a/src/test/java/org/apache/commons/collections4/MultiSetUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/MultiSetUtilsTest.java @@ -92,12 +92,7 @@ public class MultiSetUtilsTest { */ @Test public void testPredicatedMultiSet() { - final Predicate predicate = new Predicate() { - @Override - public boolean evaluate(final String object) { - return object.length() == 1; - }; - }; + final Predicate predicate = object -> object.length() == 1; final MultiSet predicated = MultiSetUtils.predicatedMultiSet(multiSet, predicate); assertEquals(multiSet.size(), predicated.size()); assertEquals(multiSet.getCount("a"), predicated.getCount("a")); @@ -115,12 +110,7 @@ public class MultiSetUtilsTest { } try { - MultiSetUtils.predicatedMultiSet(multiSet, new Predicate() { - @Override - public boolean evaluate(final String object) { - return object.equals("a"); - }; - }); + MultiSetUtils.predicatedMultiSet(multiSet, object -> object.equals("a")); fail("Predicate is violated for all elements not being 'a'"); } catch (final IllegalArgumentException iae) { diff --git a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java index 70c43d6c6..c44b3ffe6 100644 --- a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java @@ -231,12 +231,7 @@ public class SetUtilsTest { @Test public void testpredicatedSet() { - final Predicate predicate = new Predicate() { - @Override - public boolean evaluate(final Object o) { - return o instanceof String; - } - }; + final Predicate predicate = o -> o instanceof String; final Set set = SetUtils.predicatedSet(new HashSet<>(), predicate); assertTrue("returned object should be a PredicatedSet", set instanceof PredicatedSet); try { diff --git a/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java b/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java index 37b98664e..6487a2943 100644 --- a/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/SplitMapUtilsTest.java @@ -41,12 +41,7 @@ public class SplitMapUtilsTest { private Map backingMap; private TransformedSplitMap transformedMap; - private final Transformer stringToInt = new Transformer() { - @Override - public Integer transform(final String input) { - return Integer.valueOf(input); - } - }; + private final Transformer stringToInt = input -> Integer.valueOf(input); @Before public void setUp() throws Exception { @@ -84,32 +79,17 @@ public class SplitMapUtilsTest { // check individual operations int sz = map.size(); - attemptPutOperation(new Runnable() { - @Override - public void run() { - map.clear(); - } - }); + attemptPutOperation(() -> map.clear()); assertEquals(sz, map.size()); - attemptPutOperation(new Runnable() { - @Override - public void run() { - map.put("foo", 100); - } - }); + attemptPutOperation(() -> map.put("foo", 100)); final HashMap m = new HashMap<>(); m.put("foo", 100); m.put("bar", 200); m.put("baz", 300); - attemptPutOperation(new Runnable() { - @Override - public void run() { - map.putAll(m); - } - }); + attemptPutOperation(() -> map.putAll(m)); // equals, hashcode final IterableMap other = SplitMapUtils.readableMap(transformedMap); @@ -135,60 +115,15 @@ public class SplitMapUtilsTest { @SuppressWarnings("unchecked") public void testWritableMap() { final Map map = SplitMapUtils.writableMap(transformedMap); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.get(null); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.entrySet(); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.keySet(); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.values(); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.size(); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.isEmpty(); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.containsKey(null); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.containsValue(null); - } - }); - attemptGetOperation(new Runnable() { - @Override - public void run() { - map.remove(null); - } - }); + attemptGetOperation(() -> map.get(null)); + attemptGetOperation(() -> map.entrySet()); + attemptGetOperation(() -> map.keySet()); + attemptGetOperation(() -> map.values()); + attemptGetOperation(() -> map.size()); + attemptGetOperation(() -> map.isEmpty()); + attemptGetOperation(() -> map.containsKey(null)); + attemptGetOperation(() -> map.containsValue(null)); + attemptGetOperation(() -> map.remove(null)); // equals, hashcode final Map other = SplitMapUtils.writableMap(transformedMap); diff --git a/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java b/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java index b31db3970..b47d10f0e 100644 --- a/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java @@ -247,12 +247,7 @@ public class TransformerUtilsTest { assertEquals("A", TransformerUtils.ifTransformer(TruePredicate.truePredicate(), a, b).transform(null)); assertEquals("B", TransformerUtils.ifTransformer(FalsePredicate.falsePredicate(), a, b).transform(null)); - final Predicate lessThanFivePredicate = new Predicate() { - @Override - public boolean evaluate(final Integer value) { - return value < 5; - } - }; + final Predicate lessThanFivePredicate = value -> value < 5; // if/else tests assertEquals("A", TransformerUtils.ifTransformer(lessThanFivePredicate, a, b).transform(1)); assertEquals("B", TransformerUtils.ifTransformer(lessThanFivePredicate, a, b).transform(5)); diff --git a/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java b/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java index d99adfdfe..1ee345689 100644 --- a/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java @@ -44,12 +44,7 @@ public class PredicatedBagTest extends AbstractBagTest { //-------------------------------------------------------------------------- protected Predicate stringPredicate() { - return new Predicate() { - @Override - public boolean evaluate(final T o) { - return o instanceof String; - } - }; + return o -> o instanceof String; } protected Predicate truePredicate = TruePredicate.truePredicate(); diff --git a/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java b/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java index 87312d3cb..498918908 100644 --- a/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java @@ -46,12 +46,7 @@ public class PredicatedSortedBagTest extends AbstractSortedBagTest { //-------------------------------------------------------------------------- protected Predicate stringPredicate() { - return new Predicate() { - @Override - public boolean evaluate(final T o) { - return o instanceof String; - } - }; + return o -> o instanceof String; } protected Predicate truePredicate = TruePredicate.truePredicate(); diff --git a/src/test/java/org/apache/commons/collections4/bag/TreeBagTest.java b/src/test/java/org/apache/commons/collections4/bag/TreeBagTest.java index 380eecc40..4d56fc462 100644 --- a/src/test/java/org/apache/commons/collections4/bag/TreeBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/TreeBagTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.collections4.bag; -import java.util.Comparator; - import junit.framework.Test; import org.apache.commons.collections4.Bag; @@ -75,12 +73,7 @@ public class TreeBagTest extends AbstractSortedBagTest { // expected; } - final Bag bag2 = new TreeBag<>(new Comparator() { - @Override - public int compare(final String o1, final String o2) { - return o1.compareTo(o2); - } - }); + final Bag bag2 = new TreeBag<>((o1, o2) -> o1.compareTo(o2)); try { // jdk bug: adding null to an empty TreeMap works // thus ensure that the bag is not empty before adding null diff --git a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java index 4635eb1e8..65dd4bcb7 100644 --- a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java @@ -76,12 +76,7 @@ public class PredicatedCollectionTest extends AbstractCollectionTest { //----------------------------------------------------------------------- protected Predicate testPredicate = - new Predicate() { - @Override - public boolean evaluate(final E o) { - return o instanceof String; - } - }; + o -> o instanceof String; public Collection makeTestCollection() { return decorateCollection(new ArrayList(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java b/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java index d9edbae39..1417cafc2 100644 --- a/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java +++ b/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java @@ -103,18 +103,15 @@ public class ComparatorChainTest extends AbstractComparatorTest chain = new ComparatorChain<>(); - chain.addComparator(new Comparator() { - @Override - public int compare(final Integer a, final Integer b) { - final int result = a.compareTo(b); - if (result < 0) { - return Integer.MIN_VALUE; - } - if (result > 0) { - return Integer.MAX_VALUE; - } - return 0; + chain.addComparator((a, b) -> { + final int result = a.compareTo(b); + if (result < 0) { + return Integer.MIN_VALUE; } + if (result > 0) { + return Integer.MAX_VALUE; + } + return 0; }, true); assertTrue(chain.compare(Integer.valueOf(4), Integer.valueOf(5)) > 0); diff --git a/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java index bc2c755c4..82dd8345f 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java @@ -157,16 +157,13 @@ public class FilterIteratorTest extends AbstractIteratorTest { } private void verifyElementsInPredicate(final String[] elements) { - final Predicate pred = new Predicate() { - @Override - public boolean evaluate(final E x) { - for (final String element : elements) { - if (element.equals(x)) { - return true; - } + final Predicate pred = x -> { + for (final String element : elements) { + if (element.equals(x)) { + return true; } - return false; } + return false; }; initIterator(); iterator.setPredicate(pred); @@ -199,10 +196,7 @@ public class FilterIteratorTest extends AbstractIteratorTest { * @return "filtered" iterator */ protected FilterIterator makePassThroughFilter(final Iterator i) { - final Predicate pred = new Predicate() { - @Override - public boolean evaluate(final E x) { return true; } - }; + final Predicate pred = x -> true; return new FilterIterator<>(i, pred); } @@ -214,10 +208,7 @@ public class FilterIteratorTest extends AbstractIteratorTest { * @return "filtered" iterator */ protected FilterIterator makeBlockAllFilter(final Iterator i) { - final Predicate pred = new Predicate() { - @Override - public boolean evaluate(final E x) { return false; } - }; + final Predicate pred = x -> false; return new FilterIterator<>(i, pred); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java index 03b7cb3d5..817a06f84 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java @@ -70,47 +70,17 @@ public class FilterListIteratorTest { if (i % 6 == 0) { sixes.add(Integer.valueOf(i)); } } - truePred = new Predicate() { - @Override - public boolean evaluate(final Integer x) { - return true; - } - }; + truePred = x -> true; - falsePred = new Predicate() { - @Override - public boolean evaluate(final Integer x) { - return true; - } - }; + falsePred = x -> true; - evenPred = new Predicate() { - @Override - public boolean evaluate(final Integer x) { - return x % 2 == 0; - } - }; + evenPred = x -> x % 2 == 0; - oddPred = new Predicate() { - @Override - public boolean evaluate(final Integer x) { - return x % 2 != 0; //works for all numbers, not just >= 0 as is the case for "x % 2 == 1" - } - }; + oddPred = x -> x % 2 != 0; - threePred = new Predicate() { - @Override - public boolean evaluate(final Integer x) { - return x % 3 == 0; - } - }; + threePred = x -> x % 3 == 0; - fourPred = new Predicate() { - @Override - public boolean evaluate(final Integer x) { - return x % 4 == 0; - } - }; + fourPred = x -> x % 4 == 0; } diff --git a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java index 1fd563933..6786b18e0 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java @@ -91,12 +91,7 @@ public class IteratorChainTest extends AbstractIteratorTest { public void testRemoveFromFilteredIterator() { - final Predicate myPredicate = new Predicate() { - @Override - public boolean evaluate(final Integer i) { - return i.compareTo(Integer.valueOf(4)) < 0; - } - }; + final Predicate myPredicate = i -> i.compareTo(Integer.valueOf(4)) < 0; final List list1 = new ArrayList<>(); final List list2 = new ArrayList<>(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java b/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java index a8e4c066e..182611880 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java @@ -105,12 +105,7 @@ public class LazyIteratorChainTest extends AbstractIteratorTest { public void testRemoveFromFilteredIterator() { - final Predicate myPredicate = new Predicate() { - @Override - public boolean evaluate(final Integer i) { - return i.compareTo(Integer.valueOf(4)) < 0; - } - }; + final Predicate myPredicate = i -> i.compareTo(Integer.valueOf(4)) < 0; final List list1 = new ArrayList<>(); final List list2 = new ArrayList<>(); diff --git a/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java b/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java index 1e831ba47..8ef6a413e 100644 --- a/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java @@ -56,12 +56,7 @@ public class PredicatedListTest extends AbstractListTest { //-------------------------------------------------------------------- protected Predicate testPredicate = - new Predicate() { - @Override - public boolean evaluate(final E o) { - return o instanceof String; - } - }; + o -> o instanceof String; public List makeTestList() { return decorateList(new ArrayList(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java b/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java index a6953d353..eeb2d92da 100644 --- a/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java @@ -104,14 +104,11 @@ public class DefaultedMapTest extends AbstractIterableMapTest { @SuppressWarnings("unchecked") public void testMapGet4() { final HashMap base = new HashMap<>(); - final Map map = DefaultedMap.defaultedMap(base, new Transformer() { - @Override - public V transform(final K input) { - if (input instanceof String) { - return (V) "NULL"; - } - return (V) "NULL_OBJECT"; + final Map map = DefaultedMap.defaultedMap(base, (Transformer) input -> { + if (input instanceof String) { + return (V) "NULL"; } + return (V) "NULL_OBJECT"; }); assertEquals(0, map.size()); diff --git a/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java b/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java index c86698ed5..ff4976221 100644 --- a/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java @@ -72,12 +72,7 @@ public class LazyMapTest extends AbstractIterableMapTest { @Test public void mapGetWithTransformer() { - final Transformer intConverter = new Transformer(){ - @Override - public Integer transform(final Number input) { - return input.intValue(); - } - }; + final Transformer intConverter = input -> input.intValue(); final Map map = lazyMap(new HashMap(), intConverter ); assertEquals(0, map.size()); final Number i1 = map.get(123L); diff --git a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java index 1bd66b671..b9f52b299 100644 --- a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java @@ -34,12 +34,7 @@ public class PredicatedMapTest extends AbstractIterableMapTest { protected static final Predicate truePredicate = TruePredicate.truePredicate(); - protected static final Predicate testPredicate = new Predicate() { - @Override - public boolean evaluate(final Object o) { - return o instanceof String; - } - }; + protected static final Predicate testPredicate = o -> o instanceof String; public PredicatedMapTest(final String testName) { super(testName); diff --git a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java index b2f6ef2ba..275813148 100644 --- a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java @@ -36,12 +36,7 @@ public class PredicatedSortedMapTest extends AbstractSortedMapTest { protected static final Predicate truePredicate = TruePredicate.truePredicate(); - protected static final Predicate testPredicate = new Predicate() { - @Override - public boolean evaluate(final Object o) { - return o instanceof String; - } - }; + protected static final Predicate testPredicate = o -> o instanceof String; public PredicatedSortedMapTest(final String testName) { super(testName); diff --git a/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java b/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java index fa36ad5c8..1de9be5b2 100644 --- a/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java +++ b/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java @@ -44,12 +44,7 @@ public class PredicatedMultiSetTest extends AbstractMultiSetTest { //-------------------------------------------------------------------------- protected Predicate stringPredicate() { - return new Predicate() { - @Override - public boolean evaluate(final T o) { - return o instanceof String; - } - }; + return o -> o instanceof String; } protected Predicate truePredicate = TruePredicate.truePredicate(); diff --git a/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java index 4e90b7600..a78c0d8a8 100644 --- a/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java @@ -73,12 +73,7 @@ public class PredicatedQueueTest extends AbstractQueueTest { //------------------------------------------------------------ protected Predicate testPredicate = - new Predicate() { - @Override - public boolean evaluate(final E o) { - return o instanceof String; - } - }; + o -> o instanceof String; public Queue makeTestQueue() { return decorateCollection(new LinkedList(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java b/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java index 57333f483..74c6160dd 100644 --- a/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java @@ -62,12 +62,7 @@ public class PredicatedNavigableSetTest extends AbstractNavigableSetTest { //-------------------------------------------------------------------- protected Predicate testPredicate = - new Predicate() { - @Override - public boolean evaluate(final E o) { - return o instanceof String && ((String) o).startsWith("A"); - } - }; + o -> o instanceof String && ((String) o).startsWith("A"); protected PredicatedNavigableSet makeTestSet() { return PredicatedNavigableSet.predicatedNavigableSet(new TreeSet(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java b/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java index 834fc3802..5cc654409 100644 --- a/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java @@ -56,12 +56,7 @@ public class PredicatedSetTest extends AbstractSetTest { //-------------------------------------------------------------------- protected Predicate testPredicate = - new Predicate() { - @Override - public boolean evaluate(final E o) { - return o instanceof String; - } - }; + o -> o instanceof String; protected PredicatedSet makeTestSet() { return decorateSet(new HashSet(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java b/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java index 7d3022e36..ee49031b0 100644 --- a/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java @@ -62,12 +62,7 @@ public class PredicatedSortedSetTest extends AbstractSortedSetTest { //-------------------------------------------------------------------- protected Predicate testPredicate = - new Predicate() { - @Override - public boolean evaluate(final E o) { - return o instanceof String && ((String) o).startsWith("A"); - } - }; + o -> o instanceof String && ((String) o).startsWith("A"); protected PredicatedSortedSet makeTestSet() { return PredicatedSortedSet.predicatedSortedSet(new TreeSet(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java b/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java index 22504cd8c..a1a255691 100644 --- a/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java +++ b/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java @@ -35,26 +35,11 @@ import org.apache.commons.collections4.functors.NOPTransformer; @SuppressWarnings("boxing") public class TransformedSplitMapTest extends BulkTest { - private final Transformer intToString = new Transformer() { - @Override - public String transform(final Integer input) { - return String.valueOf(input); - } - }; + private final Transformer intToString = input -> String.valueOf(input); - private final Transformer> objectToClass = new Transformer>() { - @Override - public java.lang.Class transform(final Object input) { - return input == null ? null : input.getClass(); - } - }; + private final Transformer> objectToClass = input -> input == null ? null : input.getClass(); - private final Transformer stringToInt = new Transformer() { - @Override - public Integer transform(final String input) { - return Integer.valueOf(input); - } - }; + private final Transformer stringToInt = input -> Integer.valueOf(input); public TransformedSplitMapTest(final String testName) { super(testName);