List of usage examples for com.google.common.collect ImmutableTable rowMap
@Override public abstract ImmutableMap<R, Map<C, V>> rowMap();
The value Map From source file:blue.lapis.methodremapper.Remapper.java From source file:google.registry.tools.server.ListObjectsAction.javaUsage
/**
* Creates a new {@link Remapper} instance using the specified provider and
* mappings.//from w ww . j a v a 2s. c o m
*
* @param provider The provider of the classes that will be scanned
* @param mappings The method mappings to use
*/
public Remapper(ClassProvider provider, ImmutableTable<String, String, String> mappings) {
this.provider = checkNotNull(provider, "provider");
this.classes = Maps.newHashMap(mappings.rowMap());
}
/** 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//from ww w . j ava2s .c o m
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;
}