Class DataTable

java.lang.Object
com.github.martincooper.datatable.DataTable
All Implemented Interfaces:
IBaseTable, IQuickSort, Iterable<DataRow>

public class DataTable extends Object implements IBaseTable
DataTable class. Created by Martin Cooper on 08/07/2017.
  • Method Details

    • iterator

      public Iterator<DataRow> iterator()
      Returns an iterator over elements of type DataRow.
      Specified by:
      iterator in interface Iterable<DataRow>
      Returns:
      an Iterator.
    • name

      public String name()
      The name of the table.
      Specified by:
      name in interface IBaseTable
      Returns:
      Returns the table name.
    • columns

      public DataColumnCollection columns()
      The column collection.
      Specified by:
      columns in interface IBaseTable
      Returns:
      Returns the columns collection.
    • rows

      The row collection.
      Specified by:
      rows in interface IBaseTable
      Returns:
      Returns the row collection.
    • rowCount

      public Integer rowCount()
      Returns the rowCount / row count of the table.
      Specified by:
      rowCount in interface IBaseTable
      Returns:
      The row count of the table.
    • toDataTable

      public DataTable toDataTable()
      Return a new DataTable based on this table (clone).
      Specified by:
      toDataTable in interface IBaseTable
      Returns:
      Returns a clone of this DataTable.
    • toDataView

      public DataView toDataView()
      Return a new Data View based on this table.
      Specified by:
      toDataView in interface IBaseTable
      Returns:
      A new Data View based on this table.
    • filter

      public DataView filter(Predicate<DataRow> predicate)
      Filters the row data using the specified predicate, returning the results as a DataView over the original table.
      Parameters:
      predicate - The filter criteria.
      Returns:
      Returns a DataView with the filter results.
    • map

      public <U> io.vavr.collection.Seq<U> map(Function<? super DataRow,? extends U> mapper)
      Map operation across the Data Rows in the table.
      Type Parameters:
      U - The return type.
      Parameters:
      mapper - The mapper function.
      Returns:
      Returns the mapped results.
    • flatMap

      public <U> io.vavr.collection.Seq<U> flatMap(Function<? super DataRow,? extends Iterable<? extends U>> mapper)
      FlatMap implementation for the DataRowCollection class.
      Type Parameters:
      U - Mapped return type.
      Parameters:
      mapper - The map function.
      Returns:
      Returns a sequence of the applied flatMap.
    • reduce

      public DataRow reduce(BiFunction<? super DataRow,? super DataRow,? extends DataRow> reducer)
      Reduce implementation for the DataRowCollection class.
      Parameters:
      reducer - The reduce function.
      Returns:
      Returns a single, reduced DataRow.
    • groupBy

      public <C> io.vavr.collection.Map<C,io.vavr.collection.Vector<DataRow>> groupBy(Function<? super DataRow,? extends C> grouper)
      GroupBy implementation for the DataRowCollection class.
      Parameters:
      grouper - The group by function.
      Returns:
      Returns a map containing the grouped data.
    • foldLeft

      public <U> U foldLeft(U zero, BiFunction<? super U,? super DataRow,? extends U> folder)
      Fold Left implementation for the DataRowCollection class.
      Type Parameters:
      U - Fold return type.
      Parameters:
      folder - The fold function.
      Returns:
      Returns a single value of U.
    • foldRight

      public <U> U foldRight(U zero, BiFunction<? super DataRow,? super U,? extends U> folder)
      Fold Right implementation for the DataRowCollection class.
      Type Parameters:
      U - Fold return type.
      Parameters:
      folder - The fold function.
      Returns:
      Returns a single value of U.
    • row

      public DataRow row(Integer rowIdx)
      Accessor to a specific row by index.
      Specified by:
      row in interface IBaseTable
      Parameters:
      rowIdx - The index of the row to return.
      Returns:
      Returns a single row.
    • column

      public IDataColumn column(Integer colIdx)
      Accessor to a specific column by index.
      Parameters:
      colIdx - The index of the column to return.
      Returns:
      Returns a single column.
    • column

      public IDataColumn column(String colName)
      Accessor to a specific column by name.
      Parameters:
      colName - The name of the column to return.
      Returns:
      Returns a single column.
    • quickSort

      public io.vavr.control.Try<DataView> quickSort(String columnName)
      Table QuickSort by single column name.
      Specified by:
      quickSort in interface IQuickSort
      Parameters:
      columnName - The column name to sort.
      Returns:
      Returns the results as a sorted Data View.
    • quickSort

      public io.vavr.control.Try<DataView> quickSort(String columnName, SortOrder sortOrder)
      Table QuickSort by single column name and a sort order.
      Specified by:
      quickSort in interface IQuickSort
      Parameters:
      columnName - The column name to sort.
      sortOrder - The sort order.
      Returns:
      Returns the results as a sorted Data View.
    • quickSort

      public io.vavr.control.Try<DataView> quickSort(Integer columnIndex)
      Table QuickSort by single column index.
      Specified by:
      quickSort in interface IQuickSort
      Parameters:
      columnIndex - The column index to sort.
      Returns:
      Returns the results as a sorted Data View.
    • quickSort

      public io.vavr.control.Try<DataView> quickSort(Integer columnIndex, SortOrder sortOrder)
      Table QuickSort by single column index and a sort order.
      Specified by:
      quickSort in interface IQuickSort
      Parameters:
      columnIndex - The column index to sort.
      sortOrder - The sort order.
      Returns:
      Returns the results as a sorted Data View.
    • quickSort

      public io.vavr.control.Try<DataView> quickSort(SortItem sortItem)
      Table QuickSort by single sort item.
      Specified by:
      quickSort in interface IQuickSort
      Parameters:
      sortItem - The sort item.
      Returns:
      Returns the results as a sorted Data View.
    • quickSort

      public io.vavr.control.Try<DataView> quickSort(Iterable<SortItem> sortItems)
      Table QuickSort by multiple sort items.
      Specified by:
      quickSort in interface IQuickSort
      Parameters:
      sortItems - The sort items.
      Returns:
      Returns the results as a sorted Data View.
    • build

      public static DataTable build(String tableName)
      Builds an instance of a DataTable.
      Parameters:
      tableName - The name of the table.
      Returns:
      Returns an instance of a DataTable.
    • build

      public static io.vavr.control.Try<DataTable> build(String tableName, IDataColumn[] columns)
      Builds an instance of a DataTable. Columns are validated before creation, returning a Failure on error.
      Parameters:
      tableName - The name of the table.
      columns - The column collection.
      Returns:
      Returns a DataTable wrapped in a Try.
    • build

      public static io.vavr.control.Try<DataTable> build(String tableName, Iterable<IDataColumn> columns)
      Builds an instance of a DataTable. Columns are validated before creation, returning a Failure on error.
      Parameters:
      tableName - The name of the table.
      columns - The column collection.
      Returns:
      Returns a DataTable wrapped in a Try.
    • build

      public static io.vavr.control.Try<DataTable> build(String tableName, io.vavr.collection.Stream<IDataColumn> columns)
      Builds an instance of a DataTable. Columns are validated before creation, returning a Failure on error.
      Parameters:
      tableName - The name of the table.
      columns - The column collection.
      Returns:
      Returns a DataTable wrapped in a Try.