Class TableUtils

java.lang.Object
io.github.connellite.collections.TableUtils

public class TableUtils extends Object
Utilities for transposing column-oriented and row-oriented tabular data represented as maps.
  • Constructor Details

    • TableUtils

      public TableUtils()
  • Method Details

    • transposeColumnsToRows

      public static <K, T> List<Map<K,T>> transposeColumnsToRows(Map<K,? extends Collection<T>> columns)
      Transposes Map<K, ? extends Collection<T>> into List<Map<K, T>>.

      Each map entry is treated as a column. Row i contains the i-th element from every column (by iteration order within each collection). Columns shorter than the longest column are padded with null.

      Type Parameters:
      K - column key type
      T - cell value type
      Parameters:
      columns - column key to values; null or empty yields an empty list
      Returns:
      one map per row; keys are column keys and iteration order follows columns
    • transposeRowsToColumns

      public static <K, T> Map<K,Set<T>> transposeRowsToColumns(List<Map<K,T>> rows)
      Transposes List<Map<K, T>> into Map<K, Set<T>>.

      Each distinct column key collects non-null cell values in row order. null rows are skipped.

      Type Parameters:
      K - column key type
      T - cell value type
      Parameters:
      rows - row maps; null or empty yields an empty map
      Returns:
      column key to ordered set of values