Class ShortColumn
- java.lang.Object
-
- tech.tablesaw.columns.AbstractColumn<C,T>
-
- tech.tablesaw.api.NumberColumn<ShortColumn,Short>
-
- tech.tablesaw.api.ShortColumn
-
- All Implemented Interfaces:
Iterable<Short>
,Comparator<Short>
,CategoricalColumn<Short>
,NumericColumn<Short>
,Column<Short>
,NumberFilters
,NumberMapFunctions
,FilterSpec<Selection>
,NumberFilterSpec<Selection>
public class ShortColumn extends NumberColumn<ShortColumn,Short> implements CategoricalColumn<Short>
A column that contains short values
-
-
Field Summary
Fields Modifier and Type Field Description protected it.unimi.dsi.fastutil.shorts.ShortArrayList
data
-
Fields inherited from class tech.tablesaw.api.NumberColumn
comparator, locale
-
Fields inherited from class tech.tablesaw.columns.AbstractColumn
DEFAULT_ARRAY_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ShortColumn(String name, it.unimi.dsi.fastutil.shorts.ShortArrayList data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ShortColumn
append(short i)
ShortColumn
append(Short val)
Appends value to the bottom of this column and return this columnShortColumn
append(Column<Short> column)
Appends all the values in the argument to the bottom of this column and return this columnShortColumn
append(Column<Short> column, int row)
Appends the value at the given row in the given column to the bottom of this column and return this columnShortColumn
appendCell(String value)
Add one element to the bottom of this column and set its value to the parsed value of the given String.ShortColumn
appendCell(String value, 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 parserShortColumn
appendMissing()
Appends a missing value appropriate to the columnShortColumn
appendObj(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[].DoubleColumn
asDoubleColumn()
Returns a new DoubleColumn containing a value for each value in this column, truncating if necessary.FloatColumn
asFloatColumn()
Returns a new FloatColumn containing a value for each value in this column, truncating if necessary.IntColumn
asIntColumn()
Returns a new IntColumn containing a value for each value in this columnLongColumn
asLongColumn()
Returns a new LongColumn containing a value for each value in this columnShort[]
asObjectArray()
Returns an array of objects as appropriate for my type of columnSet<Short>
asSet()
Returns a Set containing all the unique values in this columnshort[]
asShortArray()
ShortColumn
bottom(int n)
Returns the smallest ("bottom") n values in the column TODO(lwhite): Consider whether this should exclude missingvoid
clear()
Removes all elements TODO: Make this return this columnint
compare(Short o1, Short o2)
ShortColumn
copy()
Returns a deep copy of the receiverint
countUnique()
Returns the count of unique values in this column.static ShortColumn
create(String name)
static ShortColumn
create(String name, int initialSize)
static ShortColumn
create(String name, short... arr)
static ShortColumn
create(String name, Short[] arr)
static ShortColumn
create(String name, Stream<Short> stream)
ShortColumn
createCol(String name)
ShortColumn
createCol(String name, int initialSize)
ShortColumn
emptyCopy()
Returns a copy of the receiver with no data.ShortColumn
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 rowNumber2Short
get(int index)
Returns the value at the given zero-based indexdouble
getDouble(int row)
Returns a double representation of the number atindex
int
getInt(int row)
Returns the value at the given index.short
getShort(int index)
String
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 appliedSelection
isIn(int... numbers)
boolean
isMissing(int rowNumber)
Returns true if the value at rowNumber is missingboolean
isMissingValue(short value)
Selection
isNotIn(int... numbers)
Iterator<Short>
iterator()
ShortColumn
lag(int n)
Returns a column of the same type and size as the receiver, containing the receivers values offset by n.ShortColumn
removeMissing()
Returns a copy of this column with the missing values removedShortColumn
set(int i, short val)
ShortColumn
set(int i, Short val)
Sets the value at index row to the given value and return this columnColumn<Short>
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 columnShortColumn
set(int row, Column<Short> column, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this columnShortColumn
setMissing(int i)
Sets the value at index i to the missing-value indicator for this column type, and return 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 orderShortColumn
subset(int[] rows)
Return a column of the same type containing just those elements whose indexes are included in the given arrayShortColumn
top(int n)
Returns the largest ("top") n values in the column TODO(lwhite): Consider whether this should exclude missingShortColumn
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(int value)
-
Methods inherited from class tech.tablesaw.api.NumberColumn
byteSize, countMissing, getPrintFormatter, rowComparator, set, set, setPrintFormatter, setPrintFormatter
-
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, 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, asList, byteSize, columnWidth, contains, count, count, countMissing, filter, first, indexOf, inRange, last, lastIndexOf, map, map, mapInto, max, max, min, min, name, noneMatch, parser, print, reduce, reduce, rowComparator, 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 java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface tech.tablesaw.columns.numbers.NumberFilters
isBetweenExclusive, isBetweenInclusive, isCloseTo, isEqualTo, isEqualTo, isGreaterThan, isGreaterThan, isGreaterThanOrEqualTo, isGreaterThanOrEqualTo, isLessThan, isLessThan, isLessThanOrEqualTo, isLessThanOrEqualTo, isNegative, isNonNegative, isNotEqualTo, isNotEqualTo, isPositive, isZero
-
Methods inherited from interface tech.tablesaw.columns.numbers.NumberMapFunctions
abs, add, add, add, asPercent, asRatio, bin, cube, cubeRoot, cumMax, cumMin, cumProd, cumSum, difference, divide, divide, divide, log10, log1p, logN, multiply, multiply, multiply, name, neg, normalize, pctChange, power, power, reciprocal, remainder, remainder, round, roundInt, sqrt, square, subtract, subtract, subtract
-
Methods inherited from interface tech.tablesaw.api.NumericColumn
allMatch, anyMatch, asDoubleArray, asShortColumn, asStringColumn, autoCorrelation, autoCorrelation, count, count, eval, eval, geometricMean, interpolate, isEmpty, isIn, isMissing, isNotIn, isNotMissing, kendalls, kurtosis, lead, mapInto, max, max, mean, median, min, min, noneMatch, pctChange, pearsons, percentile, populationVariance, product, quadraticMean, quartile1, quartile3, range, reduce, reduce, rolling, skewness, spearmans, standardDeviation, stats, sum, summarize, summary, sumOfLogs, sumOfSquares, variance, where
-
-
-
-
Constructor Detail
-
ShortColumn
protected ShortColumn(String name, it.unimi.dsi.fastutil.shorts.ShortArrayList data)
-
-
Method Detail
-
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
-
create
public static ShortColumn create(String name)
-
create
public static ShortColumn create(String name, short... arr)
-
create
public static ShortColumn create(String name, int initialSize)
-
create
public static ShortColumn create(String name, Short[] arr)
-
create
public static ShortColumn create(String name, Stream<Short> stream)
-
createCol
public ShortColumn createCol(String name, int initialSize)
- Specified by:
createCol
in classNumberColumn<ShortColumn,Short>
-
createCol
public ShortColumn createCol(String name)
- Specified by:
createCol
in classNumberColumn<ShortColumn,Short>
-
valueIsMissing
public static boolean valueIsMissing(int value)
-
get
public Short get(int index)
Returns the value at the given zero-based index
-
getShort
public short getShort(int index)
-
subset
public ShortColumn subset(int[] rows)
Return a column of the same type containing just those elements whose indexes are included in the given array- Specified by:
subset
in interfaceColumn<Short>
- Overrides:
subset
in classAbstractColumn<ShortColumn,Short>
-
isIn
public Selection isIn(int... numbers)
-
isNotIn
public Selection isNotIn(int... numbers)
-
size
public int size()
Returns the number of elements in this column, including missing values- Specified by:
size
in interfaceColumn<Short>
- Specified by:
size
in interfaceNumberFilters
- Specified by:
size
in interfaceNumberMapFunctions
-
clear
public void clear()
Removes all elements TODO: Make this return this column
-
unique
public ShortColumn unique()
Returns a column of the same type containing only the unique values
-
top
public ShortColumn top(int n)
Returns the largest ("top") n values in the column TODO(lwhite): Consider whether this should exclude missing- Specified by:
top
in classNumberColumn<ShortColumn,Short>
- 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 ShortColumn bottom(int n)
Returns the smallest ("bottom") n values in the column TODO(lwhite): Consider whether this should exclude missing- Specified by:
bottom
in classNumberColumn<ShortColumn,Short>
- 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
-
lag
public ShortColumn 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
-
removeMissing
public ShortColumn removeMissing()
Returns a copy of this column with the missing values removed- Specified by:
removeMissing
in interfaceColumn<Short>
-
append
public ShortColumn append(short i)
-
append
public ShortColumn append(Short val)
Appends value to the bottom of this column and return this column
-
emptyCopy
public ShortColumn emptyCopy()
Returns a copy of the receiver with no data. The column name and type are the same.- Specified by:
emptyCopy
in interfaceColumn<Short>
- Overrides:
emptyCopy
in classNumberColumn<ShortColumn,Short>
- Returns:
- a empty copy of
Column
-
emptyCopy
public ShortColumn emptyCopy(int rowSize)
Returns an empty copy of the receiver, with its internal storage initialized to the given row size.- Specified by:
emptyCopy
in interfaceColumn<Short>
- Overrides:
emptyCopy
in classNumberColumn<ShortColumn,Short>
- Parameters:
rowSize
- the initial row size- Returns:
- a
Column
-
copy
public ShortColumn copy()
Returns a deep copy of the receiver
-
asObjectArray
public Short[] asObjectArray()
Returns an array of objects as appropriate for my type of column- Specified by:
asObjectArray
in interfaceColumn<Short>
-
asShortArray
public short[] asShortArray()
-
compare
public int compare(Short o1, Short o2)
- Specified by:
compare
in interfaceComparator<Short>
-
set
public ShortColumn set(int i, Short val)
Sets the value at index row to the given value and return this column
-
set
public ShortColumn set(int i, short val)
-
set
public Column<Short> 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
-
append
public ShortColumn append(Column<Short> column)
Appends all the values in the argument to the bottom of this column and return this column
-
getString
public String getString(int row)
Returns a string representation of the value at the given row.- Specified by:
getString
in interfaceColumn<Short>
- Overrides:
getString
in classNumberColumn<ShortColumn,Short>
- Parameters:
row
- The index of the row.- Returns:
- value as String
-
append
public ShortColumn append(Column<Short> 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 ShortColumn set(int row, Column<Short> column, int sourceRow)
Sets the value at row to the value at sourceRow in the given column and return this column
-
appendMissing
public ShortColumn appendMissing()
Appends a missing value appropriate to the column- Specified by:
appendMissing
in interfaceColumn<Short>
-
asBytes
public byte[] asBytes(int rowNumber)
Returns the contents of the cell at rowNumber as a byte[].
-
countUnique
public int countUnique()
Returns the count of unique values in this column.- Specified by:
countUnique
in interfaceColumn<Short>
- Returns:
- unique values as int
-
getInt
public int getInt(int row)
Returns the value at the given index. The actual value is returned if the ColumnType is INTEGERReturns the closest
int
to the argument, with ties rounding to positive infinity.Special cases:
Special cases:
- If the argument is NaN, the result is 0.
- If the argument is positive infinity or any value greater than or equal to the value of
Integer.MAX_VALUE
, an error will be thrown
- Parameters:
row
- the index of the value to be rounded to an integer.- Returns:
- the value of the argument rounded to the nearest
int
value. - Throws:
ClassCastException
- if the absolute value of the value to be rounded is too large to be cast to an int
-
getDouble
public double getDouble(int row)
Returns a double representation of the number atindex
- Specified by:
getDouble
in interfaceNumberFilters
- Specified by:
getDouble
in interfaceNumberMapFunctions
- Specified by:
getDouble
in interfaceNumericColumn<Short>
-
isMissingValue
public boolean isMissingValue(short value)
-
isMissing
public boolean isMissing(int rowNumber)
Returns true if the value at rowNumber is missing- Specified by:
isMissing
in interfaceColumn<Short>
- Specified by:
isMissing
in interfaceNumberMapFunctions
-
setMissing
public ShortColumn 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<Short>
-
sortAscending
public void sortAscending()
Sorts my values in ascending order- Specified by:
sortAscending
in interfaceColumn<Short>
-
sortDescending
public void sortDescending()
Sorts my values in descending order- Specified by:
sortDescending
in interfaceColumn<Short>
-
appendObj
public ShortColumn appendObj(Object obj)
Appends the given value to the bottom of this column and return this column
-
appendCell
public ShortColumn appendCell(String value)
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<Short>
-
appendCell
public ShortColumn appendCell(String value, 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<Short>
-
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<Short>
-
asLongColumn
public LongColumn asLongColumn()
Returns a new LongColumn containing a value for each value in this columnA widening primitive conversion from short to long does not lose any information at all; the numeric value is preserved exactly.
A missing value in the receiver is converted to a missing value in the result
- Specified by:
asLongColumn
in interfaceNumericColumn<Short>
-
asFloatColumn
public FloatColumn asFloatColumn()
Returns a new FloatColumn containing a value for each value in this column, truncating if necessary.A widening primitive conversion from an int to a float does not lose information about the overall magnitude of a numeric value. It may, however, result in loss of precision - that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating-point value will be a correctly rounded version of the integer value, using IEEE 754 round-to-nearest mode.
Despite the fact that a loss of precision may occur, a widening primitive conversion never results in a run-time exception.
A missing value in the receiver is converted to a missing value in the result
- Specified by:
asFloatColumn
in interfaceNumericColumn<Short>
-
asDoubleColumn
public DoubleColumn asDoubleColumn()
Returns a new DoubleColumn containing a value for each value in this column, truncating if necessary.A widening primitive conversion from an int to a double does not lose information about the overall magnitude of a numeric value. It may, however, result in loss of precision - that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating-point value will be a correctly rounded version of the integer value, using IEEE 754 round-to-nearest mode.
Despite the fact that a loss of precision may occur, a widening primitive conversion never results in a run-time exception.
A missing value in the receiver is converted to a missing value in the result
- Specified by:
asDoubleColumn
in interfaceNumericColumn<Short>
-
asIntColumn
public IntColumn asIntColumn()
Returns a new IntColumn containing a value for each value in this columnThe exact behavior when overridden depends on the type of the receiver (LongColumn, FloatColumn, etc.)
In this version, the result is a copy of the original
- Specified by:
asIntColumn
in interfaceNumericColumn<Short>
-
-