Skip to content

Commit

Permalink
Merge pull request dhorions#274 from dev-comrade/feat/addListToTable-…
Browse files Browse the repository at this point in the history
…performance

feat(data-table): fix poor performance addListToTable method
  • Loading branch information
johnmanko authored Nov 3, 2023
2 parents 5bf2885 + ad69d3e commit 1407334
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main/java/be/quodlibet/boxable/datatable/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,32 +355,31 @@ public Cell getLastColumnCellTemplateEven() {
* @throws IOException parsing error
*/
public void addListToTable(List<List> data, Boolean hasHeader) throws IOException {
char separator = ';';
if (data == null || data.isEmpty()) {
return;
}
String output = "";
StringBuilder output = new StringBuilder();
char separator = ';';

// Convert Map of arbitrary objects to a csv String
for (List<? extends Object> inputList : data) {
StringBuilder row = new StringBuilder();
for (Object v : inputList) {
String value = v.toString();
if (value.contains("" + separator)) {
// surround value with quotes if it contains the escape
// character
value = "\"" + value + "\"";
}
}
value = value.replaceAll("\n", "<br>");
output += value + separator;
row.append(value).append(separator);
}
// remove the last separator
output = removeLastChar(output);
output += "\n";
row = new StringBuilder(row.substring(0, row.length() - 1));
output.append(row).append("\n");
}
addCsvToTable(output, hasHeader, separator);
}

private static String removeLastChar(String str) {
return str.substring(0, str.length() - 1);
addCsvToTable(output.toString(), hasHeader, separator);
}

/**
Expand Down

0 comments on commit 1407334

Please sign in to comment.