Improve NetconfMessageTransformer.isBaseOrNotificationRpc() 36/82336/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 May 2019 14:02:44 +0000 (16:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 30 May 2019 14:07:00 +0000 (16:07 +0200)
Rather than performing up to three equality comparisons, keep
matching URIs in a constant set and perform Set.contains().

Change-Id: Iaddf2bfee70ed0f53d633998f005bf9bb2290099
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java

index 79bc20ad36533c89655bc8435b2d53f235c6c08a..10603017c2e909c7a2371993761d9435b0bf977b 100644 (file)
@@ -21,6 +21,7 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Multimaps;
 import java.io.IOException;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.time.Instant;
 import java.util.Collection;
@@ -76,6 +77,11 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageTransformer.class);
 
+    private static final ImmutableSet<URI> BASE_OR_NOTIFICATION_NS = ImmutableSet.of(
+        NETCONF_URI,
+        IETF_NETCONF_NOTIFICATIONS.getNamespace(),
+        CREATE_SUBSCRIPTION_RPC_QNAME.getNamespace());
+
     private final SchemaContext schemaContext;
     private final BaseSchema baseSchema;
     private final MessageCounter counter;
@@ -258,9 +264,7 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
     }
 
     private static boolean isBaseOrNotificationRpc(final QName rpc) {
-        return rpc.getNamespace().equals(NETCONF_URI)
-                || rpc.getNamespace().equals(IETF_NETCONF_NOTIFICATIONS.getNamespace())
-                || rpc.getNamespace().equals(CREATE_SUBSCRIPTION_RPC_QNAME.getNamespace());
+        return BASE_OR_NOTIFICATION_NS.contains(rpc.getNamespace());
     }
 
     @Override