diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 5aaeb17ff..0c8d75b2b 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -7758,12 +7758,7 @@ public class ArrayUtils { * @since 3.4 */ public static > boolean isSorted(final T[] array) { - return isSorted(array, new Comparator() { - @Override - public int compare(final T o1, final T o2) { - return o1.compareTo(o2); - } - }); + return isSorted(array, (o1, o2) -> o1.compareTo(o2)); } diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index 452481070..bac78e7df 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -1376,82 +1376,73 @@ public class ClassUtils { * @since 3.2 */ public static Iterable> hierarchy(final Class type, final Interfaces interfacesBehavior) { - final Iterable> classes = new Iterable>() { + final Iterable> classes = () -> { + final MutableObject> next = new MutableObject<>(type); + return new Iterator>() { - @Override - public Iterator> iterator() { - final MutableObject> next = new MutableObject<>(type); - return new Iterator>() { + @Override + public boolean hasNext() { + return next.getValue() != null; + } - @Override - public boolean hasNext() { - return next.getValue() != null; - } + @Override + public Class next() { + final Class result = next.getValue(); + next.setValue(result.getSuperclass()); + return result; + } - @Override - public Class next() { - final Class result = next.getValue(); - next.setValue(result.getSuperclass()); - return result; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - }; - } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; }; if (interfacesBehavior != Interfaces.INCLUDE) { return classes; } - return new Iterable>() { + return () -> { + final Set> seenInterfaces = new HashSet<>(); + final Iterator> wrapped = classes.iterator(); - @Override - public Iterator> iterator() { - final Set> seenInterfaces = new HashSet<>(); - final Iterator> wrapped = classes.iterator(); + return new Iterator>() { + Iterator> interfaces = Collections.>emptySet().iterator(); - return new Iterator>() { - Iterator> interfaces = Collections.>emptySet().iterator(); + @Override + public boolean hasNext() { + return interfaces.hasNext() || wrapped.hasNext(); + } - @Override - public boolean hasNext() { - return interfaces.hasNext() || wrapped.hasNext(); + @Override + public Class next() { + if (interfaces.hasNext()) { + final Class nextInterface = interfaces.next(); + seenInterfaces.add(nextInterface); + return nextInterface; } + final Class nextSuperclass = wrapped.next(); + final Set> currentInterfaces = new LinkedHashSet<>(); + walkInterfaces(currentInterfaces, nextSuperclass); + interfaces = currentInterfaces.iterator(); + return nextSuperclass; + } - @Override - public Class next() { - if (interfaces.hasNext()) { - final Class nextInterface = interfaces.next(); - seenInterfaces.add(nextInterface); - return nextInterface; + private void walkInterfaces(final Set> addTo, final Class c) { + for (final Class iface : c.getInterfaces()) { + if (!seenInterfaces.contains(iface)) { + addTo.add(iface); } - final Class nextSuperclass = wrapped.next(); - final Set> currentInterfaces = new LinkedHashSet<>(); - walkInterfaces(currentInterfaces, nextSuperclass); - interfaces = currentInterfaces.iterator(); - return nextSuperclass; + walkInterfaces(addTo, iface); } + } - private void walkInterfaces(final Set> addTo, final Class c) { - for (final Class iface : c.getInterfaces()) { - if (!seenInterfaces.contains(iface)) { - addTo.add(iface); - } - walkInterfaces(addTo, iface); - } - } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - }; - } + }; }; } diff --git a/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java b/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java index cae064641..feb074b5c 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java @@ -115,13 +115,7 @@ public class Memoizer implements Computable { while (true) { Future future = cache.get(arg); if (future == null) { - final Callable eval = new Callable() { - - @Override - public O call() throws InterruptedException { - return computable.compute(arg); - } - }; + final Callable eval = () -> computable.compute(arg); final FutureTask futureTask = new FutureTask<>(eval); future = cache.putIfAbsent(arg, futureTask); if (future == null) { diff --git a/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java b/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java index 7fce712d1..6bea06940 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java @@ -417,12 +417,7 @@ public class TimedSemaphore { * @return a future object representing the task scheduled */ protected ScheduledFuture startTimer() { - return getExecutorService().scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - endOfPeriod(); - } - }, getPeriod(), getPeriod(), getUnit()); + return getExecutorService().scheduleAtFixedRate(() -> endOfPeriod(), getPeriod(), getPeriod(), getUnit()); } /** diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java index 640230370..2a6ccd00a 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java @@ -1715,12 +1715,7 @@ public class TypeUtils { * @since 3.2 */ public static Typed wrap(final Type type) { - return new Typed() { - @Override - public Type getType() { - return type; - } - }; + return () -> type; } /** diff --git a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java index 783acb8e3..f56d237d0 100644 --- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java +++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java @@ -94,12 +94,7 @@ public class FastDateParser implements DateParser, Serializable { // comparator used to sort regex alternatives // alternatives should be ordered longer first, and shorter last. ('february' before 'feb') // all entries must be lowercase by locale. - private static final Comparator LONGER_FIRST_LOWERCASE = new Comparator() { - @Override - public int compare(final String left, final String right) { - return right.compareTo(left); - } - }; + private static final Comparator LONGER_FIRST_LOWERCASE = (left, right) -> right.compareTo(left); /** *

Constructs a new FastDateParser.

diff --git a/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java b/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java index f4ed2a05e..a791daafb 100644 --- a/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java @@ -35,7 +35,6 @@ import java.lang.annotation.Target; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.time.Duration; import java.util.Collection; @@ -465,21 +464,17 @@ public class AnnotationUtilsTest { final Test real = getClass().getDeclaredMethod( "testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class); - final InvocationHandler generatedTestInvocationHandler = new InvocationHandler() { - - @Override - public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { - if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) { - return Boolean.valueOf(proxy == args[0]); - } - if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) { - return Integer.valueOf(System.identityHashCode(proxy)); - } - if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) { - return "Test proxy"; - } - return method.invoke(real, args); + final InvocationHandler generatedTestInvocationHandler = (proxy, method, args) -> { + if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) { + return Boolean.valueOf(proxy == args[0]); } + if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) { + return Integer.valueOf(System.identityHashCode(proxy)); + } + if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) { + return "Test proxy"; + } + return method.invoke(real, args); }; final Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread() diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java index 071e5d636..4b7c31d55 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java @@ -4394,12 +4394,7 @@ public class ArrayUtilsTest { @Test public void testIsSortedComparator() { - final Comparator c = new Comparator() { - @Override - public int compare(final Integer o1, final Integer o2) { - return o2.compareTo(o1); - } - }; + final Comparator c = (o1, o2) -> o2.compareTo(o1); Integer[] array = null; assertTrue(ArrayUtils.isSorted(array, c)); diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java index ffcf89298..74ebc802c 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderConcurrencyTest.java @@ -90,25 +90,19 @@ public class ReflectionToStringBuilderConcurrencyTest { // Create a thread pool with two threads to cause the most contention on the underlying resource. final ExecutorService threadPool = Executors.newFixedThreadPool(2); // Consumes toStrings - final Callable consumer = new Callable() { - @Override - public Integer call() { - for (int i = 0; i < REPEAT; i++) { - final String s = ReflectionToStringBuilder.toString(holder); - assertNotNull(s); - } - return Integer.valueOf(REPEAT); + final Callable consumer = () -> { + for (int i = 0; i < REPEAT; i++) { + final String s = ReflectionToStringBuilder.toString(holder); + assertNotNull(s); } + return Integer.valueOf(REPEAT); }; // Produces changes in the list - final Callable producer = new Callable() { - @Override - public Integer call() { - for (int i = 0; i < DATA_SIZE; i++) { - list.remove(list.get(0)); - } - return Integer.valueOf(REPEAT); + final Callable producer = () -> { + for (int i = 0; i < DATA_SIZE; i++) { + list.remove(list.get(0)); } + return Integer.valueOf(REPEAT); }; final Collection> tasks = new ArrayList<>(); tasks.add(consumer); diff --git a/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java b/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java index 83698702c..bed8b32c1 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ToStringStyleConcurrencyTest.java @@ -89,15 +89,12 @@ public class ToStringStyleConcurrencyTest { // Create a thread pool with two threads to cause the most contention on the underlying resource. final ExecutorService threadPool = Executors.newFixedThreadPool(2); // Consumes toStrings - final Callable consumer = new Callable() { - @Override - public Integer call() { - for (int i = 0; i < REPEAT; i++) { - // Calls ToStringStyle - new ToStringBuilder(holder).append(holder.collection); - } - return Integer.valueOf(REPEAT); + final Callable consumer = () -> { + for (int i = 0; i < REPEAT; i++) { + // Calls ToStringStyle + new ToStringBuilder(holder).append(holder.collection); } + return Integer.valueOf(REPEAT); }; final Collection> tasks = new ArrayList<>(); tasks.add(consumer); diff --git a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java index a62b3da9c..facff22da 100644 --- a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java +++ b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java @@ -136,11 +136,7 @@ public class EventListenerSupportTest { @Test public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException { final EventListenerSupport listenerSupport = EventListenerSupport.create(VetoableChangeListener.class); - listenerSupport.addListener(new VetoableChangeListener() { - - @Override - public void vetoableChange(final PropertyChangeEvent e) { - } + listenerSupport.addListener(e -> { }); listenerSupport.addListener(EasyMock.createNiceMock(VetoableChangeListener.class)); diff --git a/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java b/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java index 6fde95222..27797b2a5 100644 --- a/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/event/EventUtilsTest.java @@ -79,11 +79,8 @@ public class EventUtilsTest { public void testAddEventListenerThrowsException() { final ExceptionEventSource src = new ExceptionEventSource(); assertThrows(RuntimeException.class, () -> - EventUtils.addEventListener(src, PropertyChangeListener.class, new PropertyChangeListener() { - @Override - public void propertyChange(final PropertyChangeEvent e) { - // Do nothing! - } + EventUtils.addEventListener(src, PropertyChangeListener.class, e -> { + // Do nothing! }) ); } diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java index b0c8d02c1..843cb56bd 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java @@ -257,28 +257,25 @@ public class FastDateFormatTest { final AtomicLongArray totalElapsed= new AtomicLongArray(2); for (int i= 0; i { + for (int j= 0; j