sal-binding-broker: use lambdas 78/57178/2
authorStephen Kitt <skitt@redhat.com>
Tue, 16 May 2017 15:50:43 +0000 (17:50 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 17 May 2017 08:53:48 +0000 (08:53 +0000)
This series of patches uses lambdas instead of anonymous classes for
functional interfaces when possible. Lambdas are replaced with method
references when appropriate.

Change-Id: I17f1fd2a8964cec80d35888f437ea098caa9430a
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/ListenerMapGeneration.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMDataBrokerAdapter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationPublishServiceAdapter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMRpcServiceAdapter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/RpcServiceAdapter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/SingletonHolder.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/BindingNormalizedCodecTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/ConstantSchemaAbstractDataBrokerTest.java

index f597838..7ca35aa 100644 (file)
@@ -12,15 +12,14 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 
+import java.util.stream.Collectors;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
-import com.google.common.base.Predicate;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
 import com.google.common.collect.Multimap;
 
 /**
@@ -93,14 +92,8 @@ final class ListenerMapGeneration {
 
     private static Iterable<Class<?>> getNotificationTypes(final Class<?> cls) {
         final Class<?>[] ifaces = cls.getInterfaces();
-        return Iterables.filter(Arrays.asList(ifaces), new Predicate<Class<?>>() {
-            @Override
-            public boolean apply(final Class<?> input) {
-                if (Notification.class.equals(input)) {
-                    return false;
-                }
-                return Notification.class.isAssignableFrom(input);
-            }
-        });
+        return Arrays.stream(ifaces)
+                .filter(input -> !Notification.class.equals(input) && Notification.class.isAssignableFrom(input))
+                .collect(Collectors.toList());
     }
 }
\ No newline at end of file
index 6845dd4..c78db4b 100644 (file)
@@ -40,7 +40,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 public class BindingDOMDataBrokerAdapter extends AbstractForwardedDataBroker implements DataBroker, DataTreeChangeService {
 
 
-    static final Factory<DataBroker> BUILDER_FACTORY = () -> new Builder();
+    static final Factory<DataBroker> BUILDER_FACTORY = Builder::new;
     private final DataTreeChangeService treeChangeService;
 
     public BindingDOMDataBrokerAdapter(final DOMDataBroker domDataBroker, final BindingToNormalizedNodeCodec codec) {
index 83fa196..6f7e9e2 100644 (file)
@@ -21,14 +21,7 @@ import org.opendaylight.yangtools.yang.binding.Notification;
 
 public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
 
-    static final Factory<NotificationPublishService> BUILDER_FACTORY = new BindingDOMAdapterBuilder.Factory<NotificationPublishService>() {
-
-        @Override
-        public BindingDOMAdapterBuilder<NotificationPublishService> newBuilder() {
-            return new Builder();
-        }
-
-    };
+    static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
 
     private final BindingToNormalizedNodeCodec codecRegistry;
     private final DOMNotificationPublishService domPublishService;
index 793ffed..78a22f8 100644 (file)
@@ -21,14 +21,7 @@ import org.opendaylight.yangtools.yang.binding.NotificationListener;
 
 public class BindingDOMNotificationServiceAdapter implements NotificationService, AutoCloseable {
 
-    public static final Factory<NotificationService> BUILDER_FACTORY = new Factory<NotificationService>() {
-
-        @Override
-        public BindingDOMAdapterBuilder<NotificationService> newBuilder() {
-            return new Builder();
-        }
-
-    };
+    public static final Factory<NotificationService> BUILDER_FACTORY = Builder::new;
     private final BindingNormalizedNodeSerializer codec;
     private final DOMNotificationService domNotifService;
 
index 8ebc5e6..26e696d 100644 (file)
@@ -23,14 +23,7 @@ import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 
 public class BindingDOMRpcServiceAdapter implements RpcConsumerRegistry {
 
-    protected static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = new Factory<RpcConsumerRegistry>() {
-
-        @Override
-        public BindingDOMAdapterBuilder<RpcConsumerRegistry> newBuilder() {
-            return new Builder();
-        }
-
-    };
+    protected static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = Builder::new;
 
     private final LoadingCache<Class<? extends RpcService>, RpcServiceAdapter> proxies = CacheBuilder.newBuilder()
             .weakKeys()
index 81aa461..c6ea9db 100644 (file)
@@ -131,19 +131,16 @@ class RpcServiceAdapter implements InvocationHandler {
 
     private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
             final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
-        return Futures.transform(domFuture, new Function<DOMRpcResult, RpcResult<?>>() {
-            @Override
-            public RpcResult<?> apply(final DOMRpcResult input) {
-                final NormalizedNode<?, ?> domData = input.getResult();
-                final DataObject bindingResult;
-                if (domData != null) {
-                    final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
-                    bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
-                } else {
-                    bindingResult = null;
-                }
-                return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
+        return Futures.transform(domFuture, (Function<DOMRpcResult, RpcResult<?>>) input -> {
+            final NormalizedNode<?, ?> domData = input.getResult();
+            final DataObject bindingResult;
+            if (domData != null) {
+                final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
+                bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
+            } else {
+                bindingResult = null;
             }
+            return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
         });
     }
 
index 2ca3530..bbe5036 100644 (file)
@@ -16,7 +16,6 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -89,17 +88,14 @@ public class SingletonHolder {
 
             final ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_NOTIFICATION_THREADS, MAX_NOTIFICATION_THREADS,
                     NOTIFICATION_THREAD_LIFE, TimeUnit.SECONDS, queue, factory,
-                    new RejectedExecutionHandler() {
-                // if the max threads are met, then it will raise a rejectedExecution. We then push to the queue.
-                @Override
-                public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) {
-                    try {
-                        executor.getQueue().put(r);
-                    } catch (final InterruptedException e) {
-                        throw new RejectedExecutionException("Interrupted while waiting on the queue", e);
-                    }
-                }
-            });
+                    // if the max threads are met, then it will raise a rejectedExecution. We then push to the queue.
+                    (r, executor1) -> {
+                        try {
+                            executor1.getQueue().put(r);
+                        } catch (final InterruptedException e) {
+                            throw new RejectedExecutionException("Interrupted while waiting on the queue", e);
+                        }
+                    });
 
             NOTIFICATION_EXECUTOR = MoreExecutors.listeningDecorator(executor);
         }
index b0b740f..567c176 100644 (file)
@@ -96,18 +96,15 @@ public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
         final CountDownLatch done = new CountDownLatch(1);
         final AtomicReference<YangInstanceIdentifier> yangId = new AtomicReference<>();
         final AtomicReference<RuntimeException> error = new AtomicReference<>();
-        new Thread() {
-            @Override
-            public void run() {
-                try {
-                    yangId.set(BindingNormalizedCodecTest.this.codec.toYangInstanceIdentifierBlocking(BA_TOP_LEVEL_LIST));
-                } catch(final RuntimeException e) {
-                    error.set(e);
-                } finally {
-                    done.countDown();
-                }
+        new Thread(() -> {
+            try {
+                yangId.set(BindingNormalizedCodecTest.this.codec.toYangInstanceIdentifierBlocking(BA_TOP_LEVEL_LIST));
+            } catch(final RuntimeException e) {
+                error.set(e);
+            } finally {
+                done.countDown();
             }
-        }.start();
+        }).start();
 
         Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
         this.codec.onGlobalContextUpdated(this.context);
@@ -136,18 +133,15 @@ public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
         final CountDownLatch done = new CountDownLatch(1);
         final AtomicReference<ImmutableBiMap<Method, SchemaPath>> retMap = new AtomicReference<>();
         final AtomicReference<RuntimeException> error = new AtomicReference<>();
-        new Thread() {
-            @Override
-            public void run() {
-                try {
-                    retMap.set(BindingNormalizedCodecTest.this.codec.getRpcMethodToSchemaPath(OpendaylightTestRpcServiceService.class));
-                } catch(final RuntimeException e) {
-                    error.set(e);
-                } finally {
-                    done.countDown();
-                }
+        new Thread(() -> {
+            try {
+                retMap.set(BindingNormalizedCodecTest.this.codec.getRpcMethodToSchemaPath(OpendaylightTestRpcServiceService.class));
+            } catch(final RuntimeException e) {
+                error.set(e);
+            } finally {
+                done.countDown();
             }
-        }.start();
+        }).start();
 
         Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
         this.codec.onGlobalContextUpdated(this.context);
index dd3020d..5c09a4f 100644 (file)
@@ -20,7 +20,7 @@ public class ConstantSchemaAbstractDataBrokerTest extends AbstractConcurrentData
 
     @Override
     protected SchemaContext getSchemaContext() throws Exception {
-        return SchemaContextSingleton.getSchemaContext(() -> super.getSchemaContext());
+        return SchemaContextSingleton.getSchemaContext(super::getSchemaContext);
     }
 
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.