Permalink
Browse files

Used StringBuilder for string concatenation in loops.

  • Loading branch information...
eseifert committed Jul 29, 2017
1 parent 930ffa9 commit bf8508e0d88eb16963538a1bddab572d3739b421
@@ -73,16 +73,16 @@ public boolean equals(Object obj) {
@Override
public String toString() {
String representation = "(";
StringBuilder representation = new StringBuilder("(");
for (int elementIndex = 0; elementIndex < values.length; elementIndex++) {
Comparable element = values[elementIndex];
representation += element;
representation.append(element);
if (elementIndex != values.length - 1) {
representation += ", ";
representation.append(", ");
}
}
representation += ")";
return representation;
representation.append(")");
return representation.toString();
}
public Record insert(Comparable<?> value, int position) {
@@ -186,12 +186,12 @@ public DataSource read(InputStream input, Class<? extends Comparable<?>>... type
List<Comparable<?>> row = new LinkedList<>();
int rowIndex = 0;
int colIndex = 0;
String cellContent = "";
StringBuilder cellContent = new StringBuilder();
for (Token token : tokens) {
if (token.getType() == CSVTokenType.TEXT ||
token.getType() == CSVTokenType.EMPTY_SPACE) {
// Store the token text
cellContent += token.getContent();
cellContent.append(token.getContent());
} else if (token.getType() == CSVTokenType.COLUMN_SEPARATOR ||
token.getType() == CSVTokenType.ROW_SEPARATOR) {
// Check for a valid number of columns
@@ -208,7 +208,7 @@ public DataSource read(InputStream input, Class<? extends Comparable<?>>... type
Comparable<?> cell = null;
try {
cell = (Comparable<?>) parseMethod.invoke(
null, cellContent.trim());
null, cellContent.toString().trim());
} catch (IllegalArgumentException e) {
throw new RuntimeException(MessageFormat.format(
@@ -219,10 +219,10 @@ public DataSource read(InputStream input, Class<? extends Comparable<?>>... type
"Could not access method for parsing data type {0} in column {1,number,integer}.", //$NON-NLS-1$
types[colIndex].getSimpleName(), colIndex));
} catch (InvocationTargetException e) {
if (!cellContent.isEmpty()) {
if (cellContent.length() > 0) {
throw new IOException(MessageFormat.format(
"Type mismatch in line {0,number,integer}, column {1,number,integer}: got \"{2}\", but expected {3} value.", //$NON-NLS-1$
rowIndex + 1, colIndex + 1, cellContent, colType.getSimpleName()));
rowIndex + 1, colIndex + 1, cellContent.toString(), colType.getSimpleName()));
}
}
row.add(cell);
@@ -244,7 +244,7 @@ public DataSource read(InputStream input, Class<? extends Comparable<?>>... type
row.clear();
colIndex = 0;
}
cellContent = "";
cellContent = new StringBuilder();
}
}

0 comments on commit bf8508e

Please sign in to comment.