List of usage examples for com.google.common.collect ImmutableTable columnKeySet
@Override
public ImmutableSet<C> columnKeySet()
From source file:google.registry.tools.server.ListObjectsAction.java
/** * Check whether to display headers. If the parameter is not set, print headers only if there * is more than one column./*from w w w . j a v a 2 s .c o m*/ */ private boolean isHeaderRowInUse(final ImmutableTable<?, String, String> data) { return ((printHeaderRow != null) && printHeaderRow.isPresent()) ? printHeaderRow.get() : (data.columnKeySet().size() > 1); }
From source file:google.registry.tools.server.ListObjectsAction.java
/** Converts the provided table of data to text, formatted using the provided column widths. */ private List<String> generateFormattedData(ImmutableTable<T, String, String> data, ImmutableMap<String, Integer> columnWidths) { Function<Map<String, String>, String> rowFormatter = makeRowFormatter(columnWidths); List<String> lines = new ArrayList<>(); if (isHeaderRowInUse(data)) { // Add a row of headers (column names mapping to themselves). Map<String, String> headerRow = Maps.asMap(data.columnKeySet(), Functions.<String>identity()); lines.add(rowFormatter.apply(headerRow)); // Add a row of separator lines (column names mapping to '-' * column width). Map<String, String> separatorRow = Maps.transformValues(columnWidths, new Function<Integer, String>() { @Override/* www . j a v a 2 s. c om*/ public String apply(Integer width) { return Strings.repeat("-", width); } }); lines.add(rowFormatter.apply(separatorRow)); } // Add the actual data rows. for (Map<String, String> row : data.rowMap().values()) { lines.add(rowFormatter.apply(row)); } return lines; }