Package tech.tablesaw.api
Class BooleanColumn
- java.lang.Object
-
- tech.tablesaw.columns.AbstractColumn<BooleanColumn,Boolean>
-
- tech.tablesaw.api.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
-
Fields inherited from class tech.tablesaw.columns.AbstractColumn
DEFAULT_ARRAY_SIZE
-
-
Constructor Summary
Constructors Constructor Description BooleanColumn(String name, BooleanData data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
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 otherwiseBooleanColumn
append(boolean b)
Appends b to the end of this column and returns this columnBooleanColumn
append(byte b)
Appends b to the end of this column and returns this columnBooleanColumn
append(Boolean b)
Appends value to the bottom of this column and return this columnBooleanColumn
append(Column<Boolean> column)
Appends all the values in the argument to the bottom of this column and return this columnColumn<Boolean>
append(Column<Boolean> column, int row)
Appends the value at the given row in the given column to the bottom of this column and return this columnBooleanColumn
appendCell(String object)
Add one element to the bottom of this column and set its value to the parsed value of the given String.BooleanColumn
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 parserBooleanColumn
appendMissing()
Appends a missing value appropriate to the columnBooleanColumn
appendObj(Object obj)
Appends 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[]
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.0DoubleColumn
asDoubleColumn()
Returns a DoubleColumn containing the elements in this column, with true as 1.0 and false as 0.0.Boolean[]
asObjectArray()
Returns an array of objects as appropriate for my type of columnSelection
asSelection()
it.unimi.dsi.fastutil.booleans.BooleanSet
asSet()
Returns the values in this column as a BooleanSet instanceit.unimi.dsi.fastutil.bytes.ByteIterator
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
compare(Boolean o1, Boolean o2)
boolean
contains(boolean aBoolean)
Returns true if the column contains at least one value likeaBoolean
BooleanColumn
copy()
Returns a deep copy of the receiverint
countFalse()
Returns the number offalse
elements in this columnint
countMissing()
Returns the count of missing values in this columnint
countTrue()
Returns the number oftrue
elements in this columnint
countUnique()
Returns the count of unique values in this column.static BooleanColumn
create(String name)
Returns a new, empty Boolean column with the given name.static BooleanColumn
create(String name, boolean... values)
Returns a new Boolean column with the given name and valuesstatic BooleanColumn
create(String name, int initialSize)
Returns a new Boolean column of the given size.static BooleanColumn
create(String name, Boolean[] values)
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
create(String name, Stream<Boolean> values)
Returns a new Boolean column with the given name and valuesstatic BooleanColumn
create(String name, Selection hits, int columnSize)
Returns a new Boolean column of the given size.BooleanData
data()
BooleanColumn
emptyCopy()
Returns a copy of the receiver with no data.BooleanColumn
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 rowNumber2Selection
eval(BiPredicate<Boolean,Boolean> predicate, Boolean valueToCompare)
Returns a Selection of the elements that return true when the predicate is evaluated with the given Boolean argumentSelection
eval(Predicate<Boolean> predicate)
Returns a Selection of the elements that return true when the predicate is evaluatedSelection
eval(BytePredicate predicate)
Returns a Selection of the elements that return true when the predicate is evaluatedbyte[]
falseBytes()
Returns a byte representation of the false values, encoded in the format specified inBitSet.toByteArray()
void
falseBytes(byte[] encodedValues)
Sets the false values in the data from a byte[] encodingBooleanColumn
fillWith(it.unimi.dsi.fastutil.booleans.BooleanIterable iterable)
BooleanColumn
fillWith(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
BooleanColumn
fillWith(Supplier<Boolean> supplier)
Boolean
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.0BooleanFormatter
getPrintFormatter()
Returns the print formatter for this columnString
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
isEqualTo(BooleanColumn other)
Selection
isFalse()
Selection
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 columnSelection
isTrue()
Iterator<Boolean>
iterator()
BooleanColumn
lag(int n)
Returns a column of the same type and size as the receiver, containing the receivers values offset by n.BooleanColumn
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.byte[]
missingBytes()
Returns a byte representation of the missing values, encoded in the format specified inBitSet.toByteArray()
void
missingBytes(byte[] encodedValues)
Sets the missing values in the data from a byte[] encodingboolean
none()
Returns true if the column contains no true values, and false otherwisedouble
proportionFalse()
Returns the proportion of non-missing row elements that contain falsedouble
proportionTrue()
Returns the proportion of non-missing row elements that contain trueBooleanColumn
removeMissing()
Returns a copy of this column with the missing values removedit.unimi.dsi.fastutil.ints.IntComparator
rowComparator()
Returns an IntComparator for sorting my rowsBooleanColumn
set(int i, boolean b)
Sets the value at i to b, and returns this columnBooleanColumn
set(int i, byte b)
Sets the value at i to b, and returns this columnBooleanColumn
set(int i, Boolean val)
Sets the value at index row to the given value and return this columnBooleanColumn
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<Boolean>
set(int row, Column<Boolean> column, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this columnBooleanColumn
set(Selection rowSelection, boolean newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaBooleanColumn
set(Selection rowSelection, byte newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria.BooleanColumn
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
sortAscending()
Sorts my values in ascending ordervoid
sortDescending()
Sorts my values in descending orderTable
summary()
Returns a table containing a ColumnType specific summary of the data in this columnit.unimi.dsi.fastutil.bytes.ByteArrayList
toByteArrayList()
Returns a ByteArrayList containing 0 (false), 1 (true) or Byte.MIN_VALUE (missing)byte[]
trueBytes()
Returns a byte representation of the true values, encoded in the format specified inBitSet.toByteArray()
void
trueBytes(byte[] encodedValues)
Sets the true values in the data from a byte[] encodingBooleanColumn
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(byte b)
Returnstrue
if b is the missing value indicator for this column typeBooleanColumn
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, 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, lastIndexOf, 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
-
-
-
-
Constructor Detail
-
BooleanColumn
public BooleanColumn(String name, BooleanData data)
-
-
Method Detail
-
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
public BooleanColumn 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<Boolean>
-
create
public static BooleanColumn create(String name, Selection hits, int columnSize)
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
public static BooleanColumn create(String name)
Returns a new, empty Boolean column with the given name.- Parameters:
name
- The column name- Returns:
- A new BooleanColumn
-
create
public static BooleanColumn create(String name, int initialSize)
Returns a new Boolean column of the given size.- Parameters:
name
- The column nameinitialSize
- The column size- Returns:
- A new BooleanColumn
-
create
public static BooleanColumn create(String name, boolean... values)
Returns a new Boolean column with the given name and values
-
create
public static BooleanColumn create(String name, Collection<Boolean> values)
Returns a new Boolean column with the given name and values
-
create
public static BooleanColumn create(String name, Boolean[] values)
Returns a new Boolean column with the given name and values
-
create
public static BooleanColumn create(String name, Stream<Boolean> values)
Returns a new Boolean column with the given name and values
-
setPrintFormatter
public void setPrintFormatter(BooleanFormatter formatter)
Sets the print formatter for this column
-
getPrintFormatter
public BooleanFormatter getPrintFormatter()
Returns the print formatter for this column
-
size
public int size()
Returns the number of elements in this column, including missing values
-
summary
public Table 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
public BooleanColumn unique()
Returns a column of the same type containing only the unique values
-
append
public BooleanColumn append(boolean b)
Appends b to the end of this column and returns this column
-
append
public BooleanColumn append(Boolean b)
Appends value to the bottom of this column and return this column
-
appendObj
public BooleanColumn appendObj(Object obj)
Appends the given value to the bottom of this column and return this column
-
append
public BooleanColumn append(byte b)
Appends b to the end of this column and returns this column
-
appendMissing
public BooleanColumn 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
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<Boolean>
-
emptyCopy
public BooleanColumn 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
public BooleanColumn emptyCopy(int rowSize)
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
public BooleanColumn 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
public BooleanColumn appendCell(String object)
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
public BooleanColumn 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 parser- Specified by:
appendCell
in interfaceColumn<Boolean>
-
get
public Boolean get(int i)
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
public Selection isFalse()
- Specified by:
isFalse
in interfaceBooleanFilters
- Specified by:
isFalse
in interfaceBooleanFilterSpec<Selection>
-
isTrue
public Selection isTrue()
- Specified by:
isTrue
in interfaceBooleanFilters
- Specified by:
isTrue
in interfaceBooleanFilterSpec<Selection>
-
isEqualTo
public Selection isEqualTo(BooleanColumn other)
- Specified by:
isEqualTo
in interfaceBooleanFilters
- Specified by:
isEqualTo
in interfaceBooleanFilterSpec<Selection>
-
toByteArrayList
public it.unimi.dsi.fastutil.bytes.ByteArrayList toByteArrayList()
Returns a ByteArrayList containing 0 (false), 1 (true) or Byte.MIN_VALUE (missing)
-
data
public BooleanData data()
-
set
public BooleanColumn set(int i, boolean b)
Sets the value at i to b, and returns this column
-
set
public BooleanColumn set(int i, byte b)
Sets the value at i to b, and returns this column
-
set
public BooleanColumn set(int i, Boolean val)
Sets the value at index row to the given value and return this column
-
set
public BooleanColumn 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
-
lead
public BooleanColumn 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 BooleanColumn 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
-
set
public BooleanColumn set(Selection rowSelection, boolean newValue)
Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria
-
set
public BooleanColumn set(Selection rowSelection, byte newValue)
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
public BooleanColumn append(Column<Boolean> column)
Appends all the values in the argument to the bottom of this column and return this column
-
append
public Column<Boolean> append(Column<Boolean> 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 Column<Boolean> set(int row, Column<Boolean> column, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this column
-
asSelection
public Selection asSelection()
- Specified by:
asSelection
in interfaceBooleanMapUtils
-
isMissing
public Selection 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
public 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>
-
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
public BooleanColumn where(Selection selection)
Returns a new column containing the subset referenced by theSelection
-
removeMissing
public BooleanColumn removeMissing()
Returns a copy of this column with the missing values removed- Specified by:
removeMissing
in interfaceColumn<Boolean>
-
eval
public Selection eval(BytePredicate predicate)
Returns a Selection of the elements that return true when the predicate is evaluated
-
eval
public Selection eval(Predicate<Boolean> predicate)
Returns a Selection of the elements that return true when the predicate is evaluated
-
eval
public Selection eval(BiPredicate<Boolean,Boolean> predicate, Boolean valueToCompare)
Returns a Selection of the elements that return true when the predicate is evaluated with the given Boolean argument
-
asDoubleColumn
public DoubleColumn asDoubleColumn()
Returns a DoubleColumn containing the elements in this column, with true as 1.0 and false as 0.0.
-
compare
public int compare(Boolean o1, Boolean o2)
- Specified by:
compare
in interfaceComparator<Boolean>
-
fillWith
public BooleanColumn fillWith(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
- Specified by:
fillWith
in interfaceBooleanFillers<BooleanColumn>
-
fillWith
public BooleanColumn fillWith(it.unimi.dsi.fastutil.booleans.BooleanIterable iterable)
- Specified by:
fillWith
in interfaceBooleanFillers<BooleanColumn>
-
fillWith
public BooleanColumn fillWith(Supplier<Boolean> supplier)
- Specified by:
fillWith
in interfaceBooleanFillers<BooleanColumn>
-
asObjectArray
public Boolean[] asObjectArray()
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArray
in interfaceColumn<Boolean>
-
trueBytes
public byte[] trueBytes()
Returns a byte representation of the true values, encoded in the format specified inBitSet.toByteArray()
-
falseBytes
public byte[] falseBytes()
Returns a byte representation of the false values, encoded in the format specified inBitSet.toByteArray()
-
missingBytes
public byte[] missingBytes()
Returns a byte representation of the missing values, encoded in the format specified inBitSet.toByteArray()
-
trueBytes
public void trueBytes(byte[] encodedValues)
Sets the true values in the data from a byte[] encoding- Parameters:
encodedValues
- The true values encoded in the format specified inBitSet
-
falseBytes
public void falseBytes(byte[] encodedValues)
Sets the false values in the data from a byte[] encoding- Parameters:
encodedValues
- The false values encoded in the format specified inBitSet
-
missingBytes
public void missingBytes(byte[] encodedValues)
Sets the missing values in the data from a byte[] encoding- Parameters:
encodedValues
- The missing values encoded in the format specified inBitSet
-
-