Simplify code using Java 8 features
[netconf.git] / netconf / netconf-impl / src / main / java / org / opendaylight / netconf / impl / osgi / NetconfCapabilityMonitoringService.java
index 6259ba28a3af10d84eaf787c28ac09dc6b10b3c0..f627f15a7e81902889567ab61fc09a7ae7800dd7 100644 (file)
@@ -106,11 +106,8 @@ class NetconfCapabilityMonitoringService implements CapabilityListener, AutoClos
             }
 
             final String currentModuleName = cap.getModuleName().get();
-            Map<String, String> revisionMap = mappedModulesToRevisionToSchema.get(currentModuleName);
-            if (revisionMap == null) {
-                revisionMap = Maps.newHashMap();
-                mappedModulesToRevisionToSchema.put(currentModuleName, revisionMap);
-            }
+            Map<String, String> revisionMap =
+                mappedModulesToRevisionToSchema.computeIfAbsent(currentModuleName, k -> Maps.newHashMap());
 
             final String currentRevision = cap.getRevision().get();
             revisionMap.put(currentRevision, cap.getCapabilitySchema().get());
@@ -171,7 +168,7 @@ class NetconfCapabilityMonitoringService implements CapabilityListener, AutoClos
 
                 builder.setLocation(transformLocations(cap.getLocation()));
 
-                builder.setKey(new SchemaKey(Yang.class, identifier, version));
+                builder.withKey(new SchemaKey(Yang.class, identifier, version));
 
                 schemas.add(builder.build());
             }
@@ -205,7 +202,7 @@ class NetconfCapabilityMonitoringService implements CapabilityListener, AutoClos
     }
 
     @Override
-    public synchronized void close() throws Exception {
+    public synchronized void close() {
         listeners.clear();
         capabilities.clear();
     }
@@ -234,14 +231,14 @@ class NetconfCapabilityMonitoringService implements CapabilityListener, AutoClos
     private static NetconfCapabilityChange computeDiff(final Set<Capability> added, final Set<Capability> removed) {
         final NetconfCapabilityChangeBuilder netconfCapabilityChangeBuilder = new NetconfCapabilityChangeBuilder();
         netconfCapabilityChangeBuilder
-                .setChangedBy(new ChangedByBuilder().setServerOrUser(new ServerBuilder().setServer(true).build())
-                        .build());
+                .setChangedBy(new ChangedByBuilder().setServerOrUser(
+                    new ServerBuilder().setServer(Boolean.TRUE).build()).build());
         netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(Collections2
                 .transform(removed, CAPABILITY_TO_URI)));
         netconfCapabilityChangeBuilder.setAddedCapability(Lists.newArrayList(Collections2
                 .transform(added, CAPABILITY_TO_URI)));
         // TODO modified should be computed ... but why ?
-        netconfCapabilityChangeBuilder.setModifiedCapability(Collections.<Uri>emptyList());
+        netconfCapabilityChangeBuilder.setModifiedCapability(Collections.emptyList());
         return netconfCapabilityChangeBuilder.build();
     }