cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ko...@apache.org
Subject [09/10] git commit: updated refs/heads/master to 8ed9162
Date Sun, 09 Feb 2014 21:25:18 GMT
Replaced String concatenation in loop

Replaced String concatenation in loop with StringBuilder
Unit test added

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8d801bff
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8d801bff
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8d801bff

Branch: refs/heads/master
Commit: 8d801bffab680752d5c8ac4243197800c0cc323d
Parents: 55b6b6d
Author: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Authored: Sun Feb 9 21:27:28 2014 +0100
Committer: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Committed: Sun Feb 9 21:27:28 2014 +0100

----------------------------------------------------------------------
 utils/src/com/cloud/utils/StringUtils.java      |  8 ++++----
 utils/test/com/cloud/utils/StringUtilsTest.java | 11 +++++++++++
 2 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d801bff/utils/src/com/cloud/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java
index 38d1369..21993a6 100644
--- a/utils/src/com/cloud/utils/StringUtils.java
+++ b/utils/src/com/cloud/utils/StringUtils.java
@@ -95,17 +95,17 @@ public class StringUtils {
      */
 
     public static String listToCsvTags(List<String> tagsList) {
-        String tags = "";
+        StringBuilder tags = new StringBuilder();
         if (tagsList.size() > 0) {
             for (int i = 0; i < tagsList.size(); i++) {
-                tags += tagsList.get(i);
+                tags.append(tagsList.get(i));
                 if (i != tagsList.size() - 1) {
-                    tags += ",";
+                    tags.append(',');
                 }
             }
         }
 
-        return tags;
+        return tags.toString();
     }
 
     public static String getExceptionStackInfo(Throwable e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d801bff/utils/test/com/cloud/utils/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/StringUtilsTest.java b/utils/test/com/cloud/utils/StringUtilsTest.java
index cc22f9d..af7e4e3 100644
--- a/utils/test/com/cloud/utils/StringUtilsTest.java
+++ b/utils/test/com/cloud/utils/StringUtilsTest.java
@@ -18,6 +18,11 @@ package com.cloud.utils;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import junit.framework.Assert;
+
 import org.junit.Test;
 
 public class StringUtilsTest {
@@ -216,4 +221,10 @@ public class StringUtilsTest {
         String result = StringUtils.cleanString(input);
         assertEquals(result, expected);
     }
+
+    @Test
+    public void listToCsvTags() {
+        Assert.assertEquals("a,b,c", StringUtils.listToCsvTags(Arrays.asList("a","b", "c")));
+        Assert.assertEquals("", StringUtils.listToCsvTags(new ArrayList<String>()));
+    }
 }


Mime
View raw message