All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ansitable.SizingStrategies Maven / Gradle / Ivy

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();
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy