Package tech.tablesaw.api
Class BooleanColumn
- All Implemented Interfaces:
Iterable<Boolean>
,Comparator<Boolean>
,CategoricalColumn<Boolean>
,BooleanFillers<BooleanColumn>
,BooleanFilters
,BooleanMapUtils
,Column<Boolean>
,BooleanFilterSpec<Selection>
,FilterSpec<Selection>
public class BooleanColumn
extends AbstractColumn<BooleanColumn,Boolean>
implements BooleanFilterSpec<Selection>, BooleanMapUtils, CategoricalColumn<Boolean>, BooleanFillers<BooleanColumn>, BooleanFilters
A column that contains boolean values
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected it.unimi.dsi.fastutil.bytes.ByteArrayList
The data held by this columnFields inherited from class tech.tablesaw.columns.AbstractColumn
DEFAULT_ARRAY_SIZE
-
Method Summary
Modifier and TypeMethodDescriptionboolean
all()
Returns true if the column contains only true values, and false otherwise.boolean
any()
Returns true if the column contains any true values, and false otherwiseappend
(boolean b) Appends b to the end of this column and returns this columnappend
(byte b) Appends b to the end of this column and returns this columnAppends value to the bottom of this column and return this columnAppends all the values in the argument to the bottom of this column and return this columnAppends the value at the given row in the given column to the bottom of this column and return this columnappendCell
(String object) Add one element to the bottom of this column and set its value to the parsed value of the given String.appendCell
(String object, 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 parserAppends a missing value appropriate to the columnAppends the given value to the bottom of this column and return this columnbyte[]
asBytes
(int row) Returns the contents of the cell at rowNumber as a byte[].double[]
Returns all the values in this column as an array of doubles, with true values encoded as 1.0 and false values as 0.0Returns a DoubleColumn containing the elements in this column, with true as 1.0 and false as 0.0.Boolean[]
Returns an array of objects as appropriate for my type of columnit.unimi.dsi.fastutil.booleans.BooleanSet
asSet()
Returns the values in this column as a BooleanSet instanceit.unimi.dsi.fastutil.bytes.ByteIterator
Returns a ByteIterator for this columnint
byteSize()
Returns the width of a cell in this column, in bytes.void
clear()
Removes all elements TODO: Make this return this columnint
boolean
contains
(boolean aBoolean) Returns true if the column contains at least one value likeaBoolean
copy()
Returns a deep copy of the receiverint
Returns the number offalse
elements in this columnint
Returns the count of missing values in this columnint
Returns the number oftrue
elements in this columnint
Returns the count of unique values in this column.static BooleanColumn
Returns a new, empty Boolean column with the given name.static BooleanColumn
Returns a new Boolean column with the given name and valuesstatic BooleanColumn
Returns a new Boolean column of the given size.static BooleanColumn
Returns a new Boolean column with the given name and valuesstatic BooleanColumn
create
(String name, Collection<Boolean> values) Returns a new Boolean column with the given name and valuesstatic BooleanColumn
Returns a new Boolean column with the given name and valuesstatic BooleanColumn
Returns a new Boolean column of the given size.it.unimi.dsi.fastutil.bytes.ByteArrayList
data()
Returns a ByteArrayList containing 0 (false), 1 (true) or Byte.MIN_VALUE (missing)Returns a copy of the receiver with no data.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 rowNumber2eval
(BiPredicate<Boolean, Boolean> predicate, Boolean valueToCompare) Returns a Selection of the elements that return true when the predicate is evaluated with the given Boolean argumentReturns a Selection of the elements that return true when the predicate is evaluatedeval
(BytePredicate predicate) Returns a Selection of the elements that return true when the predicate is evaluatedfillWith
(it.unimi.dsi.fastutil.booleans.BooleanIterable iterable) fillWith
(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator) get
(int i) Returns the value in row i as a Booleanbyte
getByte
(int i) Returns the value in row i as a byte (0, 1, or Byte.MIN_VALUE representing missing data)double
getDouble
(int row) Returns the value at row as a double, with true values encoded as 1.0 and false values as 0.0Returns the print formatter for this columngetString
(int row) Returns a string representation of the value at the given row.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 dataisEqualTo
(BooleanColumn other) isFalse()
Returns a selection containing an index for every missing value in this columnboolean
isMissing
(int rowNumber) Returns true if the value at rowNumber is missingReturns a selection containing an index for every non-missing value in this columnisTrue()
iterator()
lag
(int n) Returns a column of the same type and size as the receiver, containing the receivers values offset by n.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.boolean
none()
Returns true if the column contains no true values, and false otherwisedouble
Returns the proportion of non-missing row elements that contain falsedouble
Returns the proportion of non-missing row elements that contain trueReturns a copy of this column with the missing values removedit.unimi.dsi.fastutil.ints.IntComparator
Returns an IntComparator for sorting my rowsset
(int i, boolean b) Sets the value at i to b, and returns this columnSets the value at index row to the given value and return this columnset
(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 columnSets the value at row to the value at sourceRow in the given column and return this columnConditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaConditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria.setMissing
(int i) Sets the value at index i to the missing-value indicator for this column type, and return this columnvoid
setPrintFormatter
(BooleanFormatter formatter) Sets the print formatter for this columnint
size()
Returns the number of elements in this column, including missing valuesvoid
Sorts my values in ascending ordervoid
Sorts my values in descending ordersummary()
Returns a table containing a ColumnType specific summary of the data in this columnunique()
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
(byte b) Returnstrue
if b is the missing value indicator for this column typeReturns a new column containing the subset referenced by theSelection
Methods inherited from class tech.tablesaw.columns.AbstractColumn
asStringColumn, filter, first, indexOf, inRange, last, map, max, min, name, parser, sampleN, sampleX, set, set, setName, setParser, sorted, subset, 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.columns.booleans.BooleanMapUtils
and, andNot, or
Methods inherited from interface tech.tablesaw.api.CategoricalColumn
countByCategory
Methods inherited from interface tech.tablesaw.columns.Column
allMatch, anyMatch, asList, asStringColumn, columnWidth, contains, count, count, filter, first, indexOf, inRange, interpolate, last, map, map, mapInto, max, max, min, min, name, noneMatch, parser, print, reduce, reduce, rolling, sampleN, sampleX, set, set, set, setMissingTo, setName, setParser, sorted, subset, title, type
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
data
protected it.unimi.dsi.fastutil.bytes.ByteArrayList dataThe data held by this column
-
-
Method Details
-
valueIsMissing
public static boolean valueIsMissing(byte b) Returnstrue
if b is the missing value indicator for this column type -
isMissing
public boolean isMissing(int rowNumber) Returns true if the value at rowNumber is missing -
setMissing
Sets the value at index i to the missing-value indicator for this column type, and return this column- Specified by:
setMissing
in interfaceColumn<Boolean>
-
create
Returns a new Boolean column of the given size. Elements indexed by the selection are set to true- Parameters:
name
- The column namehits
- The true valuescolumnSize
- The column size- Returns:
- A new BooleanColumn
-
create
Returns a new, empty Boolean column with the given name.- Parameters:
name
- The column name- Returns:
- A new BooleanColumn
-
create
Returns a new Boolean column of the given size.- Parameters:
name
- The column nameinitialSize
- The column size- Returns:
- A new BooleanColumn
-
create
Returns a new Boolean column with the given name and values -
create
Returns a new Boolean column with the given name and values -
create
Returns a new Boolean column with the given name and values -
create
Returns a new Boolean column with the given name and values -
setPrintFormatter
Sets the print formatter for this column -
getPrintFormatter
Returns the print formatter for this column -
size
public int size()Returns the number of elements in this column, including missing values -
summary
Returns a table containing a ColumnType specific summary of the data in this column -
countMissing
public int countMissing()Returns the count of missing values in this column- Specified by:
countMissing
in interfaceColumn<Boolean>
- Returns:
- missing values as int
-
countUnique
public int countUnique()Returns the count of unique values in this column.- Specified by:
countUnique
in interfaceColumn<Boolean>
- Returns:
- unique values as int
-
unique
Returns a column of the same type containing only the unique values -
append
Appends b to the end of this column and returns this column -
append
Appends value to the bottom of this column and return this column -
appendObj
Appends the given value to the bottom of this column and return this column -
append
Appends b to the end of this column and returns this column -
appendMissing
Appends a missing value appropriate to the column- Specified by:
appendMissing
in interfaceColumn<Boolean>
-
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 -
getString
Returns a string representation of the value at the given row. -
getUnformattedString
Returns a String representation of the value at index r, without any formatting applied- Specified by:
getUnformattedString
in interfaceColumn<Boolean>
-
emptyCopy
Returns a copy of the receiver with no data. The column name and type are the same.- Specified by:
emptyCopy
in interfaceColumn<Boolean>
- Specified by:
emptyCopy
in classAbstractColumn<BooleanColumn,
Boolean> - Returns:
- a empty copy of
Column
-
emptyCopy
Returns an empty copy of the receiver, with its internal storage initialized to the given row size. -
clear
public void clear()Removes all elements TODO: Make this return this column -
copy
Returns a deep copy of the receiver -
sortAscending
public void sortAscending()Sorts my values in ascending order- Specified by:
sortAscending
in interfaceColumn<Boolean>
-
sortDescending
public void sortDescending()Sorts my values in descending order- Specified by:
sortDescending
in interfaceColumn<Boolean>
-
appendCell
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<Boolean>
-
appendCell
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<Boolean>
-
get
Returns the value in row i as a Boolean -
getByte
public byte getByte(int i) Returns the value in row i as a byte (0, 1, or Byte.MIN_VALUE representing missing data)- Parameters:
i
- the row number
-
isEmpty
public boolean isEmpty()Returns true if the column has no data -
countTrue
public int countTrue()Returns the number oftrue
elements in this column -
countFalse
public int countFalse()Returns the number offalse
elements in this column -
proportionTrue
public double proportionTrue()Returns the proportion of non-missing row elements that contain true -
proportionFalse
public double proportionFalse()Returns the proportion of non-missing row elements that contain false -
any
public boolean any()Returns true if the column contains any true values, and false otherwise -
all
public boolean all()Returns true if the column contains only true values, and false otherwise. If there are any missing values it returns false. -
none
public boolean none()Returns true if the column contains no true values, and false otherwise -
isFalse
- Specified by:
isFalse
in interfaceBooleanFilters
- Specified by:
isFalse
in interfaceBooleanFilterSpec<Selection>
-
isTrue
- Specified by:
isTrue
in interfaceBooleanFilters
- Specified by:
isTrue
in interfaceBooleanFilterSpec<Selection>
-
isEqualTo
- Specified by:
isEqualTo
in interfaceBooleanFilters
- Specified by:
isEqualTo
in interfaceBooleanFilterSpec<Selection>
-
data
public it.unimi.dsi.fastutil.bytes.ByteArrayList data()Returns a ByteArrayList containing 0 (false), 1 (true) or Byte.MIN_VALUE (missing) -
set
Sets the value at i to b, and returns this column -
set
Sets the value at index row to the given value and return this column -
set
Sets the value at row to the parsed value of the given String using the given parser and returns this column -
lead
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
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
-
set
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria -
set
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria.- Parameters:
rowSelection
- the rows to be updatednewValue
- a byte representation of boolean values. The only valid arguments are 0, 1, andBooleanColumnType.missingValueIndicator()
-
getDouble
public double getDouble(int row) Returns the value at row as a double, with true values encoded as 1.0 and false values as 0.0 -
asDoubleArray
public double[] asDoubleArray()Returns all the values in this column as an array of doubles, with true values encoded as 1.0 and false values as 0.0 -
rowComparator
public it.unimi.dsi.fastutil.ints.IntComparator rowComparator()Returns an IntComparator for sorting my rows- Specified by:
rowComparator
in interfaceColumn<Boolean>
-
append
Appends all the values in the argument to the bottom of this column and return this column -
append
Appends the value at the given row in the given column to the bottom of this column and return this column -
set
Sets the value at row to the value at sourceRow in the given column and return this column -
asSelection
- Specified by:
asSelection
in interfaceBooleanMapUtils
-
isMissing
Returns a selection containing an index for every missing value in this column- Specified by:
isMissing
in interfaceBooleanFilters
- Specified by:
isMissing
in interfaceColumn<Boolean>
- Specified by:
isMissing
in interfaceFilterSpec<Selection>
-
isNotMissing
Returns a selection containing an index for every non-missing value in this column- Specified by:
isNotMissing
in interfaceBooleanFilters
- Specified by:
isNotMissing
in interfaceColumn<Boolean>
- Specified by:
isNotMissing
in interfaceFilterSpec<Selection>
-
iterator
-
byteIterator
public it.unimi.dsi.fastutil.bytes.ByteIterator byteIterator()Returns a ByteIterator for this column -
asSet
public it.unimi.dsi.fastutil.booleans.BooleanSet asSet()Returns the values in this column as a BooleanSet instance -
contains
public boolean contains(boolean aBoolean) Returns true if the column contains at least one value likeaBoolean
-
byteSize
public int byteSize()Returns the width of a cell in this column, in bytes. -
asBytes
public byte[] asBytes(int row) Returns the contents of the cell at rowNumber as a byte[]. -
where
Returns a new column containing the subset referenced by theSelection
-
removeMissing
Returns a copy of this column with the missing values removed- Specified by:
removeMissing
in interfaceColumn<Boolean>
-
eval
Returns a Selection of the elements that return true when the predicate is evaluated -
eval
Returns a Selection of the elements that return true when the predicate is evaluated -
eval
Returns a Selection of the elements that return true when the predicate is evaluated with the given Boolean argument -
asDoubleColumn
Returns a DoubleColumn containing the elements in this column, with true as 1.0 and false as 0.0. -
compare
- Specified by:
compare
in interfaceComparator<Boolean>
-
fillWith
- Specified by:
fillWith
in interfaceBooleanFillers<BooleanColumn>
-
fillWith
- Specified by:
fillWith
in interfaceBooleanFillers<BooleanColumn>
-
fillWith
- Specified by:
fillWith
in interfaceBooleanFillers<BooleanColumn>
-
asObjectArray
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArray
in interfaceColumn<Boolean>
-