ansitable.SizingStrategies Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ansitable Show documentation
Show all versions of ansitable Show documentation
tools for displaying tabular data in a terminal
The newest version!
package ansitable;
import com.google.common.collect.ImmutableList;
final class SizingStrategies {
@FunctionalInterface
interface SizingStrategy {
TableFormat buildTableFormat(ImmutableList columnNames, ImmutableList rows);
}
static final SizingStrategy COLUMNS_FIT_LARGEST_CONTENTS = (columnNames, rows) -> {
int ncols = columnNames.size();
TableFormat.Builder builder = TableFormat.builder(ncols);
for (int i = 0; i < ncols; ++i) {
String name = columnNames.get(i);
ColumnFormat.Builder columnFormat = new ColumnFormat.Builder(name);
for (Row row : rows) {
columnFormat.record(row.columns()[i]);
}
builder.recordColumn(columnFormat.build());
}
return builder.build();
};
static SizingStrategy allColumnsHaveWidth(int width) {
return (columnNames, rows) -> {
TableFormat.Builder builder = TableFormat.builder(columnNames.size());
for (String columnName : columnNames) {
builder.recordColumn(ColumnFormat.fixedWidth(columnName, width));
}
return builder.build();
};
}
}