Package tech.tablesaw.columns
Interface Column<T>
-
- All Superinterfaces:
Comparator<T>
,Iterable<T>
- All Known Subinterfaces:
BooleanMapUtils
,CategoricalColumn<T>
,DateFilters
,DateMapFunctions
,DateTimeFilters
,DateTimeMapFunctions
,InstantMapFunctions
,NumericColumn<T>
,TemporalColumn<T>
,TemporalFilters<T>
,TemporalMapFunctions<T>
,TimeFilters
,TimeMapFunctions
- All Known Implementing Classes:
AbstractColumn
,BooleanColumn
,DateColumn
,DateTimeColumn
,DoubleColumn
,FloatColumn
,InstantColumn
,IntColumn
,LongColumn
,NumberColumn
,ShortColumn
,StringColumn
,TimeColumn
public interface Column<T> extends Iterable<T>, Comparator<T>
The general interface for columns.Columns can either exist on their own or be a part of a table. All the data in a single column is of a particular type.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default boolean
allMatch(Predicate<? super T> test)
Returns true if all rows satisfy the predicate, false otherwisedefault boolean
anyMatch(Predicate<? super T> test)
Returns true if any row satisfies the predicate, false otherwiseColumn<T>
append(T value)
Appends value to the bottom of this column and return this columnColumn<T>
append(Column<T> column)
Appends all the values in the argument to the bottom of this column and return this columnColumn<T>
append(Column<T> column, int row)
Appends the value at the given row in the given column to the bottom of this column and return this columnColumn<T>
appendCell(String stringValue)
Add one element to the bottom of this column and set its value to the parsed value of the given String.Column<T>
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 parserColumn<T>
appendMissing()
Appends a missing value appropriate to the columnColumn<T>
appendObj(Object value)
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[].default List<T>
asList()
Returns a list of all the elements in this columnT[]
asObjectArray()
Returns an array of objects as appropriate for my type of columnSet<T>
asSet()
Returns a Set containing all the unique values in this columnStringColumn
asStringColumn()
Returns a StringColumn consisting of the (unformatted) String representation of this column valuesint
byteSize()
Returns the width of a cell in this column, in bytes.void
clear()
Removes all elements TODO: Make this return this columndefault int
columnWidth()
Returns the width of the column in characters, for printingdefault boolean
contains(T object)
Returnstrue
if the given object appears in this column, and false otherwiseColumn<T>
copy()
Returns a deep copy of the receiverdefault int
count(Predicate<? super T> test)
Counts the number of rows satisfying predicatedefault int
count(Predicate<? super T> test, int max)
Counts the number of rows satisfying predicate, but only upto the max valueint
countMissing()
Returns the count of missing values in this column.default int
countUnique()
Returns the count of unique values in this column.Column<T>
emptyCopy()
Returns a copy of the receiver with no data.Column<T>
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 rowNumber2default Column<T>
filter(Predicate<? super T> test)
Returns a new Column of the same type with only those rows satisfying the predicatedefault Column<T>
first(int numRows)
Returns a column of the same type containing the firstnumRows
of this column.T
get(int row)
Returns the value at the given zero-based indexString
getString(int row)
Returns a string representation of the value at the given row.String
getUnformattedString(int r)
Returns a String representation of the value at index r, without any formatting appliedint
indexOf(Object o)
Returns the index of the first occurrence ofo
in the column or -1 if the element is not in the column.default Column<T>
inRange(int start, int end)
Returns a column containing the rows in this column beginning with start inclusive, and ending with end exclusivedefault Interpolator<T>
interpolate()
Provides the ability to create a new column with missing cells filled based off the value of nearby cells.boolean
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 columnColumn<T>
lag(int n)
Returns a column of the same type and size as the receiver, containing the receivers values offset by n.default Column<T>
last(int numRows)
Returns a column of the same type containing the lastnumRows
of this column.int
lastIndexOf(Object o)
Returns the index of the last occurrence ofo
in the column or -1 if the element is not in the column.default Column<T>
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.default <R,C extends Column<R>>
Cmap(Function<? super T,? extends R> fun, Function<String,C> creator)
Maps the function across all rows, appending the results to the created Column.default Column<T>
map(Function<? super T,? extends T> fun)
Maps the function across all rows, appending the results to a new Column of the same typedefault <R,C extends Column<R>>
CmapInto(Function<? super T,? extends R> fun, C into)
Maps the function across all rows, storing the results into the provided Column.default Optional<T>
max(Comparator<? super T> comp)
Returns the maximum row according to the provided Comparatordefault Column<T>
max(Column<T> other)
Returns a column containing the element-wise min between this column and other columndefault Optional<T>
min(Comparator<? super T> comp)
Returns the minimum value according to the provided Comparatordefault Column<T>
min(Column<T> other)
Returns a column containing the element-wise min between this column and other columnString
name()
Returns the column's name.default boolean
noneMatch(Predicate<? super T> test)
Returns true if no row satisfies the predicate, false otherwiseAbstractColumnParser<T>
parser()
Returns the parser used byappendCell(String)
()}.default String
print()
TODO(lwhite): Print n from the top and bottom, like a table;default Optional<T>
reduce(BinaryOperator<T> op)
Reduction with binary operatordefault T
reduce(T initial, BinaryOperator<T> op)
Reduction with binary operator and initial valueColumn<T>
removeMissing()
Returns a copy of this column with the missing values removeddefault RollingColumn
rolling(int windowSize)
Returns aRollingColumn
with the given windowSize, which can be used for performing calculations on rolling subsets of my datait.unimi.dsi.fastutil.ints.IntComparator
rowComparator()
Returns an IntComparator for sorting my rowsdefault Column<T>
sampleN(int n)
Returns a column containing a random sample of the values in this columndefault Column<T>
sampleX(double proportion)
Returns a table consisting of randomly selected values from this column.default Column<T>
set(int row, String stringValue, AbstractColumnParser<?> parser)
Sets the value at row to the parsed value of the given String using the given parser and returns this columnColumn<T>
set(int row, T value)
Sets the value at index row to the given value and return this columnColumn<T>
set(int row, Column<T> sourceColumn, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this columndefault Column<T>
set(Predicate<T> condition, Column<T> other)
Updates this column where values matching the selection are replaced with the corresponding value from the given columndefault Column<T>
set(Selection rowSelection, T newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriadefault Column<T>
set(Selection condition, Column<T> other)
Updates this column where values matching the selection are replaced with the corresponding value from the given columnColumn<T>
setMissing(int i)
Sets the value at index i to the missing-value indicator for this column type, and return this columndefault Column<T>
setMissingTo(T newValue)
Sets the value of any missing data in the column to newValue and returns the same columnColumn<T>
setName(String name)
Sets the columns name to the given stringColumn<T>
setParser(AbstractColumnParser<T> parser)
Sets the parser used byappendCell(String)
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 orderdefault Column<T>
sorted(Comparator<? super T> comp)
Returns a new Column of the same type sorted according to the provided Comparatordefault Column<T>
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 columndefault String
title()
ColumnType
type()
Returns this column's ColumnTypeColumn<T>
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 indexColumn<T>
where(Selection selection)
Returns a new column containing the subset referenced by theSelection
-
Methods inherited from interface java.util.Comparator
compare, equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
size
int size()
Returns the number of elements in this column, including missing values
-
summary
Table summary()
Returns a table containing a ColumnType specific summary of the data in this column
-
asObjectArray
T[] asObjectArray()
Returns an array of objects as appropriate for my type of column
-
countMissing
int countMissing()
Returns the count of missing values in this column.- Returns:
- missing values as int
-
countUnique
default int countUnique()
Returns the count of unique values in this column.- Returns:
- unique values as int
-
name
String name()
Returns the column's name.- Returns:
- name as String
-
type
ColumnType type()
Returns this column's ColumnType- Returns:
ColumnType
-
parser
AbstractColumnParser<T> parser()
Returns the parser used byappendCell(String)
()}.- Returns:
AbstractColumnParser
-
getString
String getString(int row)
Returns a string representation of the value at the given row.- Parameters:
row
- The index of the row.- Returns:
- value as String
-
get
T get(int row)
Returns the value at the given zero-based index
-
reduce
default T reduce(T initial, BinaryOperator<T> op)
Reduction with binary operator and initial value- Parameters:
initial
- initial valueop
- the operator- Returns:
- the result of reducing initial value and all rows with operator
-
reduce
default Optional<T> reduce(BinaryOperator<T> op)
Reduction with binary operator- Parameters:
op
- the operator- Returns:
- Optional with the result of reducing all rows with operator
-
clear
void clear()
Removes all elements TODO: Make this return this column
-
sortAscending
void sortAscending()
Sorts my values in ascending order
-
sortDescending
void sortDescending()
Sorts my values in descending order
-
isEmpty
boolean isEmpty()
Returns true if the column has no data- Returns:
- true if empty, false if not
-
rowComparator
it.unimi.dsi.fastutil.ints.IntComparator rowComparator()
Returns an IntComparator for sorting my rows
-
title
default String title()
-
isMissing
Selection isMissing()
Returns a selection containing an index for every missing value in this column
-
isNotMissing
Selection isNotMissing()
Returns a selection containing an index for every non-missing value in this column
-
byteSize
int byteSize()
Returns the width of a cell in this column, in bytes.- Returns:
- width in bytes
-
asBytes
byte[] asBytes(int rowNumber)
Returns the contents of the cell at rowNumber as a byte[].- Parameters:
rowNumber
- index of the row- Returns:
- content as byte[]
-
rolling
default RollingColumn rolling(int windowSize)
Returns aRollingColumn
with the given windowSize, which can be used for performing calculations on rolling subsets of my data- Parameters:
windowSize
- The number of elements to include in each calculation- Returns:
- a RollingColumn
-
getUnformattedString
String getUnformattedString(int r)
Returns a String representation of the value at index r, without any formatting applied
-
isMissing
boolean isMissing(int rowNumber)
Returns true if the value at rowNumber is missing
-
print
default String print()
TODO(lwhite): Print n from the top and bottom, like a table;
-
columnWidth
default int columnWidth()
Returns the width of the column in characters, for printing
-
asList
default List<T> asList()
Returns a list of all the elements in this columnNote, if a value in the column is missing, a
null
is added in it's place
-
contains
default boolean contains(T object)
Returnstrue
if the given object appears in this column, and false otherwiseTODO override in column subtypes for performance
-
count
default int count(Predicate<? super T> test, int max)
Counts the number of rows satisfying predicate, but only upto the max value- Parameters:
test
- the predicatemax
- the maximum number of rows to count- Returns:
- the number of rows satisfying the predicate
-
count
default int count(Predicate<? super T> test)
Counts the number of rows satisfying predicate- Parameters:
test
- the predicate- Returns:
- the number of rows satisfying the predicate
-
allMatch
default boolean allMatch(Predicate<? super T> test)
Returns true if all rows satisfy the predicate, false otherwise- Parameters:
test
- the predicate- Returns:
- true if all rows satisfy the predicate, false otherwise
-
anyMatch
default boolean anyMatch(Predicate<? super T> test)
Returns true if any row satisfies the predicate, false otherwise- Parameters:
test
- the predicate- Returns:
- true if any rows satisfies the predicate, false otherwise
-
noneMatch
default boolean noneMatch(Predicate<? super T> test)
Returns true if no row satisfies the predicate, false otherwise- Parameters:
test
- the predicate- Returns:
- true if no row satisfies the predicate, false otherwise
-
max
default Optional<T> max(Comparator<? super T> comp)
Returns the maximum row according to the provided Comparator- Parameters:
comp
-- Returns:
- the maximum row
-
min
default Optional<T> min(Comparator<? super T> comp)
Returns the minimum value according to the provided Comparator- Parameters:
comp
- the Comparator to use- Returns:
- the minimum value
-
mapInto
default <R,C extends Column<R>> C mapInto(Function<? super T,? extends R> fun, C into)
Maps the function across all rows, storing the results into the provided Column.The target column must have at least the same number of rows.
- Parameters:
fun
- function to mapinto
- Column into which results are set- Returns:
- the provided Column
-
map
default <R,C extends Column<R>> C map(Function<? super T,? extends R> fun, Function<String,C> creator)
Maps the function across all rows, appending the results to the created Column.Example:
DoubleColumn d; StringColumn s = d.map(String::valueOf, StringColumn::create);
- Parameters:
fun
- function to mapcreator
- the creator of the Column. Its String argument will be the name of the current column (seename()
)- Returns:
- the Column with the results
-
setMissing
Column<T> setMissing(int i)
Sets the value at index i to the missing-value indicator for this column type, and return this column
-
setMissingTo
default Column<T> setMissingTo(T newValue)
Sets the value of any missing data in the column to newValue and returns the same column- Parameters:
newValue
- the value to be used for all missing data in this column- Returns:
- the column updated
-
filter
default Column<T> filter(Predicate<? super T> test)
Returns a new Column of the same type with only those rows satisfying the predicate- Parameters:
test
- the predicate- Returns:
- a new Column of the same type with only those rows satisfying the predicate
-
subset
default Column<T> subset(int[] rows)
Return a column of the same type containing just those elements whose indexes are included in the given array
-
sorted
default Column<T> sorted(Comparator<? super T> comp)
Returns a new Column of the same type sorted according to the provided Comparator- Parameters:
comp
- the Comparator- Returns:
- a sorted Column
-
emptyCopy
Column<T> emptyCopy()
Returns a copy of the receiver with no data. The column name and type are the same.- Returns:
- a empty copy of
Column
-
emptyCopy
Column<T> emptyCopy(int rowSize)
Returns an empty copy of the receiver, with its internal storage initialized to the given row size.- Parameters:
rowSize
- the initial row size- Returns:
- a
Column
-
map
default Column<T> map(Function<? super T,? extends T> fun)
Maps the function across all rows, appending the results to a new Column of the same type- Parameters:
fun
- function to map- Returns:
- the Column with the results
-
min
default Column<T> min(Column<T> other)
Returns a column containing the element-wise min between this column and other columnTODO(lwhite) Override in column subtypes for better performance
-
max
default Column<T> max(Column<T> other)
Returns a column containing the element-wise min between this column and other columnTODO(lwhite) Override in column subtypes for better performance
-
set
default Column<T> set(Predicate<T> condition, Column<T> other)
Updates this column where values matching the selection are replaced with the corresponding value from the given column
-
set
default Column<T> set(Selection condition, Column<T> other)
Updates this column where values matching the selection are replaced with the corresponding value from the given column
-
lead
default Column<T> 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.
-
set
default Column<T> set(Selection rowSelection, T newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria
-
lag
Column<T> 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
Column<T> 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
-
appendCell
Column<T> 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
-
set
Column<T> set(int row, T value)
Sets the value at index row to the given value and return this column
-
set
default Column<T> set(int row, String stringValue, AbstractColumnParser<?> parser)
Sets the value at row to the parsed value of the given String using the given parser and returns this column
-
set
Column<T> set(int row, Column<T> sourceColumn, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this column
-
append
Column<T> append(Column<T> column)
Appends all the values in the argument to the bottom of this column and return this column
-
append
Column<T> append(Column<T> column, int row)
Appends the value at the given row in the given column to the bottom of this column and return this column
-
appendObj
Column<T> appendObj(Object value)
Appends the given value to the bottom of this column and return this column
-
valueHash
int valueHash(int rowNumber)
Returns an int suitable as a hash for the value in this column at the given index
-
equals
boolean equals(int rowNumber1, int rowNumber2)
Returns true if the value in this column at rowNumber1 is equal to the value at rowNumber2
-
where
Column<T> where(Selection selection)
Returns a new column containing the subset referenced by theSelection
-
removeMissing
Column<T> removeMissing()
Returns a copy of this column with the missing values removed
-
unique
Column<T> unique()
Returns a column of the same type containing only the unique values- Returns:
- a
Column
-
first
default Column<T> first(int numRows)
Returns a column of the same type containing the firstnumRows
of this column.
-
last
default Column<T> last(int numRows)
Returns a column of the same type containing the lastnumRows
of this column.
-
setName
Column<T> setName(String name)
Sets the columns name to the given string- Parameters:
name
- The new name MUST be unique for any table containing this column- Returns:
- this Column to allow method chaining
-
setParser
Column<T> setParser(AbstractColumnParser<T> parser)
Sets the parser used byappendCell(String)
- Parameters:
parser
- a column parser that converts text input to the column data type- Returns:
- this Column to allow method chaining
-
inRange
default Column<T> inRange(int start, int end)
Returns a column containing the rows in this column beginning with start inclusive, and ending with end exclusive
-
sampleN
default Column<T> sampleN(int n)
Returns a column containing a random sample of the values in this column- Parameters:
n
- the number of values to select- Returns:
- A column of the same type as the receiver
-
sampleX
default Column<T> sampleX(double proportion)
Returns a table consisting of randomly selected values from this column. The sample size is based on the given proportion of the total number of cells in this column- Parameters:
proportion
- The proportion to go in the sample
-
interpolate
default Interpolator<T> interpolate()
Provides the ability to create a new column with missing cells filled based off the value of nearby cells.
-
asStringColumn
StringColumn asStringColumn()
Returns a StringColumn consisting of the (unformatted) String representation of this column values- Returns:
- a
StringColumn
built using the columngetUnformattedString(int)
method
-
indexOf
int indexOf(Object o)
Returns the index of the first occurrence ofo
in the column or -1 if the element is not in the column.
-
lastIndexOf
int lastIndexOf(Object o)
Returns the index of the last occurrence ofo
in the column or -1 if the element is not in the column.
-
-