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 booleanall()Returns true if the column contains only true values, and false otherwise.booleanany()Returns true if the column contains any true values, and false otherwiseBooleanColumnappend(boolean b)Appends b to the end of this column and returns this columnBooleanColumnappend(byte b)Appends b to the end of this column and returns this columnBooleanColumnappend(Boolean b)Appends value to the bottom of this column and return this columnBooleanColumnappend(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 columnBooleanColumnappendCell(String object)Add one element to the bottom of this column and set its value to the parsed value of the given String.BooleanColumnappendCell(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 parserBooleanColumnappendMissing()Appends a missing value appropriate to the columnBooleanColumnappendObj(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.0DoubleColumnasDoubleColumn()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 columnSelectionasSelection()it.unimi.dsi.fastutil.booleans.BooleanSetasSet()Returns the values in this column as a BooleanSet instanceit.unimi.dsi.fastutil.bytes.ByteIteratorbyteIterator()Returns a ByteIterator for this columnintbyteSize()Returns the width of a cell in this column, in bytes.voidclear()Removes all elements TODO: Make this return this columnintcompare(Boolean o1, Boolean o2)booleancontains(boolean aBoolean)Returns true if the column contains at least one value likeaBooleanBooleanColumncopy()Returns a deep copy of the receiverintcountFalse()Returns the number offalseelements in this columnintcountMissing()Returns the count of missing values in this columnintcountTrue()Returns the number oftrueelements in this columnintcountUnique()Returns the count of unique values in this column.static BooleanColumncreate(String name)Returns a new, empty Boolean column with the given name.static BooleanColumncreate(String name, boolean... values)Returns a new Boolean column with the given name and valuesstatic BooleanColumncreate(String name, int initialSize)Returns a new Boolean column of the given size.static BooleanColumncreate(String name, Boolean[] values)Returns a new Boolean column with the given name and valuesstatic BooleanColumncreate(String name, Collection<Boolean> values)Returns a new Boolean column with the given name and valuesstatic BooleanColumncreate(String name, Stream<Boolean> values)Returns a new Boolean column with the given name and valuesstatic BooleanColumncreate(String name, Selection hits, int columnSize)Returns a new Boolean column of the given size.BooleanDatadata()BooleanColumnemptyCopy()Returns a copy of the receiver with no data.BooleanColumnemptyCopy(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 rowNumber2Selectioneval(BiPredicate<Boolean,Boolean> predicate, Boolean valueToCompare)Returns a Selection of the elements that return true when the predicate is evaluated with the given Boolean argumentSelectioneval(Predicate<Boolean> predicate)Returns a Selection of the elements that return true when the predicate is evaluatedSelectioneval(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()voidfalseBytes(byte[] encodedValues)Sets the false values in the data from a byte[] encodingBooleanColumnfillWith(it.unimi.dsi.fastutil.booleans.BooleanIterable iterable)BooleanColumnfillWith(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)BooleanColumnfillWith(Supplier<Boolean> supplier)Booleanget(int i)Returns the value in row i as a BooleanbytegetByte(int i)Returns the value in row i as a byte (0, 1, or Byte.MIN_VALUE representing missing data)doublegetDouble(int row)Returns the value at row as a double, with true values encoded as 1.0 and false values as 0.0BooleanFormattergetPrintFormatter()Returns the print formatter for this columnStringgetString(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 dataSelectionisEqualTo(BooleanColumn other)SelectionisFalse()SelectionisMissing()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 columnSelectionisTrue()Iterator<Boolean>iterator()BooleanColumnlag(int n)Returns a column of the same type and size as the receiver, containing the receivers values offset by n.BooleanColumnlead(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()voidmissingBytes(byte[] encodedValues)Sets the missing values in the data from a byte[] encodingbooleannone()Returns true if the column contains no true values, and false otherwisedoubleproportionFalse()Returns the proportion of non-missing row elements that contain falsedoubleproportionTrue()Returns the proportion of non-missing row elements that contain trueBooleanColumnremoveMissing()Returns a copy of this column with the missing values removedit.unimi.dsi.fastutil.ints.IntComparatorrowComparator()Returns an IntComparator for sorting my rowsBooleanColumnset(int i, boolean b)Sets the value at i to b, and returns this columnBooleanColumnset(int i, byte b)Sets the value at i to b, and returns this columnBooleanColumnset(int i, Boolean val)Sets the value at index row to the given value and return this columnBooleanColumnset(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 columnBooleanColumnset(Selection rowSelection, boolean newValue)Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteriaBooleanColumnset(Selection rowSelection, byte newValue)Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria.BooleanColumnsetMissing(int i)Sets the value at index i to the missing-value indicator for this column type, and return this columnvoidsetPrintFormatter(BooleanFormatter formatter)Sets the print formatter for this columnintsize()Returns the number of elements in this column, including missing valuesvoidsortAscending()Sorts my values in ascending ordervoidsortDescending()Sorts my values in descending orderTablesummary()Returns a table containing a ColumnType specific summary of the data in this columnit.unimi.dsi.fastutil.bytes.ByteArrayListtoByteArrayList()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()voidtrueBytes(byte[] encodedValues)Sets the true values in the data from a byte[] encodingBooleanColumnunique()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(byte b)Returnstrueif b is the missing value indicator for this column typeBooleanColumnwhere(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)
Returnstrueif 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:
setMissingin 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:
countMissingin interfaceColumn<Boolean>- Returns:
- missing values as int
-
countUnique
public int countUnique()
Returns the count of unique values in this column.- Specified by:
countUniquein 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:
appendMissingin 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:
getUnformattedStringin 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:
emptyCopyin interfaceColumn<Boolean>- Specified by:
emptyCopyin 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:
sortAscendingin interfaceColumn<Boolean>
-
sortDescending
public void sortDescending()
Sorts my values in descending order- Specified by:
sortDescendingin 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:
appendCellin 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:
appendCellin 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 oftrueelements in this column
-
countFalse
public int countFalse()
Returns the number offalseelements 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:
isFalsein interfaceBooleanFilters- Specified by:
isFalsein interfaceBooleanFilterSpec<Selection>
-
isTrue
public Selection isTrue()
- Specified by:
isTruein interfaceBooleanFilters- Specified by:
isTruein interfaceBooleanFilterSpec<Selection>
-
isEqualTo
public Selection isEqualTo(BooleanColumn other)
- Specified by:
isEqualToin interfaceBooleanFilters- Specified by:
isEqualToin 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:
rowComparatorin 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:
asSelectionin interfaceBooleanMapUtils
-
isMissing
public Selection isMissing()
Returns a selection containing an index for every missing value in this column- Specified by:
isMissingin interfaceBooleanFilters- Specified by:
isMissingin interfaceColumn<Boolean>- Specified by:
isMissingin interfaceFilterSpec<Selection>
-
isNotMissing
public Selection isNotMissing()
Returns a selection containing an index for every non-missing value in this column- Specified by:
isNotMissingin interfaceBooleanFilters- Specified by:
isNotMissingin interfaceColumn<Boolean>- Specified by:
isNotMissingin 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:
removeMissingin 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:
comparein interfaceComparator<Boolean>
-
fillWith
public BooleanColumn fillWith(it.unimi.dsi.fastutil.booleans.BooleanIterator iterator)
- Specified by:
fillWithin interfaceBooleanFillers<BooleanColumn>
-
fillWith
public BooleanColumn fillWith(it.unimi.dsi.fastutil.booleans.BooleanIterable iterable)
- Specified by:
fillWithin interfaceBooleanFillers<BooleanColumn>
-
fillWith
public BooleanColumn fillWith(Supplier<Boolean> supplier)
- Specified by:
fillWithin interfaceBooleanFillers<BooleanColumn>
-
asObjectArray
public Boolean[] asObjectArray()
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArrayin 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
-
-