Package tech.tablesaw.api
Class DateTimeColumn
- java.lang.Object
-
- tech.tablesaw.columns.AbstractColumn<DateTimeColumn,LocalDateTime>
-
- tech.tablesaw.api.DateTimeColumn
-
- All Implemented Interfaces:
Iterable<LocalDateTime>
,Comparator<LocalDateTime>
,CategoricalColumn<LocalDateTime>
,Column<LocalDateTime>
,DateTimeFilters
,DateTimeMapFunctions
,TemporalColumn<LocalDateTime>
,TemporalFillers<LocalDateTime,DateTimeColumn>
,TemporalFilters<LocalDateTime>
,TemporalMapFunctions<LocalDateTime>
,DateAndDateTimeFilterSpec<Selection>
,DateTimeFilterSpec<Selection>
,FilterSpec<Selection>
,InstantFilterSpec<Selection>
,TimeAndDateTimeFilterSpec<Selection>
public class DateTimeColumn extends AbstractColumn<DateTimeColumn,LocalDateTime> implements DateTimeMapFunctions, DateTimeFilters, TemporalFillers<LocalDateTime,DateTimeColumn>, CategoricalColumn<LocalDateTime>
A column that contains long-integer encoded (packed) local date-time values
-
-
Field Summary
Fields Modifier and Type Field Description protected it.unimi.dsi.fastutil.longs.LongArrayList
data
The dateTime values held in this column, in theirPackedLocalDateTime
format-
Fields inherited from class tech.tablesaw.columns.AbstractColumn
DEFAULT_ARRAY_SIZE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DateTimeColumn
append(LocalDateTime dateTime)
Appends value to the bottom of this column and return this columnDateTimeColumn
append(Column<LocalDateTime> column)
Appends all the values in the argument to the bottom of this column and return this columnDateTimeColumn
append(Column<LocalDateTime> column, int row)
Appends the value at the given row in the given column to the bottom of this column and return this columnDateTimeColumn
appendCell(String stringValue)
Add one element to the bottom of this column and set its value to the parsed value of the given String.DateTimeColumn
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 parserDateTimeColumn
appendInternal(long dateTime)
Returns this column with the argument appended at the bottomDateTimeColumn
appendMissing()
Appends a missing value appropriate to the columnDateTimeColumn
appendObj(Object obj)
Appends the given value to the bottom of this column and return this columnbyte[]
asBytes(int rowNumber)
Returns the contents of the cell at rowNumber as a byte[]double[]
asDoubleArray()
DoubleColumn
asDoubleColumn()
long[]
asEpochMillisArray()
Returns an array where each entry is the difference, measured in milliseconds, between the LocalDateTime and midnight, January 1, 1970 UTC.long[]
asEpochMillisArray(ZoneOffset offset)
Returns an array where each entry is the difference, measured in milliseconds, between the LocalDateTime and midnight, January 1, 1970 UTC.long[]
asEpochSecondArray()
Returns an array where each entry is the difference, measured in seconds, between the LocalDateTime and midnight, January 1, 1970 UTC.long[]
asEpochSecondArray(ZoneOffset offset)
Returns the seconds from epoch for each value as an array based on the given offsetInstantColumn
asInstantColumn()
InstantColumn
asInstantColumn(ZoneId zone)
LocalDateTime[]
asObjectArray()
Returns an array of objects as appropriate for my type of columnSet<LocalDateTime>
asSet()
Returns a Set containing all the unique values in this columnList<LocalDateTime>
bottom(int n)
Returns the smallest ("bottom") n values in the columnint
byteSize()
Returns the width of a cell in this column, in bytes.void
clear()
Removes all elements TODO: Make this return this columnint
compare(LocalDateTime o1, LocalDateTime o2)
boolean
contains(LocalDateTime dateTime)
Returnstrue
if the given object appears in this column, and false otherwiseDateTimeColumn
copy()
Returns a deep copy of the receiverint
countMissing()
Returns the count of missing values in this columnint
countUnique()
Returns the count of unique values in this column.static DateTimeColumn
create(String name)
static DateTimeColumn
create(String name, int initialSize)
static DateTimeColumn
create(String name, LocalDateTime... data)
static DateTimeColumn
create(String name, Collection<LocalDateTime> data)
static DateTimeColumn
create(String name, Stream<LocalDateTime> stream)
static DateTimeColumn
createInternal(String name, long[] longs)
For internal Tablesaw use only Returns a new column with the given name and dataDateTimeColumn
emptyCopy()
Returns a copy of the receiver with no data.DateTimeColumn
emptyCopy(int rowSize)
Returns an empty copy of the receiver, with its internal storage initialized to the given row size.boolean
equals(int rowNumber1, int rowNumber2)
Returns true if the value in this column at rowNumber1 is equal to the value at rowNumber2DateTimeColumn
fillWith(Iterable<LocalDateTime> iterable)
DateTimeColumn
fillWith(Supplier<LocalDateTime> supplier)
DateTimeColumn
fillWith(Iterator<LocalDateTime> iterator)
LocalDateTime
get(int index)
Returns a value of the Object type stored in the column (e.g.double
getDouble(int i)
long
getLongInternal(int index)
Returns the internal (long-encoded) value stored in the column at the given rowprotected long
getPackedDateTime(int index)
String
getString(int row)
Returns a string representation of the value at the given row.String
getUnformattedString(int row)
Returns a String representation of the value at index r, without any formatting appliedboolean
isEmpty()
Returns true if the column has no databoolean
isMissing(int rowNumber)
Returns true if the value at rowNumber is missingIterator<LocalDateTime>
iterator()
Returns an iterator over elements of typeT
.DateTimeColumn
lag(int n)
Returns a column of the same type and size as the receiver, containing the receivers values offset by n.it.unimi.dsi.fastutil.longs.LongIterator
longIterator()
LocalDateTime
max()
LocalDateTime
min()
DateTimeColumn
plus(long amountToAdd, ChronoUnit unit)
DateTimeColumn
removeMissing()
Returns a copy of this column with the missing values removedit.unimi.dsi.fastutil.ints.IntComparator
rowComparator()
Returns an IntComparator for sorting my rowsDateTimeColumn
set(int index, long value)
DateTimeColumn
set(int index, LocalDateTime value)
Sets the value at index row to the given value and return this columnDateTimeColumn
set(int row, Column<LocalDateTime> column, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this columnDateTimeColumn
set(Selection rowSelection, LocalDateTime newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaDateTimeColumn
setMissing(int i)
Sets the value at index i to the missing-value indicator for this column type, and return this columnvoid
setPrintFormatter(DateTimeFormatter dateTimeFormatter)
void
setPrintFormatter(DateTimeFormatter dateTimeFormatter, String missingValueString)
void
setPrintFormatter(DateTimeColumnFormatter formatter)
int
size()
Returns the number of elements in this column, including missing valuesvoid
sortAscending()
Sorts my values in ascending ordervoid
sortDescending()
Sorts my values in descending orderDateTimeColumn
subset(int[] rows)
Return a column of the same type containing just those elements whose indexes are included in the given arrayTable
summary()
Returns a table containing a ColumnType specific summary of the data in this columnList<LocalDateTime>
top(int n)
Returns the largest ("top") n values in the columnDateTimeColumn
unique()
Returns a column of the same type containing only the unique valuesint
valueHash(int rowNumber)
Returns an int suitable as a hash for the value in this column at the given indexstatic boolean
valueIsMissing(long value)
DateTimeColumn
where(Selection selection)
Returns a new column containing the subset referenced by theSelection
-
Methods inherited from class tech.tablesaw.columns.AbstractColumn
asStringColumn, filter, first, indexOf, inRange, last, lastIndexOf, map, max, min, name, parser, sampleN, sampleX, set, setName, setParser, sorted, toString, type
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface tech.tablesaw.api.CategoricalColumn
countByCategory
-
Methods inherited from interface tech.tablesaw.columns.Column
allMatch, anyMatch, asList, asStringColumn, columnWidth, count, count, filter, first, indexOf, inRange, interpolate, last, lastIndexOf, map, map, mapInto, max, max, min, min, name, noneMatch, parser, print, reduce, reduce, rolling, sampleN, sampleX, set, set, set, setMissingTo, setName, setParser, sorted, title, type
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from interface tech.tablesaw.columns.datetimes.DateTimeFilters
isAfter, isAfter, isAfter, isAfterNoon, isBefore, isBefore, isBefore, isBeforeNoon, isBetweenExcluding, isBetweenIncluding, isEqualTo, isEqualTo, isFirstDayOfMonth, isFriday, isInApril, isInAugust, isInDecember, isInFebruary, isInJanuary, isInJuly, isInJune, isInMarch, isInMay, isInNovember, isInOctober, isInQ1, isInQ2, isInQ3, isInQ4, isInSeptember, isInYear, isLastDayOfMonth, isMidnight, isMissing, isMonday, isNoon, isNotEqualTo, isNotEqualTo, isNotMissing, isOnOrAfter, isOnOrAfter, isOnOrAfter, isOnOrBefore, isOnOrBefore, isOnOrBefore, isSaturday, isSunday, isThursday, isTuesday, isWednesday
-
Methods inherited from interface tech.tablesaw.columns.datetimes.DateTimeMapFunctions
date, dayOfMonth, dayOfWeek, dayOfWeekValue, dayOfYear, hour, hourMinute, lead, minute, minuteOfDay, month, monthValue, plusDays, plusHours, plusMicros, plusMillis, plusMinutes, plusMonths, plusSeconds, plusWeeks, plusYears, secondOfDay, time, timeWindow, timeWindow, year, yearDay, yearMonth, yearQuarter, yearWeek
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface tech.tablesaw.columns.temporal.TemporalFilters
eval, eval, eval, eval, eval, isAfter, isBefore, isBetweenExcluding, isBetweenIncluding, isEqualTo
-
Methods inherited from interface tech.tablesaw.columns.temporal.TemporalMapFunctions
difference, differenceInDays, differenceInHours, differenceInMilliseconds, differenceInMinutes, differenceInSeconds, differenceInYears, missingValues, temporalColumnName
-
-
-
-
Field Detail
-
data
protected it.unimi.dsi.fastutil.longs.LongArrayList data
The dateTime values held in this column, in theirPackedLocalDateTime
format
-
-
Method Detail
-
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 interfaceColumn<LocalDateTime>
-
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 interfaceColumn<LocalDateTime>
-
createInternal
public static DateTimeColumn createInternal(String name, long[] longs)
For internal Tablesaw use only Returns a new column with the given name and data- Parameters:
name
- The column namelongs
- An array of longs representing datetime values in Tablesaw internal format
-
create
public static DateTimeColumn create(String name)
-
create
public static DateTimeColumn create(String name, int initialSize)
-
create
public static DateTimeColumn create(String name, Collection<LocalDateTime> data)
-
create
public static DateTimeColumn create(String name, Stream<LocalDateTime> stream)
-
plus
public DateTimeColumn plus(long amountToAdd, ChronoUnit unit)
- Specified by:
plus
in interfaceDateTimeMapFunctions
- Specified by:
plus
in interfaceTemporalMapFunctions<LocalDateTime>
-
create
public static DateTimeColumn create(String name, LocalDateTime... data)
-
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 interfaceColumn<LocalDateTime>
-
subset
public DateTimeColumn 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 interfaceColumn<LocalDateTime>
- Overrides:
subset
in classAbstractColumn<DateTimeColumn,LocalDateTime>
-
removeMissing
public DateTimeColumn removeMissing()
Returns a copy of this column with the missing values removed- Specified by:
removeMissing
in interfaceColumn<LocalDateTime>
-
contains
public boolean contains(LocalDateTime dateTime)
Returnstrue
if the given object appears in this column, and false otherwiseTODO override in column subtypes for performance
- Specified by:
contains
in interfaceColumn<LocalDateTime>
-
setMissing
public DateTimeColumn 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 interfaceColumn<LocalDateTime>
-
where
public DateTimeColumn where(Selection selection)
Returns a new column containing the subset referenced by theSelection
- Specified by:
where
in interfaceColumn<LocalDateTime>
-
setPrintFormatter
public void setPrintFormatter(DateTimeFormatter dateTimeFormatter, String missingValueString)
-
setPrintFormatter
public void setPrintFormatter(DateTimeFormatter dateTimeFormatter)
-
setPrintFormatter
public void setPrintFormatter(DateTimeColumnFormatter formatter)
-
lag
public DateTimeColumn 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 interfaceColumn<LocalDateTime>
- Specified by:
lag
in interfaceDateTimeMapFunctions
-
appendCell
public DateTimeColumn 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 interfaceColumn<LocalDateTime>
-
appendCell
public DateTimeColumn 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 interfaceColumn<LocalDateTime>
-
append
public DateTimeColumn append(LocalDateTime dateTime)
Appends value to the bottom of this column and return this column- Specified by:
append
in interfaceColumn<LocalDateTime>
-
appendObj
public DateTimeColumn appendObj(Object obj)
Appends the given value to the bottom of this column and return this column- Specified by:
appendObj
in interfaceColumn<LocalDateTime>
-
size
public int size()
Returns the number of elements in this column, including missing values- Specified by:
size
in interfaceColumn<LocalDateTime>
- Specified by:
size
in interfaceTemporalFilters<LocalDateTime>
-
appendInternal
public DateTimeColumn appendInternal(long dateTime)
Returns this column with the argument appended at the bottom- Specified by:
appendInternal
in interfaceTemporalColumn<LocalDateTime>
-
getString
public String getString(int row)
Returns a string representation of the value at the given row.- Specified by:
getString
in interfaceColumn<LocalDateTime>
- 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 interfaceColumn<LocalDateTime>
-
emptyCopy
public DateTimeColumn emptyCopy()
Returns a copy of the receiver with no data. The column name and type are the same.- Specified by:
emptyCopy
in interfaceColumn<LocalDateTime>
- Specified by:
emptyCopy
in interfaceTemporalMapFunctions<LocalDateTime>
- Specified by:
emptyCopy
in classAbstractColumn<DateTimeColumn,LocalDateTime>
- Returns:
- a empty copy of
Column
-
emptyCopy
public DateTimeColumn emptyCopy(int rowSize)
Returns an empty copy of the receiver, with its internal storage initialized to the given row size.- Specified by:
emptyCopy
in interfaceColumn<LocalDateTime>
- Parameters:
rowSize
- the initial row size- Returns:
- a
Column
-
copy
public DateTimeColumn copy()
Returns a deep copy of the receiver- Specified by:
copy
in interfaceColumn<LocalDateTime>
- Returns:
- a
Column
-
clear
public void clear()
Removes all elements TODO: Make this return this column- Specified by:
clear
in interfaceColumn<LocalDateTime>
-
sortAscending
public void sortAscending()
Sorts my values in ascending order- Specified by:
sortAscending
in interfaceColumn<LocalDateTime>
-
sortDescending
public void sortDescending()
Sorts my values in descending order- Specified by:
sortDescending
in interfaceColumn<LocalDateTime>
-
summary
public Table summary()
Returns a table containing a ColumnType specific summary of the data in this column- Specified by:
summary
in interfaceColumn<LocalDateTime>
-
countUnique
public int countUnique()
Returns the count of unique values in this column.- Specified by:
countUnique
in interfaceColumn<LocalDateTime>
- Returns:
- unique values as int
-
unique
public DateTimeColumn unique()
Returns a column of the same type containing only the unique values- Specified by:
unique
in interfaceColumn<LocalDateTime>
- Returns:
- a
Column
-
isEmpty
public boolean isEmpty()
Returns true if the column has no data- Specified by:
isEmpty
in interfaceColumn<LocalDateTime>
- 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 interfaceTemporalColumn<LocalDateTime>
- Specified by:
getLongInternal
in interfaceTemporalFilters<LocalDateTime>
-
getPackedDateTime
protected long getPackedDateTime(int index)
-
get
public LocalDateTime 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 interfaceColumn<LocalDateTime>
- Specified by:
get
in interfaceTemporalColumn<LocalDateTime>
- Specified by:
get
in interfaceTemporalFilters<LocalDateTime>
-
rowComparator
public it.unimi.dsi.fastutil.ints.IntComparator rowComparator()
Returns an IntComparator for sorting my rows- Specified by:
rowComparator
in interfaceColumn<LocalDateTime>
-
set
public DateTimeColumn set(Selection rowSelection, LocalDateTime newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaExample: myColumn.set(myColumn.valueIsMissing(), LocalDateTime.now()); // no more missing values
- Specified by:
set
in interfaceColumn<LocalDateTime>
- Overrides:
set
in classAbstractColumn<DateTimeColumn,LocalDateTime>
-
countMissing
public int countMissing()
Returns the count of missing values in this column- Specified by:
countMissing
in interfaceColumn<LocalDateTime>
- Returns:
- missing values as int
-
asEpochSecondArray
public long[] asEpochSecondArray()
Returns an array where each entry is the difference, measured in seconds, between the LocalDateTime and midnight, January 1, 1970 UTC.If a value is missing, DateTimeColumnType.missingValueIndicator() is used
-
asEpochSecondArray
public long[] asEpochSecondArray(ZoneOffset offset)
Returns the seconds from epoch for each value as an array based on the given offsetIf a value is missing, DateTimeColumnType.missingValueIndicator() is used
-
asEpochMillisArray
public long[] asEpochMillisArray()
Returns an array where each entry is the difference, measured in milliseconds, between the LocalDateTime and midnight, January 1, 1970 UTC.If a missing value is encountered, DateTimeColumnType.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 LocalDateTime and midnight, January 1, 1970 UTC.If a missing value is encountered, DateTimeColumnType.missingValueIndicator() is inserted in the array
-
asInstantColumn
public InstantColumn asInstantColumn()
-
asInstantColumn
public InstantColumn asInstantColumn(ZoneId zone)
-
append
public DateTimeColumn append(Column<LocalDateTime> column)
Appends all the values in the argument to the bottom of this column and return this column- Specified by:
append
in interfaceColumn<LocalDateTime>
-
append
public DateTimeColumn append(Column<LocalDateTime> 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 interfaceColumn<LocalDateTime>
-
set
public DateTimeColumn set(int row, Column<LocalDateTime> 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 interfaceColumn<LocalDateTime>
-
max
public LocalDateTime max()
-
appendMissing
public DateTimeColumn appendMissing()
Appends a missing value appropriate to the column- Specified by:
appendMissing
in interfaceColumn<LocalDateTime>
-
min
public LocalDateTime min()
- Specified by:
min
in interfaceTemporalMapFunctions<LocalDateTime>
-
set
public DateTimeColumn set(int index, long value)
-
set
public DateTimeColumn set(int index, LocalDateTime value)
Sets the value at index row to the given value and return this column- Specified by:
set
in interfaceColumn<LocalDateTime>
-
top
public List<LocalDateTime> 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<LocalDateTime> 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()
-
asSet
public Set<LocalDateTime> asSet()
Description copied from interface:Column
Returns a Set containing all the unique values in this column- Specified by:
asSet
in interfaceColumn<LocalDateTime>
-
byteSize
public int byteSize()
Returns the width of a cell in this column, in bytes.- Specified by:
byteSize
in interfaceColumn<LocalDateTime>
- 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 interfaceColumn<LocalDateTime>
- 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<LocalDateTime> iterator()
Returns an iterator over elements of typeT
.- Specified by:
iterator
in interfaceIterable<LocalDateTime>
- Returns:
- an Iterator.
-
fillWith
public DateTimeColumn fillWith(Iterator<LocalDateTime> iterator)
- Specified by:
fillWith
in interfaceTemporalFillers<LocalDateTime,DateTimeColumn>
-
fillWith
public DateTimeColumn fillWith(Iterable<LocalDateTime> iterable)
- Specified by:
fillWith
in interfaceTemporalFillers<LocalDateTime,DateTimeColumn>
-
fillWith
public DateTimeColumn fillWith(Supplier<LocalDateTime> supplier)
- Specified by:
fillWith
in interfaceTemporalFillers<LocalDateTime,DateTimeColumn>
-
asObjectArray
public LocalDateTime[] asObjectArray()
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArray
in interfaceColumn<LocalDateTime>
-
compare
public int compare(LocalDateTime o1, LocalDateTime o2)
- Specified by:
compare
in interfaceComparator<LocalDateTime>
-
-