switch (borderWidth) {
case 1: horizontalLine = '─'; separator += "│ "; break;
case 2: horizontalLine = '═'; separator += "║ "; break;
}
final TableAppender table = new TableAppender(toAppendTo, separator);
final Vocabulary resources = Vocabulary.getResources(headerLocale);
/*
* If there is a header for at least one statistics, write the full headers row.
*/
if (horizontalLine != 0) {
table.nextLine(horizontalLine);
}
if (showHeaders) {
table.nextColumn();
for (final String header : headers) {
if (header != null) {
table.append(header);
table.setCellAlignment(TableAppender.ALIGN_CENTER);
}
table.nextColumn();
}
table.append(lineSeparator);
if (horizontalLine != 0) {
table.nextLine(horizontalLine);
}
}
/*
* Initialize the NumberFormat for formatting integers without scientific notation.
* This is necessary since the format may have been modified by a previous execution
* of this method.
*/
final Format format = getFormat(Double.class);
if (format instanceof DecimalFormat) {
((DecimalFormat) format).applyPattern("#0"); // Also disable scientific notation.
} else if (format instanceof NumberFormat) {
setFractionDigits((NumberFormat) format, 0);
}
/*
* Iterates over the rows to format (count, minimum, maximum, mean, RMS, standard deviation),
* then iterate over columns (statistics on sample values, on the first derivatives, etc.)
* The NumberFormat configuration may be different for each column, but we can skip many
* reconfiguration in the common case where there is only one column.
*/
boolean needsConfigure = false;
for (int i=0; i<KEYS.length; i++) {
switch (i) {
case 1: if (!showNaNCount) continue; else break;
// Case 0 and 1 use the above configuration for integers.
// Case 2 unconditionally needs a reconfiguration for floating point values.
// Case 3 and others need reconfiguration only if there is more than one column.
case 2: needsConfigure = true; break;
case 3: needsConfigure = (stats[0].differences() != null); break;
}
table.setCellAlignment(TableAppender.ALIGN_LEFT);
table.append(resources.getString(KEYS[i])).append(':');
for (final Statistics s : stats) {
final Number value;
switch (i) {
case 0: value = s.count(); break;
case 1: value = s.countNaN(); break;