Use singleton NodeIdentifierWithPredicates
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / ClusterUtils.java
index 2fb9cf1cda0663db408e740f6ff94e66e621e307..927dca43e6b49da627bfebbd1651b677915a357f 100644 (file)
@@ -5,10 +5,8 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.datastore.utils;
 
-import java.util.Map;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
@@ -21,7 +19,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Utils for encoding prefix shard name.
  */
-public class ClusterUtils {
+public final class ClusterUtils {
     private static final Logger LOG = LoggerFactory.getLogger(ClusterUtils.class);
 
     // id for the shard used to store prefix configuration
@@ -44,6 +42,9 @@ public class ClusterUtils {
     public static final YangInstanceIdentifier SHARD_LIST_PATH =
             PREFIX_SHARDS_PATH.node(SHARD_LIST_QNAME).toOptimized();
 
+    private ClusterUtils() {
+    }
+
     public static ShardIdentifier getShardIdentifier(final MemberName memberName, final DOMDataTreeIdentifier prefix) {
         final String type;
         switch (prefix.getDatastoreType()) {
@@ -80,15 +81,12 @@ public class ClusterUtils {
             builder.append(p.getNodeType().getLocalName());
             if (p instanceof NodeIdentifierWithPredicates) {
                 builder.append("-key_");
-                final Map<QName, Object> key = ((NodeIdentifierWithPredicates) p).getKeyValues();
-                key.entrySet().forEach(e -> {
-                    builder.append(e.getKey().getLocalName());
-                    builder.append(e.getValue());
-                    builder.append("-");
+                ((NodeIdentifierWithPredicates) p).entrySet().forEach(entry -> {
+                    builder.append(entry.getKey().getLocalName()).append(entry.getValue()).append('-');
                 });
-                builder.append("_");
+                builder.append('_');
             }
-            builder.append("!");
+            builder.append('!');
         });
         return builder.toString();
     }