Use StringBuilders in loops
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogPanel.java b/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
index 88aa9ef..96eb716 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
@@ -1864,17 +1864,17 @@
}
if (o instanceof String[]) {
- String value = "";
+ StringBuilder value = new StringBuilder();
//exception - build message + throwable
String[] ti = (String[])o;
if (ti.length > 0 && (!(ti.length == 1 && ti[0].equals("")))) {
LoggingEventWrapper loggingEventWrapper = ((ChainsawCyclicBufferTableModel)(currentTable.getModel())).getRow(row);
- value = loggingEventWrapper.getLoggingEvent().getMessage().toString();
+ value = new StringBuilder(loggingEventWrapper.getLoggingEvent().getMessage().toString());
for (int i=0;i<((String[])o).length;i++) {
- value = value + "\n" + ((String[]) o)[i];
+ value.append('\n').append(((String[]) o)[i]);
}
}
- return value;
+ return value.toString();
}
return "";
}
diff --git a/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java b/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
index 2818b1b..b65ec41 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LoggerNameTreePanel.java
@@ -1094,7 +1094,7 @@
//add all top level loggers as hidden loggers
TreePath[] paths = logTree.getSelectionPaths();
- String parentPathString = "";
+ StringBuilder parentPathString = new StringBuilder();
DefaultMutableTreeNode root;
if ((paths == null) || (paths.length == 0))
{
@@ -1105,12 +1105,12 @@
//don't add 'root logger' to path string
for (int i=1;i<path.length;i++) {
if (i > 1) {
- parentPathString = parentPathString + ".";
+ parentPathString.append(".");
}
- parentPathString = parentPathString + path[i].toString();
+ parentPathString.append(path[i].toString());
}
- if (!(parentPathString.equals(""))) {
- parentPathString = parentPathString + ".";
+ if (!(parentPathString.toString().equals(""))) {
+ parentPathString.append(".");
}
}
Enumeration topLevelLoggersEnumeration = root.children();
diff --git a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
index d28baae..34853b9 100644
--- a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
+++ b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
@@ -512,22 +512,24 @@
protected void process(BufferedReader bufferedReader) throws IOException {
Matcher eventMatcher;
Matcher exceptionMatcher;
- String line;
+ String readLine;
//if newlines are provided in the logFormat - (NL) - combine the lines prior to matching
- while ((line = bufferedReader.readLine()) != null) {
+ while ((readLine = bufferedReader.readLine()) != null) {
+ StringBuilder line = new StringBuilder(readLine);
//there is already one line (read above, start i at 1
for (int i=1;i<lineCount;i++)
{
String thisLine = bufferedReader.readLine();
if (thisLine != null)
{
- line = line + newLine + thisLine;
+ line.append(newLine).append(thisLine);
}
}
- eventMatcher = regexpPattern.matcher(line);
+ String input = line.toString();
+ eventMatcher = regexpPattern.matcher(input);
//skip empty line entries
- if (line.trim().equals("")) {continue;}
- exceptionMatcher = exceptionPattern.matcher(line);
+ if (input.trim().equals("")) {continue;}
+ exceptionMatcher = exceptionPattern.matcher(input);
if (eventMatcher.matches()) {
//build an event from the previous match (held in current map)
LoggingEvent event = buildEvent();
@@ -539,7 +541,7 @@
currentMap.putAll(processEvent(eventMatcher.toMatchResult()));
} else if (exceptionMatcher.matches()) {
//an exception line
- additionalLines.add(line);
+ additionalLines.add(input);
} else {
//neither...either post an event with the line or append as additional lines
//if this was a logging event with multiple lines, each line will show up as its own event instead of being
@@ -560,9 +562,9 @@
if (lastTime != null) {
currentMap.put(TIMESTAMP, lastTime);
}
- currentMap.put(MESSAGE, line);
+ currentMap.put(MESSAGE, input);
} else {
- additionalLines.add(line);
+ additionalLines.add(input);
}
}
}
@@ -739,24 +741,26 @@
}
}
- String buildingInt = "";
+ StringBuilder buildingInt = new StringBuilder();
for (int i=0;i<newPattern.length();i++) {
String thisValue = String.valueOf(newPattern.substring(i, i+1));
if (isInteger(thisValue)) {
- buildingInt = buildingInt + thisValue;
+ buildingInt.append(thisValue);
} else {
- if (isInteger(buildingInt)) {
- matchingKeywords.add(buildingKeywords.get(Integer.parseInt(buildingInt)));
+ String stringInt = buildingInt.toString();
+ if (isInteger(stringInt)) {
+ matchingKeywords.add(buildingKeywords.get(Integer.parseInt(stringInt)));
}
//reset
- buildingInt = "";
+ buildingInt.setLength(0);
}
}
//if the very last value is an int, make sure to add it
- if (isInteger(buildingInt)) {
- matchingKeywords.add(buildingKeywords.get(Integer.parseInt(buildingInt)));
+ String stringInt = buildingInt.toString();
+ if (isInteger(stringInt)) {
+ matchingKeywords.add(buildingKeywords.get(Integer.parseInt(stringInt)));
}
newPattern = replaceMetaChars(newPattern);