/*
* 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;
case 2: value = s.minimum(); break;
case 3: value = s.maximum(); break;
case 4: value = s.mean(); break;
case 5: value = s.rms(); break;
case 6: value = s.standardDeviation(allPopulation); break;
default: throw new AssertionError(i);
}
if (needsConfigure) {
configure(format, s);
}
table.append(beforeFill);
table.nextColumn(fillCharacter);
table.append(format.format(value));
table.setCellAlignment(TableAppender.ALIGN_RIGHT);
}
table.append(lineSeparator);
}
if (horizontalLine != 0) {