Package tech.tablesaw.api
Class InstantColumn
- java.lang.Object
-
- tech.tablesaw.columns.AbstractColumn<InstantColumn,Instant>
-
- tech.tablesaw.api.InstantColumn
-
- All Implemented Interfaces:
Iterable<Instant>
,Comparator<Instant>
,CategoricalColumn<Instant>
,Column<Instant>
,InstantMapFunctions
,TemporalColumn<Instant>
,TemporalFillers<Instant,InstantColumn>
,TemporalFilters<Instant>
,TemporalMapFunctions<Instant>
,FilterSpec<Selection>
,InstantFilterSpec<Selection>
public class InstantColumn extends AbstractColumn<InstantColumn,Instant> implements InstantMapFunctions, TemporalFillers<Instant,InstantColumn>, TemporalFilters<Instant>, CategoricalColumn<Instant>
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 ofInstant
, which have nanosecond precision
-
-
Field Summary
Fields Modifier and Type Field Description protected it.unimi.dsi.fastutil.longs.LongArrayList
data
-
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 InstantColumn
append(Instant dateTime)
Appends value to the bottom of this column and return this columnInstantColumn
append(Column<Instant> column)
Appends all the values in the argument to the bottom of this column and return this columnInstantColumn
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 columnInstantColumn
appendCell(String stringValue)
Add one element to the bottom of this column and set its value to the parsed value of the given String.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 parserInstantColumn
appendInternal(long dateTime)
Returns this column with the argument appended at the bottomInstantColumn
appendMissing()
Appends a missing value appropriate to the columnInstantColumn
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 Instant and midnight, January 1, 1970 UTC.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.long[]
asEpochSecondArray()
Returns an array where each entry is the difference, measured in seconds, between the Instant 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 offsetDateTimeColumn
asLocalDateTimeColumn()
Returns a DateTimeColumn where each element is a representation of the associated Instant translated using UTC as the timezoneDateTimeColumn
asLocalDateTimeColumn(ZoneId zone)
Returns a DateTimeColumn where each element is a representation of the associated Instant translated using the argument as the timezoneInstant[]
asObjectArray()
Returns an array of objects as appropriate for my type of columnSet<Instant>
asSet()
Returns a Set containing all the unique values in this columnList<Instant>
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(Instant o1, Instant o2)
boolean
contains(Instant dateTime)
Returnstrue
if the given object appears in this column, and false otherwiseInstantColumn
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 InstantColumn
create(String name)
static InstantColumn
create(String name, int initialSize)
static InstantColumn
create(String name, Instant... data)
static InstantColumn
create(String name, Collection<Instant> data)
static InstantColumn
create(String name, Stream<Instant> stream)
static InstantColumn
createInternal(String name, long[] data)
For internal Tablesaw use only Returns a new column with the given name and dataInstantColumn
emptyCopy()
Returns a copy of the receiver with no data.InstantColumn
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 rowNumber2InstantColumn
fillWith(Iterable<Instant> iterable)
InstantColumn
fillWith(Supplier<Instant> supplier)
InstantColumn
fillWith(Iterator<Instant> iterator)
Instant
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
getPackedInstant(int index)
Returns the long-encoded version of the instant at the given indexString
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 dataSelection
isMissing()
Returns a selection containing an index for every missing value in this columnboolean
isMissing(int rowNumber)
Returns true if the value at rowNumber is missingSelection
isNotMissing()
Returns a selection containing an index for every non-missing value in this columnIterator<Instant>
iterator()
Returns an iterator over elements of typeT
.InstantColumn
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()
Returns an iterator over the long representations of the instants in this columnInstant
max()
Returns the largest instant value in the columnInstant
min()
InstantColumn
plus(long amountToAdd, ChronoUnit unit)
InstantColumn
removeMissing()
Returns a copy of this column with the missing values removedit.unimi.dsi.fastutil.ints.IntComparator
rowComparator()
Returns an IntComparator for sorting my rowsInstantColumn
set(int index, long value)
InstantColumn
set(int index, Instant value)
Sets the value at index row to the given value and return this columnInstantColumn
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 columnInstantColumn
set(Selection rowSelection, Instant newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaInstantColumn
setMissing(int i)
Sets the value at index i to the missing-value indicator for this column type, and return this columnvoid
setPrintFormatter(InstantColumnFormatter formatter)
Sets the print formatter to the argument.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 orderInstantColumn
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<Instant>
top(int n)
Returns the largest ("top") n values in the columnInstantColumn
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)
InstantColumn
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, lead, 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.instant.InstantMapFunctions
plusDays, plusHours, plusMicros, plusMillis, plusMinutes, plusMonths, plusSeconds, plusWeeks, plusYears
-
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
-
-
-
-
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
-
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
-
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 namedata
- 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
-
plus
public InstantColumn plus(long amountToAdd, ChronoUnit unit)
- Specified by:
plus
in interfaceInstantMapFunctions
- Specified by:
plus
in interfaceTemporalMapFunctions<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 interfaceColumn<Instant>
- Overrides:
subset
in classAbstractColumn<InstantColumn,Instant>
-
removeMissing
public InstantColumn removeMissing()
Returns a copy of this column with the missing values removed- Specified by:
removeMissing
in interfaceColumn<Instant>
-
contains
public boolean contains(Instant dateTime)
Returnstrue
if the given object appears in this column, and false otherwiseTODO override in column subtypes for performance
-
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 interfaceColumn<Instant>
-
where
public InstantColumn where(Selection selection)
Returns a new column containing the subset referenced by theSelection
-
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
-
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 interfaceColumn<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 interfaceColumn<Instant>
-
append
public InstantColumn append(Instant dateTime)
Appends value to the bottom of this column and return this column
-
appendObj
public InstantColumn appendObj(Object obj)
Appends the given value to the bottom of this column and return this column
-
size
public int size()
Returns the number of elements in this column, including missing values
-
appendInternal
public InstantColumn appendInternal(long dateTime)
Returns this column with the argument appended at the bottom- Specified by:
appendInternal
in interfaceTemporalColumn<Instant>
-
getString
public String getString(int row)
Returns a string representation of the value at the given row.
-
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<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 interfaceColumn<Instant>
- Specified by:
emptyCopy
in interfaceTemporalMapFunctions<Instant>
- Specified by:
emptyCopy
in classAbstractColumn<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.
-
copy
public InstantColumn copy()
Returns a deep copy of the receiver
-
clear
public void clear()
Removes all elements TODO: Make this return this column
-
sortAscending
public void sortAscending()
Sorts my values in ascending order- Specified by:
sortAscending
in interfaceColumn<Instant>
-
sortDescending
public void sortDescending()
Sorts my values in descending order- Specified by:
sortDescending
in interfaceColumn<Instant>
-
summary
public Table summary()
Returns a table containing a ColumnType specific summary of the data in this column
-
countUnique
public int countUnique()
Returns the count of unique values in this column.- Specified by:
countUnique
in interfaceColumn<Instant>
- Returns:
- unique values as int
-
unique
public InstantColumn unique()
Returns a column of the same type containing only the unique values
-
isEmpty
public boolean isEmpty()
Returns true if the column has no data
-
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<Instant>
- Specified by:
getLongInternal
in interfaceTemporalFilters<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 interfaceColumn<Instant>
- Specified by:
get
in interfaceTemporalColumn<Instant>
- Specified by:
get
in interfaceTemporalFilters<Instant>
-
rowComparator
public it.unimi.dsi.fastutil.ints.IntComparator rowComparator()
Returns an IntComparator for sorting my rows- Specified by:
rowComparator
in interfaceColumn<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 criteriaExample: myColumn.set(myColumn.valueIsMissing(), Instant.now()); // no more missing values
- Specified by:
set
in interfaceColumn<Instant>
- Overrides:
set
in classAbstractColumn<InstantColumn,Instant>
-
countMissing
public int countMissing()
Returns the count of missing values in this column- Specified by:
countMissing
in interfaceColumn<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 offsetIf a value is missing, InstantColumnType.missingValueIndicator() is 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
-
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
-
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
-
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
-
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 interfaceColumn<Instant>
-
min
public Instant min()
- Specified by:
min
in interfaceTemporalMapFunctions<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
-
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
-
byteSize
public int byteSize()
Returns the width of a cell in this column, in bytes.
-
asBytes
public byte[] asBytes(int rowNumber)
Returns the contents of the cell at rowNumber as a byte[]
-
getDouble
public double getDouble(int i)
-
asDoubleArray
public double[] asDoubleArray()
-
asDoubleColumn
public DoubleColumn asDoubleColumn()
-
fillWith
public InstantColumn fillWith(Iterator<Instant> iterator)
- Specified by:
fillWith
in interfaceTemporalFillers<Instant,InstantColumn>
-
fillWith
public InstantColumn fillWith(Iterable<Instant> iterable)
- Specified by:
fillWith
in interfaceTemporalFillers<Instant,InstantColumn>
-
fillWith
public InstantColumn fillWith(Supplier<Instant> supplier)
- Specified by:
fillWith
in interfaceTemporalFillers<Instant,InstantColumn>
-
asObjectArray
public Instant[] asObjectArray()
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArray
in interfaceColumn<Instant>
-
compare
public int compare(Instant o1, Instant o2)
- Specified by:
compare
in interfaceComparator<Instant>
-
isMissing
public Selection isMissing()
Returns a selection containing an index for every missing value in this column- Specified by:
isMissing
in interfaceColumn<Instant>
- Specified by:
isMissing
in interfaceFilterSpec<Selection>
- Specified by:
isMissing
in interfaceTemporalFilters<Instant>
-
isNotMissing
public Selection isNotMissing()
Returns a selection containing an index for every non-missing value in this column- Specified by:
isNotMissing
in interfaceColumn<Instant>
- Specified by:
isNotMissing
in interfaceFilterSpec<Selection>
- Specified by:
isNotMissing
in interfaceTemporalFilters<Instant>
-
-