Cleanup SimulatedCreateSubscription 35/76535/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 27 Sep 2018 12:04:11 +0000 (14:04 +0200)
committerJakub Morvay <jakub.morvay@gmail.com>
Mon, 1 Oct 2018 14:11:42 +0000 (14:11 +0000)
Using .get().get() twice is ugly, create a local variable.

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

netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpc/SimulatedCreateSubscription.java

index 8a42baa7a29e6d263ffcc6c15416ff7f93642333..fc7e99a31d3cf0b72cb56b05e872a3b20f79b882 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.collect.Maps;
 import java.io.File;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -45,7 +46,7 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
     public SimulatedCreateSubscription(final String id, final Optional<File> notificationsFile) {
         super(id);
 
-        Optional<Notifications> notifs;
+        final Optional<Notifications> notifs;
 
         if (notificationsFile.isPresent()) {
             notifs = Optional.of(loadNotifications(notificationsFile.get()));
@@ -55,9 +56,9 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
         }
 
         if (notifs.isPresent()) {
-            Map<Notification, NetconfMessage> preparedMessages = Maps.newHashMapWithExpectedSize(
-                notifs.get().getNotificationList().size());
-            for (final Notification notification : notifs.get().getNotificationList()) {
+            final Collection<Notification> toCopy = notifs.get().getNotificationList();
+            final Map<Notification, NetconfMessage> preparedMessages = Maps.newHashMapWithExpectedSize(toCopy.size());
+            for (final Notification notification : toCopy) {
                 final NetconfMessage parsedNotification = parseNetconfNotification(notification.getContent());
                 preparedMessages.put(notification, parsedNotification);
             }
@@ -65,7 +66,6 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
         } else {
             this.notifications = Collections.emptyMap();
         }
-
     }
 
     private static Notifications loadNotifications(final File file) {