Use builder fluently 18/97118/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 9 Aug 2021 21:46:53 +0000 (23:46 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 10 Aug 2021 08:04:38 +0000 (08:04 +0000)
DOMRpcRouter should use ImmutableList.Builder()'s methods as fluent
to maximize expressiveness.

Change-Id: I0e1663041a323cb65595675a029767a68cf2ba64
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 46752eea74eeeeee773f888a023f10d33bf750d1)

dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMRpcRouter.java

index 43d32dd74295fead7b7870cd22448dc9f99351d2..2a10b9aed5c8af0804bfc3eebd5300745dff8dae 100644 (file)
@@ -16,7 +16,6 @@ import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.MapDifference;
@@ -401,12 +400,12 @@ public final class DOMRpcRouter extends AbstractRegistration
         @Override
         public <T extends AvailabilityListener> ListenerRegistration<T> registerAvailabilityListener(final T listener) {
             synchronized (DOMRpcRouter.this) {
-                final ActionRegistration<T> ret = new ActionRegistration<>(DOMRpcRouter.this,
-                    listener, actionRoutingTable.getOperations(listener));
-                final Builder<ActionRegistration<?>> b = ImmutableList.builder();
-                b.addAll(actionListeners);
-                b.add(ret);
-                actionListeners = b.build();
+                final ActionRegistration<T> ret = new ActionRegistration<>(DOMRpcRouter.this, listener,
+                    actionRoutingTable.getOperations(listener));
+                actionListeners = ImmutableList.<ActionRegistration<?>>builder()
+                    .addAll(actionListeners)
+                    .add(ret)
+                    .build();
 
                 listenerNotifier.execute(ret::initialTable);
                 return ret;
@@ -477,10 +476,7 @@ public final class DOMRpcRouter extends AbstractRegistration
             synchronized (DOMRpcRouter.this) {
                 final Registration<T> ret = new Registration<>(DOMRpcRouter.this, listener,
                     routingTable.getOperations(listener));
-                final Builder<Registration<?>> b = ImmutableList.builder();
-                b.addAll(listeners);
-                b.add(ret);
-                listeners = b.build();
+                listeners = ImmutableList.<Registration<?>>builder().addAll(listeners).add(ret).build();
 
                 listenerNotifier.execute(ret::initialTable);
                 return ret;