Class InstantColumn

All Implemented Interfaces:
Iterable<Instant>, Comparator<Instant>, CategoricalColumn<Instant>, Column<Instant>, TemporalColumn<Instant>, TemporalFillers<Instant,InstantColumn>, TemporalFilters<Instant>, TemporalMapFunctions<InstantColumn,Instant>, FilterSpec<Selection>, InstantFilterSpec<Selection>

A column that contains long-integer encoded (packed) instant values. An instant is a unique point of time on the timeline. The instants held by Instant column have millisecond precision, unlike instances of Instant, which have nanosecond precision
  • Field Details

    • data

      protected it.unimi.dsi.fastutil.longs.LongArrayList data
  • Method Details

    • valueHash

      public int valueHash(int rowNumber)
      Returns an int suitable as a hash for the value in this column at the given index
      Specified by:
      valueHash in interface Column<Instant>
    • equals

      public boolean equals(int rowNumber1, int rowNumber2)
      Returns true if the value in this column at rowNumber1 is equal to the value at rowNumber2
      Specified by:
      equals in interface Column<Instant>
    • create

      public static InstantColumn create(String name)
    • createInternal

      public static InstantColumn createInternal(String name, long[] data)
      For internal Tablesaw use only Returns a new column with the given name and data
      Parameters:
      name - The column name
      data - An array of longs representing Instant values in Tablesaw internal format
    • create

      public static InstantColumn create(String name, int initialSize)
    • create

      public static InstantColumn create(String name, Collection<Instant> data)
    • create

      public static InstantColumn create(String name, Instant... data)
    • create

      public static InstantColumn create(String name, Stream<Instant> stream)
    • valueIsMissing

      public static boolean valueIsMissing(long value)
    • isMissing

      public boolean isMissing(int rowNumber)
      Returns true if the value at rowNumber is missing
      Specified by:
      isMissing in interface Column<Instant>
    • plus

      public InstantColumn plus(long amountToAdd, ChronoUnit unit)
      Specified by:
      plus in interface TemporalMapFunctions<InstantColumn,Instant>
    • subset

      public InstantColumn subset(int[] rows)
      Return a column of the same type containing just those elements whose indexes are included in the given array
      Specified by:
      subset in interface Column<Instant>
      Overrides:
      subset in class AbstractColumn<InstantColumn,Instant>
    • removeMissing

      public InstantColumn removeMissing()
      Returns a copy of this column with the missing values removed
      Specified by:
      removeMissing in interface Column<Instant>
    • contains

      public boolean contains(Instant dateTime)
      Returns true if the given object appears in this column, and false otherwise

      TODO override in column subtypes for performance

      Specified by:
      contains in interface Column<Instant>
    • setMissing

      public InstantColumn setMissing(int i)
      Sets the value at index i to the missing-value indicator for this column type, and return this column
      Specified by:
      setMissing in interface Column<Instant>
    • where

      public InstantColumn where(Selection selection)
      Returns a new column containing the subset referenced by the Selection
      Specified by:
      where in interface Column<Instant>
    • setPrintFormatter

      public void setPrintFormatter(InstantColumnFormatter formatter)
      Sets the print formatter to the argument. The print formatter is used in pretty-printing and optionally for writing to text files like CSVs
    • lag

      public InstantColumn lag(int n)
      Returns a column of the same type and size as the receiver, containing the receivers values offset by n.

      For example if you lag a column containing 2, 3, 4 by 1, you get a column containing NA, 2, 3

      Specified by:
      lag in interface Column<Instant>
      Specified by:
      lag in interface TemporalMapFunctions<InstantColumn,Instant>
    • appendCell

      public InstantColumn appendCell(String stringValue)
      Add one element to the bottom of this column and set its value to the parsed value of the given String. Parsing is type-specific
      Specified by:
      appendCell in interface Column<Instant>
    • appendCell

      public InstantColumn appendCell(String stringValue, AbstractColumnParser<?> parser)
      Add one element to the bottom of this column and set its value to the parsed value of the given String, as performed by the given parser
      Specified by:
      appendCell in interface Column<Instant>
    • append

      public InstantColumn append(Instant dateTime)
      Appends value to the bottom of this column and return this column
      Specified by:
      append in interface Column<Instant>
    • appendObj

      public InstantColumn appendObj(Object obj)
      Appends the given value to the bottom of this column and return this column
      Specified by:
      appendObj in interface Column<Instant>
    • size

      public int size()
      Returns the number of elements in this column, including missing values
      Specified by:
      size in interface Column<Instant>
      Specified by:
      size in interface TemporalFilters<Instant>
    • appendInternal

      public InstantColumn appendInternal(long dateTime)
      Returns this column with the argument appended at the bottom
      Specified by:
      appendInternal in interface TemporalColumn<Instant>
    • getString

      public String getString(int row)
      Returns a string representation of the value at the given row.
      Specified by:
      getString in interface Column<Instant>
      Parameters:
      row - The index of the row.
      Returns:
      value as String
    • getUnformattedString

      public String getUnformattedString(int row)
      Returns a String representation of the value at index r, without any formatting applied
      Specified by:
      getUnformattedString in interface Column<Instant>
    • emptyCopy

      public InstantColumn emptyCopy()
      Returns a copy of the receiver with no data. The column name and type are the same.
      Specified by:
      emptyCopy in interface Column<Instant>
      Specified by:
      emptyCopy in interface TemporalMapFunctions<InstantColumn,Instant>
      Returns:
      a empty copy of Column
    • emptyCopy

      public InstantColumn emptyCopy(int rowSize)
      Returns an empty copy of the receiver, with its internal storage initialized to the given row size.
      Specified by:
      emptyCopy in interface Column<Instant>
      Parameters:
      rowSize - the initial row size
      Returns:
      a Column
    • copy

      public InstantColumn copy()
      Returns a deep copy of the receiver
      Specified by:
      copy in interface Column<Instant>
      Returns:
      a Column
    • clear

      public void clear()
      Removes all elements TODO: Make this return this column
      Specified by:
      clear in interface Column<Instant>
    • sortAscending

      public void sortAscending()
      Sorts my values in ascending order
      Specified by:
      sortAscending in interface Column<Instant>
    • sortDescending

      public void sortDescending()
      Sorts my values in descending order
      Specified by:
      sortDescending in interface Column<Instant>
    • summary

      public Table summary()
      Returns a table containing a ColumnType specific summary of the data in this column
      Specified by:
      summary in interface Column<Instant>
    • countUnique

      public int countUnique()
      Returns the count of unique values in this column.
      Specified by:
      countUnique in interface Column<Instant>
      Returns:
      unique values as int
    • unique

      public InstantColumn unique()
      Returns a column of the same type containing only the unique values
      Specified by:
      unique in interface Column<Instant>
      Returns:
      a Column
    • isEmpty

      public boolean isEmpty()
      Returns true if the column has no data
      Specified by:
      isEmpty in interface Column<Instant>
      Returns:
      true if empty, false if not
    • getLongInternal

      public long getLongInternal(int index)
      Returns the internal (long-encoded) value stored in the column at the given row
      Specified by:
      getLongInternal in interface TemporalColumn<Instant>
      Specified by:
      getLongInternal in interface TemporalFilters<Instant>
    • getPackedInstant

      protected long getPackedInstant(int index)
      Returns the long-encoded version of the instant at the given index
    • get

      public Instant get(int index)
      Returns a value of the Object type stored in the column (e.g. a LocalDateTime) at the given row
      Specified by:
      get in interface Column<Instant>
      Specified by:
      get in interface TemporalColumn<Instant>
      Specified by:
      get in interface TemporalFilters<Instant>
    • rowComparator

      public it.unimi.dsi.fastutil.ints.IntComparator rowComparator()
      Returns an IntComparator for sorting my rows
      Specified by:
      rowComparator in interface Column<Instant>
    • set

      public InstantColumn set(Selection rowSelection, Instant newValue)
      Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria

      Example: myColumn.set(myColumn.valueIsMissing(), Instant.now()); // no more missing values

      Specified by:
      set in interface Column<Instant>
      Overrides:
      set in class AbstractColumn<InstantColumn,Instant>
    • countMissing

      public int countMissing()
      Returns the count of missing values in this column
      Specified by:
      countMissing in interface Column<Instant>
      Returns:
      missing values as int
    • asEpochSecondArray

      public long[] asEpochSecondArray()
      Returns an array where each entry is the difference, measured in seconds, between the Instant and midnight, January 1, 1970 UTC.

      If a value is missing, InstantColumnType.missingValueIndicator() is used

    • asEpochSecondArray

      public long[] asEpochSecondArray(ZoneOffset offset)
      Returns the seconds from epoch for each value as an array based on the given offset

      If a value is missing, InstantColumnType.missingValueIndicator() is used This method is only for consistency with DateTimeColumn, offset is not used

    • asEpochMillisArray

      public long[] asEpochMillisArray()
      Returns an array where each entry is the difference, measured in milliseconds, between the Instant and midnight, January 1, 1970 UTC.

      If a missing value is encountered, InstantColumnType.missingValueIndicator() is inserted in the array

    • asEpochMillisArray

      public long[] asEpochMillisArray(ZoneOffset offset)
      Returns an array where each entry is the difference, measured in milliseconds, between the Instant and midnight, January 1, 1970 UTC.

      If a missing value is encountered, InstantColumnType.missingValueIndicator() is inserted in the array This method is only for consistency with DateTimeColumn, offset is not used

    • asLocalDateTimeColumn

      public DateTimeColumn asLocalDateTimeColumn()
      Returns a DateTimeColumn where each element is a representation of the associated Instant translated using UTC as the timezone
    • asLocalDateTimeColumn

      public DateTimeColumn asLocalDateTimeColumn(ZoneId zone)
      Returns a DateTimeColumn where each element is a representation of the associated Instant translated using the argument as the timezone
    • append

      public InstantColumn append(Column<Instant> column)
      Appends all the values in the argument to the bottom of this column and return this column
      Specified by:
      append in interface Column<Instant>
    • append

      public InstantColumn append(Column<Instant> column, int row)
      Appends the value at the given row in the given column to the bottom of this column and return this column
      Specified by:
      append in interface Column<Instant>
    • set

      public InstantColumn set(int row, Column<Instant> column, int sourceRow)
      Sets the value at row to the value at sourceRow in the given column and return this column
      Specified by:
      set in interface Column<Instant>
    • max

      public Instant max()
      Returns the largest instant value in the column
    • appendMissing

      public InstantColumn appendMissing()
      Appends a missing value appropriate to the column
      Specified by:
      appendMissing in interface Column<Instant>
    • min

      public Instant min()
      Specified by:
      min in interface TemporalMapFunctions<InstantColumn,Instant>
    • set

      public InstantColumn set(int index, long value)
    • set

      public InstantColumn set(int index, Instant value)
      Sets the value at index row to the given value and return this column
      Specified by:
      set in interface Column<Instant>
    • top

      public List<Instant> top(int n)
      Returns the largest ("top") n values in the column
      Parameters:
      n - The maximum number of records to return. The actual number will be smaller if n is greater than the number of observations in the column
      Returns:
      A list, possibly empty, of the largest observations
    • bottom

      public List<Instant> bottom(int n)
      Returns the smallest ("bottom") n values in the column
      Parameters:
      n - The maximum number of records to return. The actual number will be smaller if n is greater than the number of observations in the column
      Returns:
      A list, possibly empty, of the smallest n observations
    • longIterator

      public it.unimi.dsi.fastutil.longs.LongIterator longIterator()
      Returns an iterator over the long representations of the instants in this column
    • asSet

      public Set<Instant> asSet()
      Returns a Set containing all the unique values in this column
      Specified by:
      asSet in interface Column<Instant>
    • byteSize

      public int byteSize()
      Returns the width of a cell in this column, in bytes.
      Specified by:
      byteSize in interface Column<Instant>
      Returns:
      width in bytes
    • asBytes

      public byte[] asBytes(int rowNumber)
      Returns the contents of the cell at rowNumber as a byte[]
      Specified by:
      asBytes in interface Column<Instant>
      Parameters:
      rowNumber - index of the row
      Returns:
      content as byte[]
    • getDouble

      public double getDouble(int i)
    • asDoubleArray

      public double[] asDoubleArray()
    • asDoubleColumn

      public DoubleColumn asDoubleColumn()
    • iterator

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

      public InstantColumn fillWith(Iterator<Instant> iterator)
      Specified by:
      fillWith in interface TemporalFillers<Instant,InstantColumn>
    • fillWith

      public InstantColumn fillWith(Iterable<Instant> iterable)
      Specified by:
      fillWith in interface TemporalFillers<Instant,InstantColumn>
    • fillWith

      public InstantColumn fillWith(Supplier<Instant> supplier)
      Specified by:
      fillWith in interface TemporalFillers<Instant,InstantColumn>
    • asObjectArray

      public Instant[] asObjectArray()
      Returns an array of objects as appropriate for my type of column
      Specified by:
      asObjectArray in interface Column<Instant>
    • compare

      public int compare(Instant o1, Instant o2)
      Specified by:
      compare in interface Comparator<Instant>
    • isMissing

      public Selection isMissing()
      Returns a selection containing an index for every missing value in this column
      Specified by:
      isMissing in interface Column<Instant>
      Specified by:
      isMissing in interface FilterSpec<Selection>
      Specified by:
      isMissing in interface TemporalFilters<Instant>
    • isNotMissing

      public Selection isNotMissing()
      Returns a selection containing an index for every non-missing value in this column
      Specified by:
      isNotMissing in interface Column<Instant>
      Specified by:
      isNotMissing in interface FilterSpec<Selection>
      Specified by:
      isNotMissing in interface TemporalFilters<Instant>