mirror of https://github.com/apache/cloudstack.git
Replaced String concatenation in loop
Replaced String concatenation in loop with StringBuilder Unit test added Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
This commit is contained in:
parent
55b6b6d50b
commit
8d801bffab
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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>()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue