Permalink
Browse files

Used StringBuilder instead String concatenation

  • Loading branch information...
1 parent a5484a7 commit 6b9850e229536adb81f6f9886bee9302093b0947 Arjan Wulder committed Aug 3, 2012
@@ -78,10 +78,10 @@ public String getAttribute(String key) {
}
protected String makeIndent(int depth) {
- String indent = "";
+ StringBuilder indent = new StringBuilder();
for (int i = 0; i < depth; i++)
- indent += '\t';
- return indent;
+ indent.append('\t');
+ return indent.toString();
}
public static class Attribute {
@@ -173,11 +173,11 @@ private String makeTagEnd() {
}
private String makeAttributes() {
- String attributes = "";
+ StringBuilder attributes = new StringBuilder();
for (Attribute attribute : HtmlTag.this.attributes) {
- attributes += " " + attribute.name + "=\"" + attribute.value + "\"";
+ attributes.append(" ").append(attribute.name).append("=\"").append(attribute.value).append("\"");
}
- return attributes;
+ return attributes.toString();
}
private String makeTag() {
@@ -13,7 +13,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import util.FileUtil;
import fitnesse.FitNesseContext;
import fitnesse.authentication.AlwaysSecureOperation;
import fitnesse.authentication.SecureOperation;
@@ -22,7 +21,7 @@
import fitnesse.http.Response;
import fitnesse.http.SimpleResponse;
import fitnesse.http.UploadedFile;
-import fitnesse.responders.ErrorResponder;
+import util.FileUtil;
public class UploadResponder implements SecureResponder {
private static final Pattern filenamePattern = Pattern.compile("([^/\\\\]*[/\\\\])*([^/\\\\]*)");
@@ -90,14 +89,14 @@ public static String makeNewFilename(String filename, int copyId) {
if (parts.length == 1)
return filename + "_copy" + copyId;
else {
- String newName = "";
+ StringBuilder newName = new StringBuilder();
for (int i = 0; i < parts.length - 1; i++) {
if (i != 0)
- newName += ".";
- newName += parts[i];
+ newName.append(".");
+ newName.append(parts[i]);
}
- newName += "_copy" + copyId + "." + parts[parts.length - 1];
- return newName;
+ newName.append("_copy").append(copyId).append(".").append(parts[parts.length - 1]);
+ return newName.toString();
}
}
@@ -299,9 +299,9 @@ String processAllTablesOnPage(ReadOnlyPageData pageData) throws IOException {
testResults = pageData;
boolean runAllTablesAtOnce = false;
- String htmlResults = "";
+ StringBuilder htmlResults = new StringBuilder();
if (runAllTablesAtOnce || (allTables.size() == 0)) {
- htmlResults = processTablesAndGetHtml(allTables, START_OF_TEST, END_OF_TEST);
+ htmlResults.append(processTablesAndGetHtml(allTables, START_OF_TEST, END_OF_TEST));
} else {
List<SlimTable> oneTableList = new ArrayList<SlimTable>(1);
for (int index = 0; index < allTables.size(); index++) {
@@ -310,11 +310,11 @@ String processAllTablesOnPage(ReadOnlyPageData pageData) throws IOException {
SlimTable nextTable = (index + 1 < allTables.size()) ? allTables.get(index + 1) : END_OF_TEST;
oneTableList.add(theTable);
- htmlResults += processTablesAndGetHtml(oneTableList, startWithTable, nextTable);
+ htmlResults.append(processTablesAndGetHtml(oneTableList, startWithTable, nextTable));
oneTableList.clear();
}
}
- return htmlResults;
+ return htmlResults.toString();
}
protected abstract TableScanner scanTheTables(ReadOnlyPageData pageData);
@@ -505,10 +505,10 @@ public ParsedPage getPreparsedScenarioLibrary() {
}
private String getScenarioLibraryContent() {
- String content = "!*> Precompiled Libraries\n\n";
- content += includeUncleLibraries();
- content += "*!\n";
- return content;
+ StringBuilder content = new StringBuilder("!*> Precompiled Libraries\n\n");
+ content.append(includeUncleLibraries());
+ content.append("*!\n");
+ return content.toString();
}
private String includeUncleLibraries() {
@@ -18,8 +18,8 @@ public static boolean isWikiWord(String word) {
public static String makeWikiWord(String input) {
if (isWikiWord(input)) return input;
- String base = input;
- while (base.length() < 3) base += "a";
+ StringBuilder base = new StringBuilder(input);
+ while (base.length() < 3) base.append("a");
return base.substring(0, 1).toUpperCase()
+ base.substring(1, base.length() - 1).toLowerCase()
+ base.substring(base.length() - 1).toUpperCase();
@@ -1,8 +1,9 @@
package fitnesse.wikitext.test;
-import fitnesse.html.HtmlElement;
import org.junit.Test;
+import fitnesse.html.HtmlElement;
+
public class ListTest {
@Test
public void scansLists() {
@@ -37,9 +38,9 @@ private String listItem(String item, int level) {
}
private String indent(int level) {
- String result = "";
- for (int i = 0; i < level; i++) result += "\t";
- return result;
+ StringBuilder result = new StringBuilder();
+ for (int i = 0; i < level; i++) result.append("\t");
+ return result.toString();
}
@Test
Oops, something went wrong.

0 comments on commit 6b9850e

Please sign in to comment.