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.LongArrayListdata-
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 InstantColumnappend(Instant dateTime)Appends value to the bottom of this column and return this columnInstantColumnappend(Column<Instant> column)Appends all the values in the argument to the bottom of this column and return this columnInstantColumnappend(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 columnInstantColumnappendCell(String stringValue)Add one element to the bottom of this column and set its value to the parsed value of the given String.InstantColumnappendCell(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 parserInstantColumnappendInternal(long dateTime)Returns this column with the argument appended at the bottomInstantColumnappendMissing()Appends a missing value appropriate to the columnInstantColumnappendObj(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()DoubleColumnasDoubleColumn()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 offsetDateTimeColumnasLocalDateTimeColumn()Returns a DateTimeColumn where each element is a representation of the associated Instant translated using UTC as the timezoneDateTimeColumnasLocalDateTimeColumn(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 columnintbyteSize()Returns the width of a cell in this column, in bytes.voidclear()Removes all elements TODO: Make this return this columnintcompare(Instant o1, Instant o2)booleancontains(Instant dateTime)Returnstrueif the given object appears in this column, and false otherwiseInstantColumncopy()Returns a deep copy of the receiverintcountMissing()Returns the count of missing values in this columnintcountUnique()Returns the count of unique values in this column.static InstantColumncreate(String name)static InstantColumncreate(String name, int initialSize)static InstantColumncreate(String name, Instant... data)static InstantColumncreate(String name, Collection<Instant> data)static InstantColumncreate(String name, Stream<Instant> stream)static InstantColumncreateInternal(String name, long[] data)For internal Tablesaw use only Returns a new column with the given name and dataInstantColumnemptyCopy()Returns a copy of the receiver with no data.InstantColumnemptyCopy(int rowSize)Returns an empty copy of the receiver, with its internal storage initialized to the given row size.booleanequals(int rowNumber1, int rowNumber2)Returns true if the value in this column at rowNumber1 is equal to the value at rowNumber2InstantColumnfillWith(Iterable<Instant> iterable)InstantColumnfillWith(Supplier<Instant> supplier)InstantColumnfillWith(Iterator<Instant> iterator)Instantget(int index)Returns a value of the Object type stored in the column (e.g.doublegetDouble(int i)longgetLongInternal(int index)Returns the internal (long-encoded) value stored in the column at the given rowprotected longgetPackedInstant(int index)Returns the long-encoded version of the instant at the given indexStringgetString(int row)Returns a string representation of the value at the given row.StringgetUnformattedString(int row)Returns a String representation of the value at index r, without any formatting appliedbooleanisEmpty()Returns true if the column has no dataSelectionisMissing()Returns a selection containing an index for every missing value in this columnbooleanisMissing(int rowNumber)Returns true if the value at rowNumber is missingSelectionisNotMissing()Returns a selection containing an index for every non-missing value in this columnIterator<Instant>iterator()Returns an iterator over elements of typeT.InstantColumnlag(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.LongIteratorlongIterator()Returns an iterator over the long representations of the instants in this columnInstantmax()Returns the largest instant value in the columnInstantmin()InstantColumnplus(long amountToAdd, ChronoUnit unit)InstantColumnremoveMissing()Returns a copy of this column with the missing values removedit.unimi.dsi.fastutil.ints.IntComparatorrowComparator()Returns an IntComparator for sorting my rowsInstantColumnset(int index, long value)InstantColumnset(int index, Instant value)Sets the value at index row to the given value and return this columnInstantColumnset(int row, Column<Instant> column, int sourceRow)Sets the value at row to the value at sourceRow in the given column and return this columnInstantColumnset(Selection rowSelection, Instant newValue)Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaInstantColumnsetMissing(int i)Sets the value at index i to the missing-value indicator for this column type, and return this columnvoidsetPrintFormatter(InstantColumnFormatter formatter)Sets the print formatter to the argument.intsize()Returns the number of elements in this column, including missing valuesvoidsortAscending()Sorts my values in ascending ordervoidsortDescending()Sorts my values in descending orderInstantColumnsubset(int[] rows)Return a column of the same type containing just those elements whose indexes are included in the given arrayTablesummary()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 columnInstantColumnunique()Returns a column of the same type containing only the unique valuesintvalueHash(int rowNumber)Returns an int suitable as a hash for the value in this column at the given indexstatic booleanvalueIsMissing(long value)InstantColumnwhere(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:
plusin interfaceInstantMapFunctions- Specified by:
plusin 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:
subsetin interfaceColumn<Instant>- Overrides:
subsetin classAbstractColumn<InstantColumn,Instant>
-
removeMissing
public InstantColumn removeMissing()
Returns a copy of this column with the missing values removed- Specified by:
removeMissingin interfaceColumn<Instant>
-
contains
public boolean contains(Instant dateTime)
Returnstrueif 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:
setMissingin 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:
appendCellin 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:
appendCellin 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:
appendInternalin 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:
getUnformattedStringin 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:
emptyCopyin interfaceColumn<Instant>- Specified by:
emptyCopyin interfaceTemporalMapFunctions<Instant>- Specified by:
emptyCopyin 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:
sortAscendingin interfaceColumn<Instant>
-
sortDescending
public void sortDescending()
Sorts my values in descending order- Specified by:
sortDescendingin 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:
countUniquein 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:
getLongInternalin interfaceTemporalColumn<Instant>- Specified by:
getLongInternalin 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:
getin interfaceColumn<Instant>- Specified by:
getin interfaceTemporalColumn<Instant>- Specified by:
getin interfaceTemporalFilters<Instant>
-
rowComparator
public it.unimi.dsi.fastutil.ints.IntComparator rowComparator()
Returns an IntComparator for sorting my rows- Specified by:
rowComparatorin 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:
setin interfaceColumn<Instant>- Overrides:
setin classAbstractColumn<InstantColumn,Instant>
-
countMissing
public int countMissing()
Returns the count of missing values in this column- Specified by:
countMissingin 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:
appendMissingin interfaceColumn<Instant>
-
min
public Instant min()
- Specified by:
minin 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:
fillWithin interfaceTemporalFillers<Instant,InstantColumn>
-
fillWith
public InstantColumn fillWith(Iterable<Instant> iterable)
- Specified by:
fillWithin interfaceTemporalFillers<Instant,InstantColumn>
-
fillWith
public InstantColumn fillWith(Supplier<Instant> supplier)
- Specified by:
fillWithin interfaceTemporalFillers<Instant,InstantColumn>
-
asObjectArray
public Instant[] asObjectArray()
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArrayin interfaceColumn<Instant>
-
compare
public int compare(Instant o1, Instant o2)
- Specified by:
comparein interfaceComparator<Instant>
-
isMissing
public Selection isMissing()
Returns a selection containing an index for every missing value in this column- Specified by:
isMissingin interfaceColumn<Instant>- Specified by:
isMissingin interfaceFilterSpec<Selection>- Specified by:
isMissingin interfaceTemporalFilters<Instant>
-
isNotMissing
public Selection isNotMissing()
Returns a selection containing an index for every non-missing value in this column- Specified by:
isNotMissingin interfaceColumn<Instant>- Specified by:
isNotMissingin interfaceFilterSpec<Selection>- Specified by:
isNotMissingin interfaceTemporalFilters<Instant>
-
-