Class StringColumn

    • Method Detail

      • valueIsMissing

        public static boolean valueIsMissing​(String string)
      • valueHash

        public int valueHash​(int rowNumber)
        Returns an int suitable as a hash for the value in this column at the given index
        Specified by:
        valueHash in interface Column<String>
      • 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
        Specified by:
        equals in interface Column<String>
      • setPrintFormatter

        public void setPrintFormatter​(StringColumnFormatter formatter)
        Sets an StringColumnFormatter which will be used to format the display of data from this column when it is printed (using, for example, Table:print()) and optionally when written to a text file like a CSV.
      • isMissing

        public boolean isMissing​(int rowNumber)
        Returns true if the value at rowNumber is missing
        Specified by:
        isMissing in interface Column<String>
      • emptyCopy

        public StringColumn emptyCopy​(int rowSize)
        Returns an empty copy of the receiver, with its internal storage initialized to the given row size.
        Specified by:
        emptyCopy in interface Column<String>
        Parameters:
        rowSize - the initial row size
        Returns:
        a Column
      • sortAscending

        public void sortAscending()
        Sorts my values in ascending order
        Specified by:
        sortAscending in interface Column<String>
      • sortDescending

        public void sortDescending()
        Sorts my values in descending order
        Specified by:
        sortDescending in interface Column<String>
      • get

        public String get​(int rowIndex)
        Returns the value at rowIndex in this column. The index is zero-based.
        Specified by:
        get in interface Column<String>
        Specified by:
        get in interface StringFilters
        Parameters:
        rowIndex - index of the row
        Returns:
        value as String
        Throws:
        IndexOutOfBoundsException - if the given rowIndex is not in the column
      • asList

        public List<String> asList()
        Returns a List<String> representation of all the values in this column

        NOTE: Unless you really need a string consider using the column itself for large datasets as it uses much less memory

        Specified by:
        asList in interface Column<String>
        Returns:
        values as a list of String.
      • summary

        public Table summary()
        Returns a table containing a ColumnType specific summary of the data in this column
        Specified by:
        summary in interface Column<String>
      • countByCategory

        public Table countByCategory()
        Returns a count of the number of elements in each category (i.e., the number of repetitions of each value) TODO: This needs to be well tested, especially for IntColumn
        Specified by:
        countByCategory in interface CategoricalColumn<String>
      • clear

        public void clear()
        Removes all elements TODO: Make this return this column
        Specified by:
        clear in interface Column<String>
      • lead

        public StringColumn 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.
        Specified by:
        lead in interface Column<String>
      • lag

        public StringColumn 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

        Specified by:
        lag in interface Column<String>
      • set

        public StringColumn set​(Selection rowSelection,
                                String newValue)
        Conditionally update this column, replacing current values with newValue for all rows where the current value matches the selection criteria

        Examples: myCatColumn.set(myCatColumn.isEqualTo("Cat"), "Dog"); // no more cats myCatColumn.set(myCatColumn.valueIsMissing(), "Fox"); // no more missing values

        Specified by:
        set in interface Column<String>
        Overrides:
        set in class AbstractColumn<StringColumn,​String>
      • set

        public StringColumn set​(int rowIndex,
                                String stringValue)
        Sets the value at index row to the given value and return this column
        Specified by:
        set in interface Column<String>
      • countUnique

        public int countUnique()
        Returns the count of unique values in this column.
        Specified by:
        countUnique in interface Column<String>
        Returns:
        unique values as int
      • contains

        public boolean contains​(String aString)
        Returns true if this column contains a cell with the given string, and false otherwise
        Specified by:
        contains in interface Column<String>
        Parameters:
        aString - the value to look for
        Returns:
        true if contains, false otherwise
      • setMissing

        public StringColumn 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 interface Column<String>
      • addAll

        public StringColumn addAll​(List<String> stringValues)
        Add all the strings in the list to this column
        Parameters:
        stringValues - a list of values
      • appendCell

        public StringColumn 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 interface Column<String>
      • rowComparator

        public it.unimi.dsi.fastutil.ints.IntComparator rowComparator()
        Returns an IntComparator for sorting my rows
        Specified by:
        rowComparator in interface Column<String>
      • isEmpty

        public boolean isEmpty()
        Returns true if the column has no data
        Specified by:
        isEmpty in interface Column<String>
        Returns:
        true if empty, false if not
      • getDummies

        public List<BooleanColumn> getDummies()
        Returns a list of boolean columns suitable for use as dummy variables in, for example, regression analysis, select a column of categorical data must be encoded as a list of columns, such that each column represents a single category and indicates whether it is present (1) or not present (0)
        Returns:
        a list of BooleanColumn
      • unique

        public StringColumn unique()
        Returns a new Column containing all the unique values in this column
        Specified by:
        unique in interface Column<String>
        Returns:
        a column with unique values.
      • countMissing

        public int countMissing()
        Returns the count of missing values in this column
        Specified by:
        countMissing in interface Column<String>
        Returns:
        missing values as int
      • asSet

        public Set<String> asSet()
        Description copied from interface: Column
        Returns a Set containing all the unique values in this column
        Specified by:
        asSet in interface Column<String>
      • asBytes

        public byte[] asBytes​(int rowNumber)
        Returns the contents of the cell at rowNumber as a byte[]
        Specified by:
        asBytes in interface Column<String>
        Parameters:
        rowNumber - index of the row
        Returns:
        content as byte[]
      • getDouble

        public double getDouble​(int i)
      • asDoubleArray

        public double[] asDoubleArray()
      • firstIndexOf

        public int firstIndexOf​(String value)
      • countOccurrences

        public int countOccurrences​(String value)
      • asObjectArray

        public String[] asObjectArray()
        Returns an array of objects as appropriate for my type of column
        Specified by:
        asObjectArray in interface Column<String>
      • getDictionary

        @Nullable
        public DictionaryMap getDictionary()
        For tablesaw internal use Note: This method returns null if the stringDataType is TEXTUAL
      • getString

        public String getString​(int row)
        Returns a string representation of the value at the given row.
        Specified by:
        getString in interface Column<String>
        Specified by:
        getString in interface StringMapFunctions
        Parameters:
        row - The index of the row.
        Returns:
        value as String
      • getUnformattedString

        public String getUnformattedString​(int row)
        Returns a String representation of the value at index r, without any formatting applied
        Specified by:
        getUnformattedString in interface Column<String>
      • top

        public List<String> top​(int n)
        Returns the largest ("top") n values in the column
        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 List<String> bottom​(int n)
        Returns the smallest ("bottom") n values in the column
        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
      • append

        public Column<String> append​(Column<String> column,
                                     int row)
        Appends the value at the given row in the given column to the bottom of this column and return this column
        Specified by:
        append in interface Column<String>
      • set

        public Column<String> set​(int row,
                                  Column<String> column,
                                  int sourceRow)
        Sets the value at row to the value at sourceRow in the given column and return this column
        Specified by:
        set in interface Column<String>
      • byteSize

        public int byteSize()
        Returns the width of a cell in this column, in bytes.
        Specified by:
        byteSize in interface Column<String>
        Returns:
        width in bytes