BUG-2459: use ImmutableSet instead of an unmodifieable HashSet 10/13410/5
authorRobert Varga <rovarga@cisco.com>
Fri, 5 Dec 2014 10:36:04 +0000 (11:36 +0100)
committerRobert Varga <rovarga@cisco.com>
Thu, 18 Dec 2014 15:58:36 +0000 (16:58 +0100)
This makes the lookups much more efficient.

Change-Id: I9c9a210b1eef1b5a2850013259191fde9a9c439b
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceSnapshotImpl.java

index 1a35e4d6bace2e313c084cf5ffdf23bbfd3833bb..26abdd974ddc7a6d9bfdd42c85147e39fde5e7b6 100644 (file)
@@ -8,8 +8,8 @@
 
 package org.opendaylight.controller.netconf.impl.osgi;
 
-import java.util.Collections;
-import java.util.HashSet;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
 import java.util.Set;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
@@ -21,17 +21,15 @@ public class NetconfOperationServiceSnapshotImpl implements NetconfOperationServ
     private final Set<NetconfOperationService> services;
     private final String netconfSessionIdForReporting;
 
-    public NetconfOperationServiceSnapshotImpl(Set<NetconfOperationServiceFactory> factories, String sessionIdForReporting) {
-        Set<NetconfOperationService> services = new HashSet<>();
+    public NetconfOperationServiceSnapshotImpl(final Set<NetconfOperationServiceFactory> factories, final String sessionIdForReporting) {
+        final Builder<NetconfOperationService> b = ImmutableSet.builder();
         netconfSessionIdForReporting = sessionIdForReporting;
         for (NetconfOperationServiceFactory factory : factories) {
-            services.add(factory.createService(netconfSessionIdForReporting));
+            b.add(factory.createService(netconfSessionIdForReporting));
         }
-        this.services = Collections.unmodifiableSet(services);
+        this.services = b.build();
     }
 
-
-
     @Override
     public String getNetconfSessionIdForReporting() {
         return netconfSessionIdForReporting;