Package tech.tablesaw.api
Class DateColumn
- java.lang.Object
-
- tech.tablesaw.columns.AbstractColumn<DateColumn,LocalDate>
-
- tech.tablesaw.api.DateColumn
-
- All Implemented Interfaces:
Iterable<LocalDate>,Comparator<LocalDate>,CategoricalColumn<LocalDate>,Column<LocalDate>,DateFillers<DateColumn>,DateFilters,DateMapFunctions,DateAndDateTimeFilterSpec<Selection>,FilterSpec<Selection>
public class DateColumn extends AbstractColumn<DateColumn,LocalDate> implements DateFilters, DateFillers<DateColumn>, DateMapFunctions, CategoricalColumn<LocalDate>
A column that contains int-encoded local date values
-
-
Field Summary
Fields Modifier and Type Field Description protected it.unimi.dsi.fastutil.ints.IntArrayListdataThe data held in this column in its integer encoding form.-
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 DateColumnappend(LocalDate value)Appends value to the bottom of this column and return this columnDateColumnappend(Column<LocalDate> column)Appends all the values in the argument to the bottom of this column and return this columnDateColumnappend(Column<LocalDate> column, int row)Appends the value at the given row in the given column to the bottom of this column and return this columnDateColumnappendCell(String string)Add one element to the bottom of this column and set its value to the parsed value of the given String.DateColumnappendCell(String string, 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 parserDateColumnappendInternal(int f)DateColumnappendMissing()Appends a missing value appropriate to the columnDateColumnappendObj(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()List<LocalDate>asList()Returns a list of all the elements in this columnLocalDate[]asObjectArray()Returns an array of objects as appropriate for my type of columnSet<LocalDate>asSet()Returns a Set containing all the unique values in this columnList<LocalDate>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(LocalDate o1, LocalDate o2)booleancontains(LocalDate localDate)Returnstrueif the given object appears in this column, and false otherwiseDateColumncopy()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 DateColumncreate(String name)Creates a new DateColumn with the given name.static DateColumncreate(String name, int initialSize)Creates a new DateColumn with the given name.static DateColumncreate(String name, LocalDate... data)Creates a new DateColumn with the given name and datastatic DateColumncreate(String name, Collection<LocalDate> data)Creates a new DateColumn with the given name and datastatic DateColumncreate(String name, Stream<LocalDate> stream)Creates a new DateColumn with the given name and datastatic DateColumncreateInternal(String name, int[] data)Creates a new DateColumn with the given name and integer-encoded data.DateColumnemptyCopy()Returns a copy of the receiver with no data.DateColumnemptyCopy(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 rowNumber2DateColumnfillWith(Iterable<LocalDate> iterable)DateColumnfillWith(Supplier<LocalDate> supplier)DateColumnfillWith(Iterator<LocalDate> iterator)LocalDateget(int index)Returns the value at the given zero-based indexdoublegetDouble(int i)intgetIntInternal(int index)protected intgetPackedDate(int index)StringgetString(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 appliedit.unimi.dsi.fastutil.ints.IntIteratorintIterator()booleanisEmpty()Returns true if the column has no databooleanisMissing(int rowNumber)Returns true if the value at rowNumber is missingIterator<LocalDate>iterator()Returns an iterator over elements of typeT.DateColumnlag(int n)Returns a column of the same type and size as the receiver, containing the receivers values offset by n.DateColumnlead(int n)Returns a column of the same type as the receiver, containing the receivers values offset -n For example if you lead a column containing 2, 3, 4 by 1, you get a column containing 3, 4, NA.LocalDatemax()LocalDatemin()DateColumnremoveMissing()Returns a copy of this column with the missing values removedit.unimi.dsi.fastutil.ints.IntComparatorrowComparator()Returns an IntComparator for sorting my rowsDateColumnset(int index, int value)DateColumnset(int index, LocalDate value)Sets the value at index row to the given value and return this columnDateColumnset(int row, Column<LocalDate> column, int sourceRow)Sets the value at row to the value at sourceRow in the given column and return this columnDateColumnset(Selection rowSelection, LocalDate newValue)Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaDateColumnsetMissing(int i)Sets the value at index i to the missing-value indicator for this column type, and return this columnvoidsetPrintFormatter(DateTimeFormatter dateTimeFormatter)Creates and sets a printFormatter based-on the given DateTimeFormatter.voidsetPrintFormatter(DateTimeFormatter dateTimeFormatter, String missingValueString)Creates and sets a printFormatter based-on the given DateTimeFormatter.voidsetPrintFormatter(DateColumnFormatter dateColumnFormatter)Sets the print formatter to the argumentintsize()Returns the number of elements in this column, including missing valuesvoidsortAscending()Sorts my values in ascending ordervoidsortDescending()Sorts my values in descending orderDateColumnsubset(int[] rows)Return a column of the same type containing just those elements whose indexes are included in the given arrayTablesummary()Returns a table of dates and the number of observations of those datesList<LocalDate>top(int n)Returns the largest ("top") n values in the columnDateColumnunique()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(int i)DateColumnwhere(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, 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.dates.DateFilters
eval, eval, eval, eval, eval, isAfter, isAfter, isAfter, isBefore, isBefore, isBefore, isBetweenExcluding, isBetweenExcluding, isBetweenIncluding, isBetweenIncluding, isEqualTo, isEqualTo, isEqualTo, isFirstDayOfMonth, isFriday, isInApril, isInAugust, isInDecember, isInFebruary, isInJanuary, isInJuly, isInJune, isInMarch, isInMay, isInNovember, isInOctober, isInQ1, isInQ2, isInQ3, isInQ4, isInSeptember, isInYear, isLastDayOfMonth, isMissing, isMonday, isNotEqualTo, isNotEqualTo, isNotEqualTo, isNotMissing, isOnOrAfter, isOnOrAfter, isOnOrBefore, isOnOrBefore, isSaturday, isSunday, isThursday, isTuesday, isWednesday
-
Methods inherited from interface tech.tablesaw.columns.dates.DateMapFunctions
atStartOfDay, atTime, atTime, dayOfMonth, dayOfWeek, dayOfWeekValue, dayOfYear, daysUntil, minus, minusDays, minusMonths, minusWeeks, minusYears, month, monthsUntil, monthValue, plus, plusDays, plusMonths, plusWeeks, plusYears, timeUntil, timeWindow, timeWindow, weeksUntil, year, yearDay, yearMonth, yearQuarter, yearsUntil, yearWeek
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
data
protected it.unimi.dsi.fastutil.ints.IntArrayList data
The data held in this column in its integer encoding form. SeePackedLocalDate
-
-
Method Detail
-
create
public static DateColumn create(String name)
Creates a new DateColumn with the given name. The column is completely empty.
-
createInternal
public static DateColumn createInternal(String name, int[] data)
Creates a new DateColumn with the given name and integer-encoded data. SeePackedLocalDatefor details of the encoding
-
create
public static DateColumn create(String name, int initialSize)
Creates a new DateColumn with the given name. The column containsinitialSizemissing values.
-
create
public static DateColumn create(String name, Collection<LocalDate> data)
Creates a new DateColumn with the given name and data
-
create
public static DateColumn create(String name, LocalDate... data)
Creates a new DateColumn with the given name and data
-
create
public static DateColumn create(String name, Stream<LocalDate> stream)
Creates a new DateColumn with the given name and data
-
size
public int size()
Returns the number of elements in this column, including missing values
-
subset
public DateColumn 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<LocalDate>- Overrides:
subsetin classAbstractColumn<DateColumn,LocalDate>
-
appendInternal
public DateColumn appendInternal(int f)
-
set
public DateColumn set(int index, int value)
-
set
public DateColumn set(int index, LocalDate value)
Sets the value at index row to the given value and return this column
-
setPrintFormatter
public void setPrintFormatter(DateTimeFormatter dateTimeFormatter, String missingValueString)
Creates and sets a printFormatter based-on the given DateTimeFormatter. Missing values will be printed as the given missingValueString. Non missing values will be handled by the dateTimeFormatter
-
setPrintFormatter
public void setPrintFormatter(DateTimeFormatter dateTimeFormatter)
Creates and sets a printFormatter based-on the given DateTimeFormatter. Missing values will be printed as empty strings. Non missing values will be handled by the dateTimeFormatter
-
setPrintFormatter
public void setPrintFormatter(@Nonnull DateColumnFormatter dateColumnFormatter)Sets the print formatter to the argument
-
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<LocalDate>
-
emptyCopy
public DateColumn emptyCopy()
Returns a copy of the receiver with no data. The column name and type are the same.- Specified by:
emptyCopyin interfaceColumn<LocalDate>- Specified by:
emptyCopyin classAbstractColumn<DateColumn,LocalDate>- Returns:
- a empty copy of
Column
-
emptyCopy
public DateColumn emptyCopy(int rowSize)
Returns an empty copy of the receiver, with its internal storage initialized to the given row size.
-
copy
public DateColumn copy()
Returns a deep copy of the receiver
-
clear
public void clear()
Removes all elements TODO: Make this return this column
-
lead
public DateColumn lead(int n)
Returns a column of the same type as the receiver, containing the receivers values offset -n For example if you lead a column containing 2, 3, 4 by 1, you get a column containing 3, 4, NA.
-
lag
public DateColumn 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
-
sortAscending
public void sortAscending()
Sorts my values in ascending order- Specified by:
sortAscendingin interfaceColumn<LocalDate>
-
sortDescending
public void sortDescending()
Sorts my values in descending order- Specified by:
sortDescendingin interfaceColumn<LocalDate>
-
countUnique
public int countUnique()
Returns the count of unique values in this column.- Specified by:
countUniquein interfaceColumn<LocalDate>- Returns:
- unique values as int
-
unique
public DateColumn unique()
Returns a column of the same type containing only the unique values
-
append
public DateColumn append(Column<LocalDate> column)
Appends all the values in the argument to the bottom of this column and return this column
-
append
public DateColumn append(Column<LocalDate> 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 DateColumn set(int row, Column<LocalDate> column, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this column
-
max
public LocalDate max()
- Specified by:
maxin interfaceDateMapFunctions
-
min
public LocalDate min()
- Specified by:
minin interfaceDateMapFunctions
-
set
public DateColumn set(Selection rowSelection, LocalDate 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(), LocalDate.now()); // no more missing values
- Specified by:
setin interfaceColumn<LocalDate>- Overrides:
setin classAbstractColumn<DateColumn,LocalDate>
-
appendMissing
public DateColumn appendMissing()
Appends a missing value appropriate to the column- Specified by:
appendMissingin interfaceColumn<LocalDate>
-
get
public LocalDate get(int index)
Returns the value at the given zero-based index- Specified by:
getin interfaceColumn<LocalDate>- Specified by:
getin interfaceDateMapFunctions
-
isEmpty
public boolean isEmpty()
Returns true if the column has no data
-
rowComparator
public it.unimi.dsi.fastutil.ints.IntComparator rowComparator()
Returns an IntComparator for sorting my rows- Specified by:
rowComparatorin interfaceColumn<LocalDate>
-
append
public DateColumn append(LocalDate value)
Appends value to the bottom of this column and return this column
-
appendObj
public DateColumn appendObj(Object obj)
Appends the given value to the bottom of this column and return this column
-
appendCell
public DateColumn appendCell(String string)
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<LocalDate>
-
appendCell
public DateColumn appendCell(String string, 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<LocalDate>
-
getIntInternal
public int getIntInternal(int index)
- Specified by:
getIntInternalin interfaceDateFilters- Specified by:
getIntInternalin interfaceDateMapFunctions
-
getPackedDate
protected int getPackedDate(int index)
-
summary
public Table summary()
Returns a table of dates and the number of observations of those dates
-
valueIsMissing
public static boolean valueIsMissing(int i)
-
countMissing
public int countMissing()
Returns the count of missing values in this column- Specified by:
countMissingin interfaceColumn<LocalDate>- Returns:
- missing values as int
-
top
public List<LocalDate> 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<LocalDate> 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
-
intIterator
public it.unimi.dsi.fastutil.ints.IntIterator intIterator()
- Specified by:
intIteratorin interfaceDateFilters
-
removeMissing
public DateColumn removeMissing()
Returns a copy of this column with the missing values removed- Specified by:
removeMissingin interfaceColumn<LocalDate>
-
asList
public List<LocalDate> asList()
Returns a list of all the elements in this columnNote, if a value in the column is missing, a
nullis added in it's place
-
where
public DateColumn where(Selection selection)
Returns a new column containing the subset referenced by theSelection- Specified by:
wherein interfaceColumn<LocalDate>- Specified by:
wherein interfaceDateFilters
-
contains
public boolean contains(LocalDate localDate)
Returnstrueif the given object appears in this column, and false otherwiseTODO override in column subtypes for performance
-
setMissing
public DateColumn 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<LocalDate>
-
asDoubleArray
public double[] asDoubleArray()
-
asDoubleColumn
public DoubleColumn asDoubleColumn()
-
isMissing
public boolean isMissing(int rowNumber)
Returns true if the value at rowNumber is missing
-
getDouble
public double getDouble(int i)
-
byteSize
public int byteSize()
Returns the width of a cell in this column, in bytes.
-
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
-
asBytes
public byte[] asBytes(int rowNumber)
Returns the contents of the cell at rowNumber as a byte[]
-
fillWith
public DateColumn fillWith(Iterator<LocalDate> iterator)
- Specified by:
fillWithin interfaceDateFillers<DateColumn>
-
fillWith
public DateColumn fillWith(Iterable<LocalDate> iterable)
- Specified by:
fillWithin interfaceDateFillers<DateColumn>
-
fillWith
public DateColumn fillWith(Supplier<LocalDate> supplier)
- Specified by:
fillWithin interfaceDateFillers<DateColumn>
-
asObjectArray
public LocalDate[] asObjectArray()
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArrayin interfaceColumn<LocalDate>
-
compare
public int compare(LocalDate o1, LocalDate o2)
- Specified by:
comparein interfaceComparator<LocalDate>
-
-