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 cf51743..1dd0f3b 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 1b85d46..bdad86d 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 4515bd7..c639064 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 31a06fe..88e2640 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 2c032af..08f81c1 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 57237bc..a54ee62 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 1418713..92138a7 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 afeba29..5751b71 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 b27ad86..d5c9e21 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 6339749..8dd04e5 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 1e5a053..dae4cec 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 1aedae3..fc07bfc 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 20268a6..c154b81 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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.