String pattern = queryFormat.getPattern(col);
List<Integer> indices = columnIndices.getColumnIndices(col);
boolean allSucceeded = true;
for (int i : indices) {
ColumnDescription colDesc = columnDescriptions.get(i);
ValueFormatter f = ValueFormatter.createFromPattern(colDesc.getType(), pattern, locale);
if (f == null) {
allSucceeded = false;
} else {
indexToFormatter.put(i, f);
table.getColumnDescription(i).setPattern(pattern); // May override datasource pattern.
}
}
if (!allSucceeded) {
Warning warning = new Warning(ReasonType.ILLEGAL_FORMATTING_PATTERNS,
"Illegal formatting pattern: " + pattern + " requested on column: " + col.getId());
table.addWarning(warning);
}
}
for (TableRow row : table.getRows()) {
for (int col : indexToFormatter.keySet()) {
TableCell cell = row.getCell(col);
Value value = cell.getValue();
ValueFormatter formatter = indexToFormatter.get(col);
String formattedValue = formatter.format(value);
cell.setFormattedValue(formattedValue);
}
}
return table;
}