Class DataColumn<T>

java.lang.Object
com.github.martincooper.datatable.DataColumn<T>
All Implemented Interfaces:
IDataColumn, IModifiable<Integer,Object,IDataColumn>, IModifiableByIndex<Object,IDataColumn>

public class DataColumn<T> extends Object implements IDataColumn
DataColumn. Handles the data for a single column. Created by Martin Cooper on 08/07/2017.
  • Constructor Details

    • DataColumn

      public DataColumn(Class<T> type, String columnName)
      DataColumn constructor.
      Parameters:
      type - Stores the type of data stored in this column.
      columnName - The column name.
    • DataColumn

      public DataColumn(Class<T> type, String columnName, T[] data)
      DataColumn constructor.
      Parameters:
      type - Stores the type of data stored in this column.
      columnName - The column name.
      data - The data items stored in the column.
    • DataColumn

      public DataColumn(Class<T> type, String columnName, Iterable<T> data)
      DataColumn constructor.
      Parameters:
      type - Stores the type of data stored in this column.
      columnName - The column name.
      data - The data items stored in the column.
    • DataColumn

      public DataColumn(Class<T> type, String columnName, io.vavr.collection.Vector<T> data)
      DataColumn constructor.
      Parameters:
      type - Stores the type of data stored in this column.
      columnName - The column name.
      data - The data items stored in the column.
  • Method Details

    • name

      public String name()
      Gets the column name.
      Specified by:
      name in interface IDataColumn
      Returns:
      Returns the column name.
    • type

      public Type type()
      Gets the column type.
      Specified by:
      type in interface IDataColumn
      Returns:
      Returns the column type.
    • data

      public io.vavr.collection.Vector<T> data()
      Returns the underlying data.
      Specified by:
      data in interface IDataColumn
      Returns:
      Returns access to the underlying data.
    • valueAt

      public T valueAt(Integer rowIndex)
      Returns the value at the specified index.
      Specified by:
      valueAt in interface IDataColumn
      Parameters:
      rowIndex - The row index.
      Returns:
      Returns the value.
    • asType

      public <V> io.vavr.control.Try<DataColumn<V>> asType(Class<V> type)
      Returns the generic data column as it's typed implementation. If the types don't match, then it'll return Failure.
      Specified by:
      asType in interface IDataColumn
      Type Parameters:
      V - The type.
      Parameters:
      type - The type of the column.
      Returns:
      Returns the typed Data Column wrapped in a Try.
    • buildFromRows

      public io.vavr.control.Try<IDataColumn> buildFromRows(io.vavr.collection.Seq<Integer> rowIndexes)
      Builds a new DataColumn from the data at the specified row indexes.
      Specified by:
      buildFromRows in interface IDataColumn
      Parameters:
      rowIndexes - The rows which the new column data is to be built from.
      Returns:
      Returns a new IDataColumn with just the rows specified.
    • add

      public io.vavr.control.Try<IDataColumn> add(Object value)
      Attempts to add / append a new item to the end of the column. A type check is performed before addition.
      Specified by:
      add in interface IModifiable<Integer,Object,IDataColumn>
      Parameters:
      value - The item required to be added.
      Returns:
      Returns a Success with the new modified DataColumn, or a Failure.
    • insert

      public io.vavr.control.Try<IDataColumn> insert(Integer index, Object value)
      Attempts to insert a new item into the column. A type check is performed before insertion.
      Specified by:
      insert in interface IModifiable<Integer,Object,IDataColumn>
      Parameters:
      index - The index the item is to be inserted at.
      value - The item required to be inserted.
      Returns:
      Returns a Success with the new modified DataColumn, or a Failure.
    • replace

      public io.vavr.control.Try<IDataColumn> replace(Integer index, Object value)
      Attempts to replace an existing item with a new item in the column. A type check is performed before replacement.
      Specified by:
      replace in interface IModifiable<Integer,Object,IDataColumn>
      Parameters:
      index - The index the item is to be replaced at.
      value - The new item.
      Returns:
      Returns a Success with the new modified DataColumn, or a Failure.
    • remove

      public io.vavr.control.Try<IDataColumn> remove(Integer index)
      Attempts to remove an existing item at the specified index.
      Specified by:
      remove in interface IModifiable<Integer,Object,IDataColumn>
      Parameters:
      index - The index to remove the item at.
      Returns:
      Returns a Success with the new modified DataColumn, or a Failure.
    • addItem

      public io.vavr.control.Try<DataColumn<T>> addItem(T value)
      Adds / Appends and item to the end of the column.
      Parameters:
      value - The value to append.
      Returns:
      Returns a new DataColumn with the new item appended.
    • insertItem

      public io.vavr.control.Try<DataColumn<T>> insertItem(Integer index, T value)
      Inserts the item at the specified index.
      Parameters:
      index - The index to insert the item at.
      value - The item to insert.
      Returns:
      Returns a new DataColumn with the new item inserted.
    • replaceItem

      public io.vavr.control.Try<DataColumn<T>> replaceItem(Integer index, T value)
      Replaces the existing item at the specified index with the new item.
      Parameters:
      index - The index to replace the existing item.
      value - The new item to replace the existing one.
      Returns:
      Returns a new DataColumn with the specified item replaced.
    • removeItem

      public io.vavr.control.Try<DataColumn<T>> removeItem(Integer index)
      Removes the item at the specified index.
      Parameters:
      index - The index to remove the item at.
      Returns:
      Returns a new DataColumn with the specified item removed.
    • IsComparable

      public boolean IsComparable()
      Checks if the data column supports comparable for sorting.
      Specified by:
      IsComparable in interface IDataColumn
      Returns:
      Returns true if the type supports Comparable.