Example usage for com.google.common.collect ImmutableTable columnMap

List of usage examples for com.google.common.collect ImmutableTable columnMap

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableTable columnMap.

Prototype

@Override
public abstract ImmutableMap<C, Map<R, V>> columnMap();

Source Link

Document

The value Map instances in the returned map are ImmutableMap instances as well.

Usage

From source file:google.registry.tools.server.ListObjectsAction.java

/**
 * Computes the column widths of the given table of strings column-keyed by strings and returns
 * them as a map from column key name to integer width.  The column width is defined as the max
 * length of any string in that column, including the name of the column.
 *//*  w  ww.j av a2  s  .  c o m*/
private static ImmutableMap<String, Integer> computeColumnWidths(ImmutableTable<?, String, String> data,
        final boolean includingHeader) {
    return ImmutableMap.copyOf(Maps.transformEntries(data.columnMap(),
            new Maps.EntryTransformer<String, Map<?, String>, Integer>() {
                @Override
                public Integer transformEntry(String columnName, Map<?, String> columnValues) {
                    // Return the length of the longest string in this column (including the column name).
                    return Ordering.natural()
                            .max(Iterables.transform(
                                    Iterables.concat(ImmutableList.of(includingHeader ? columnName : ""),
                                            columnValues.values()),
                                    new Function<String, Integer>() {
                                        @Override
                                        public Integer apply(String value) {
                                            return value.length();
                                        }
                                    }));
                }
            }));
}