Fix usage of StringBuilder when getting parent path 30/9830/1
authorBasheeruddin Ahmed <syedbahm@cisco.com>
Fri, 8 Aug 2014 21:39:25 +0000 (14:39 -0700)
committerBasheeruddin Ahmed <syedbahm@cisco.com>
Fri, 8 Aug 2014 21:39:25 +0000 (14:39 -0700)
in PathUtils
Making constants final
timing encode/decode in a test case

Change-Id: Ia552163dfe35dcd268bd8a0620c6b34c910f47b2
Signed-off-by: Basheeruddin Ahmed <syedbahm@cisco.com>
13 files changed:
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/AbortTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/AbortTransactionReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseDataChangeListenerRegistration.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CommitTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CommitTransactionReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CreateTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CreateTransactionChain.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PreCommitTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PreCommitTransactionReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/InstanceIdentifierUtils.java

index cf5174319d2128518f70391d0d459ad5af26b2cf..1dd0f3b8278407752b91afbb24548eb857385cbc 100644 (file)
@@ -12,18 +12,19 @@ package org.opendaylight.controller.cluster.datastore.node.utils;
 
 public class PathUtils {
     public static String getParentPath(String currentElementPath){
-        String parentPath = "";
+        StringBuilder parentPath = new StringBuilder();
 
         if(currentElementPath != null){
             String[] parentPaths = currentElementPath.split("/");
             if(parentPaths.length > 2){
                 for(int i=0;i<parentPaths.length-1;i++){
                     if(parentPaths[i].length() > 0){
-                        parentPath += "/" + parentPaths[i];
+                        parentPath.append("/");
+                        parentPath.append(parentPaths[i]);
                     }
                 }
             }
         }
-        return parentPath;
+        return parentPath.toString();
     }
 }
index 1b85d46fc6ebdfa9b13de079db728b9dadf2beac..bdad86ddc1e8fb5521607fbb91a575a99e677d38 100644 (file)
@@ -78,8 +78,12 @@ public class NormalizedNodeToNodeCodecTest {
 
     NormalizedNodeToNodeCodec codec =
         new NormalizedNodeToNodeCodec(schemaContext);
+    long start = System.currentTimeMillis();
     Container container =
         codec.encode(instanceIdentifierFromString(id), output);
+    long end = System.currentTimeMillis();
+
+    System.out.println("Timetaken to encode :"+(end-start));
 
     assertNotNull(container);
     assertEquals(id, container.getParentPath() + "/"
@@ -89,8 +93,12 @@ public class NormalizedNodeToNodeCodecTest {
     // first get the node representation of normalized node
     final Node node = container.getNormalizedNode();
 
+    start = System.currentTimeMillis();
     NormalizedNode<?, ?> normalizedNode =
         codec.decode(instanceIdentifierFromString(id), node);
+    end = System.currentTimeMillis();
+
+    System.out.println("Timetaken to decode :"+(end-start));
 
     assertEquals(normalizedNode.getValue().toString(), output.getValue()
         .toString());
index 4515bd70427a6eca892bb61115817941684d0a1c..c639064036e82ff80ea5556f769af60bcecbec51 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.cluster.datastore.messages;
 import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
 
 public class AbortTransaction implements SerializableMessage {
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.AbortTransaction.class;
+  public static final Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.AbortTransaction.class;
 
   @Override
   public Object toSerializable() {
index 31a06fe4c51f66329dd2b85dc49bad38afeb7b25..88e26401f700a449094960aaa784f984e9a27253 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.cluster.datastore.messages;
 import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
 
 public class AbortTransactionReply implements SerializableMessage {
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.AbortTransactionReply.class;
+  public static final Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.AbortTransactionReply.class;
 
 
   @Override
index 2c032aff65ea569567b09595f76b9b52a1108124..08f81c121f1d115b991005e945f2f03c4a8c1892 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.cluster.datastore.messages;
 import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
 
 public class CanCommitTransaction implements SerializableMessage {
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.CanCommitTransaction.class;
+  public static final Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.CanCommitTransaction.class;
 
   @Override
   public Object toSerializable() {
index 57237bcbe219d0a93ba0de4d25001683ed425bed..a54ee6209c8d75b36681cfec470f44a7bcbae593 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.cluster.datastore.messages;
 import org.opendaylight.controller.protobuff.messages.registration.ListenerRegistrationMessages;
 
 public class CloseDataChangeListenerRegistration implements SerializableMessage {
-  public static Class SERIALIZABLE_CLASS = ListenerRegistrationMessages.CloseDataChangeListenerRegistration.class;
+  public static final Class SERIALIZABLE_CLASS = ListenerRegistrationMessages.CloseDataChangeListenerRegistration.class;
   @Override
   public Object toSerializable() {
     return ListenerRegistrationMessages.CloseDataChangeListenerRegistration.newBuilder().build();
index 14187139aafefd1758dd0dff444882b1ae4c54c9..92138a769c1b4b0d3b3a7f4749313cc4c458002a 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.cluster.datastore.messages;
 import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
 
 public class CommitTransaction implements SerializableMessage {
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.CommitTransaction.class;
+  public static final  Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.CommitTransaction.class;
 
   @Override
   public Object toSerializable() {
index afeba298797ea2aead2879ec98d4100bde0996cd..5751b71037ba84e97a68834c8e28a1399e7c1d36 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommit
 
 public class CommitTransactionReply implements SerializableMessage {
 
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.CommitTransactionReply.class;
+  public static final Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.CommitTransactionReply.class;
 
   @Override
   public Object toSerializable() {
index b27ad86be987097b9bb9c37713a50116bfa5116e..d5c9e21611af20df37bb1999d00ead9a44495fda 100644 (file)
@@ -13,7 +13,7 @@ import org.opendaylight.controller.protobuff.messages.transaction.ShardTransacti
 
 
 public class CreateTransaction implements SerializableMessage {
-  public static Class SERIALIZABLE_CLASS = ShardTransactionMessages.CreateTransaction.class;
+  public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.CreateTransaction.class;
   private final String transactionId;
   private final int transactionType;
 
index 6339749f7bb298f27238493dfa999035f48d70ad..8dd04e540e881baf2ac1aefa60671b8803e96280 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.cluster.datastore.messages;
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages;
 
 public class CreateTransactionChain implements SerializableMessage{
-  public static Class SERIALIZABLE_CLASS = ShardTransactionChainMessages.CreateTransactionChain.class;
+  public static final Class SERIALIZABLE_CLASS = ShardTransactionChainMessages.CreateTransactionChain.class;
 
   @Override
   public Object toSerializable() {
index 1e5a05329b72c38b72637a6ceaeee3002741b64e..dae4cec3c3a606c059771e9335317d1d75c233d7 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommit
 
 public class PreCommitTransaction implements SerializableMessage{
 
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.PreCommitTransaction.class;
+  public static final Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.PreCommitTransaction.class;
 
   @Override
   public Object toSerializable() {
index 1aedae3ae72fb51b0794e12ee338c0ca478c97f4..fc07bfcb4b786793f02125bfad01f77088bcfe33 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommit
 
 public class PreCommitTransactionReply implements SerializableMessage{
 
-  public static Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.PreCommitTransactionReply.class;
+  public static final Class SERIALIZABLE_CLASS = ThreePhaseCommitCohortMessages.PreCommitTransactionReply.class;
 
   @Override
   public Object toSerializable() {
index 20268a67449d2ff1bcddeef240b91ef4f287a774..c154b81e3567d19e6be40db61dbe41690ebca78e 100644 (file)
@@ -18,19 +18,21 @@ public class InstanceIdentifierUtils {
         .getLogger(InstanceIdentifierUtils.class);
 
     public static String getParentPath(String currentElementPath) {
-        String parentPath = "";
+
+        StringBuilder parentPath = new StringBuilder();
 
         if (currentElementPath != null) {
             String[] parentPaths = currentElementPath.split("/");
             if (parentPaths.length > 2) {
                 for (int i = 0; i < parentPaths.length - 1; i++) {
                     if (parentPaths[i].length() > 0) {
-                        parentPath += "/" + parentPaths[i];
+                        parentPath.append( "/");
+                        parentPath.append( parentPaths[i]);
                     }
                 }
             }
         }
-        return parentPath;
+        return parentPath.toString();
     }
 
     @Deprecated