Class Columns

java.lang.Object
app.babylon.table.column.Columns

public class Columns extends Object
Utility methods for common column construction, conversion, aggregation, and reshaping operations.
  • Method Details

    • isStringColumn

      public static boolean isStringColumn(Column column)
      Returns whether the column stores strings.
      Parameters:
      column - column to inspect
      Returns:
      true when the column is a string object column
    • asStringColumn

      public static ColumnObject<String> asStringColumn(Column column)
      Casts a generic column to a string column.
      Parameters:
      column - column to cast
      Returns:
      string column view
    • frequencyMap

      public static <T> Map<T,Integer> frequencyMap(ColumnObject<T> c)
      Builds a frequency map of set values in an object column.
      Type Parameters:
      T - value type
      Parameters:
      c - source column
      Returns:
      value frequency map
    • stringToType

      public static <S> ColumnObject<S> stringToType(Column column, Function<String,S> parser, Column.Type targetType)
      Converts a string column to another object type using the supplied parser.
      Type Parameters:
      S - target value type
      Parameters:
      column - source column
      parser - string parser
      targetType - target type
      Returns:
      converted column or null
    • stringToDecimal

      public static ColumnObject<BigDecimal> stringToDecimal(Column column)
      Converts a string column to decimals.
      Parameters:
      column - source column
      Returns:
      decimal column or null
    • isEmpty

      public static boolean isEmpty(Column column)
      Returns whether the column has no rows.
      Parameters:
      column - column to inspect
      Returns:
      true when empty
    • newColumn

      public static Column.Builder newColumn(ColumnName colName)
      Creates a default string column builder.
      Parameters:
      colName - column name
      Returns:
      new builder
    • newBuilder

      public static Column.Builder newBuilder(ColumnName colName, Column.Type type)
      Creates a builder suitable for the supplied type.
      Parameters:
      colName - column name
      type - target type
      Returns:
      new builder
    • newDecimal

      public static ColumnObject<BigDecimal> newDecimal(ColumnName colName, BigDecimal value, int size)
      Creates a constant decimal column.
      Parameters:
      colName - column name
      value - constant value
      size - row count
      Returns:
      constant decimal column
    • decimalPlaces

      public static int decimalPlaces(ColumnObject<BigDecimal> column)
      Returns the largest non-negative scale found in a decimal column.
      Parameters:
      column - decimal column to inspect
      Returns:
      maximum decimal places across set values
    • newInt

      public static ColumnInt newInt(ColumnName colName, int value, int size)
      Creates a constant int column.
    • newLong

      public static ColumnLong newLong(ColumnName colName, long value, int size)
      Creates a constant long column.
    • newBoolean

      public static ColumnBoolean newBoolean(ColumnName colName, boolean value, int size)
      Creates a constant boolean column.
    • newByte

      public static ColumnByte newByte(ColumnName colName, byte value, int size)
      Creates a constant byte column.
    • newString

      public static ColumnObject<String> newString(ColumnName colName, String value, int size)
      Creates a constant string column.
    • newCategorical

      public static <T> ColumnCategorical<T> newCategorical(ColumnName colName, T value, int size, Column.Type type)
      Creates a constant categorical column.
    • aggregate

      public static BigDecimal aggregate(ColumnObject<BigDecimal> cd, Aggregate aggregate)
      Computes an aggregate over a decimal column.
    • max

      public static <T> T max(ColumnObject<T> co)
      Returns the maximum set value in an object column.
    • min

      public static <T> T min(ColumnObject<T> co)
      Returns the minimum set value in an object column.
    • aggregate

      public static double aggregate(ColumnDouble cd, Aggregate aggregate)
      Computes an aggregate over a double column.
    • newDouble

      public static ColumnDouble newDouble(ColumnName colName, double value, int size)
      Creates a constant double column.
    • newView

      public static <T extends Enum<T>> Column newView(Column c, ViewIndex rowIndex)
      Returns a row view of the supplied column.
    • sort

      public static Column sort(Column column)
      Returns a sorted view using the column's natural row comparison.
    • sort

      public static Column sort(Column column, ComparatorInt comparator)
      Returns a sorted view using the supplied row comparator.
    • newStringView

      public static ColumnObject<String> newStringView(ColumnObject<String> c, ViewIndex rowIndex)
      Returns a string-column view.
    • concat

      public static Column concat(List<Column> columns)
      Concatenates multiple columns of the same logical type.
    • toString

      public static String toString(Column column)
      Returns a short preview string for a column.