Class DataLine

java.lang.Object
org.broadinstitute.hellbender.utils.tsv.DataLine

public final class DataLine extends Object
Table data-line string array wrapper.

This wrapper includes convenience methods to get and set(java.lang.String, java.lang.String) values on data-line string array from within record type conversion methods: TableReader.record and TableWriter.composeLine.

Apart for set operations, it includes convenience methods to set column values in order of appearance when this is known using append.

There are various method overloads for type conversion to and from primitive type int and double.

You can use columns() to obtain the corresponding TableColumnCollection and query the presence of and the index of columns.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Constant to indicate that a data-line has no line number assigned.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataLine(long lineNumber, TableColumnCollection columns, Function<String,RuntimeException> formatErrorFactory)
    Creates a new data-line instance.
    Creates a new data-line instance with no line-number.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(double value)
    Sets the next double value in the data-line that correspond to a column.
    append(double... values)
    Sets the next double values in the data-line that correspond to next few columns.
    append(int value)
    Sets the next int value in the data-line that correspond to a column.
    append(int... values)
    Sets the next int values in the data-line that correspond to next few columns.
    append(long value)
    Sets the next long value in the data-line that correspond to a column.
    append(long... values)
    Sets the next long values in the data-line that correspond to next few columns.
    append(String value)
    Sets the next string value in the data-line that correspond to a column.
    append(String... values)
    Sets the next string values in the data-line that correspond to next few columns.
    Returns the column collection for this data-line instance.
    get()
     
    get(int index)
    Returns the string value in a column by its index.
    get(Enum<?> column)
    Returns the string value of a column by its name.
    get(String columnName)
    Returns the string value in a column by its index.
    get(String columnName, String defaultValue)
    Returns the string value in a column by its index.
    boolean
    getBoolean(int index)
    Returns the boolean value in a column by its index.
    boolean
    getBoolean(String columnName)
    Returns the boolean value in a column by its index.
    byte
    Returns the byte value in a column at the current column index and advance it.
    byte
    getByte(int index)
     
    byte
    getByte(String column)
    Returns the byte value of a column by its name.
    double
    getDouble(int index)
    Returns the double value in a column by its index.
    double
    getDouble(int index, Function<String,RuntimeException> formatErrorFactory)
    Returns the double value in a column by its index.
    double
    getDouble(Enum<?> column)
    Returns the double value of a column by its name.
    double
    getDouble(String columnName)
    Returns the double value in a column by its index.
    int
    Returns the int value in a column at the current column index and advance it.
    int
    getInt(int index)
    Returns the int value in a column by its index.
    int
    getInt(Enum<?> column)
    Returns the int value of a column by its name.
    int
    getInt(String columnName)
    Returns the int value in a column by its index.
    long
    Returns the line number for this data-line.
    long
     
    long
    getLong(int index)
    Returns the long value in a column by its index.
    long
    getLong(Enum<?> column)
    Returns the long value in a column by its name expressed as an enum constant.
    long
    getLong(String columnName)
    Returns the long value in a column by its index.
    seek(int index)
    Changes the index of the next value to set using append operations.
    seek(Enum<?> column)
    Changes the index of the next value to set using append operations.
    seek(String columnName)
    Changes the index of the next value to set using append operations.
    set(int index, double value)
    Sets the value for a column to a double given its index.
    set(int index, double value, int numDecimals)
    Sets the value for a column to a double given its index.
    set(int index, int value)
    Sets the int value of a column given its index.
    set(int index, long value)
    Sets the long value of a column given its index.
    set(int index, String value)
    Sets the string value of a column given its index.
    set(String name, boolean value)
    Sets the boolean value in the data-line that correspond to a column by its name.
    set(String name, double value)
    Sets the double value in the data-line that correspond to a column by its name.
    set(String name, double value, int numDecimals)
    Sets the double value in the data-line that correspond to a column by its name.
    set(String name, int value)
    Sets the int value in the data-line that correspond to a column by its name.
    set(String name, long value)
    Sets the long value in the data-line that correspond to a column by its name.
    set(String name, String value)
    Sets the string value in the data-line that correspond to a column by its name.
    setAll(String... values)
    Sets all the data-line values at once.
    Returns the current values in a string array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NO_LINE_NUMBER

      public static final long NO_LINE_NUMBER
      Constant to indicate that a data-line has no line number assigned.
      See Also:
  • Constructor Details

    • DataLine

      public DataLine(long lineNumber, TableColumnCollection columns, Function<String,RuntimeException> formatErrorFactory)
      Creates a new data-line instance.
      Parameters:
      lineNumber - the line number for this data-line, NO_LINE_NUMBER when this is unspecified.
      columns - the columns of the table that will enclose this data-line instance.
      formatErrorFactory - to be used when there is a column formatting error based on the requested data-type.
      Throws:
      IllegalArgumentException - if columns or formatErrorFactory are null.
    • DataLine

      public DataLine(TableColumnCollection columns, Function<String,RuntimeException> formatErrorFactory)
      Creates a new data-line instance with no line-number.
      Parameters:
      columns - the columns of the table that will enclose this data-line instance.
      formatErrorFactory - to be used when there is a column formatting error based on the requested data-type.
      Throws:
      IllegalArgumentException - if columns or formatErrorFactory are null.
  • Method Details

    • columns

      public TableColumnCollection columns()
      Returns the column collection for this data-line instance.
      Returns:
      never null.
    • set

      public DataLine set(String name, String value)
      Sets the string value in the data-line that correspond to a column by its name.
      Parameters:
      name - the column name.
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if name is null or it does not match an actual column name.
    • set

      public DataLine set(String name, boolean value)
      Sets the boolean value in the data-line that correspond to a column by its name.
      Parameters:
      name - the column name.
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if name is null or it does not match an actual column name.
    • set

      public DataLine set(String name, int value)
      Sets the int value in the data-line that correspond to a column by its name.
      Parameters:
      name - the column name.
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if name is null or it does not match an actual column name.
    • set

      public DataLine set(String name, long value)
      Sets the long value in the data-line that correspond to a column by its name.
      Parameters:
      name - the column name.
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if name is null or it does not match an actual column name.
    • set

      public DataLine set(String name, double value)
      Sets the double value in the data-line that correspond to a column by its name.
      Parameters:
      name - the column name.
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if name is null or it does not match an actual column name.
    • set

      public DataLine set(String name, double value, int numDecimals)
      Sets the double value in the data-line that correspond to a column by its name.
      Parameters:
      name - the column name.
      value - the new value.
      numDecimals - the number of decimals to print
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if name is null or it does not match an actual column name.
    • set

      public DataLine set(int index, String value)
      Sets the string value of a column given its index.
      Parameters:
      index - the target column index.
      value - the new value for that column.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if index is not a valid column index.
    • set

      public DataLine set(int index, int value)
      Sets the int value of a column given its index.
      Parameters:
      index - the target column index.
      value - the new value for that column.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if index is not a valid column index.
    • set

      public DataLine set(int index, long value)
      Sets the long value of a column given its index.
      Parameters:
      index - the target column index.
      value - the new value for that column.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if index is not a valid column index.
    • set

      public DataLine set(int index, double value)
      Sets the value for a column to a double given its index.
      Parameters:
      index - the target column index.
      value - the new value for that column.
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if index is not a valid column index.
    • set

      public DataLine set(int index, double value, int numDecimals)
      Sets the value for a column to a double given its index.
      Parameters:
      index - the target column index.
      value - the new value for that column.
      numDecimals - the number of decimal places to print
      Returns:
      reference to this data-line.
      Throws:
      IllegalArgumentException - if index is not a valid column index.
    • get

      public String get(int index)
      Returns the string value in a column by its index.
      Parameters:
      index - target column index.
      Returns:
      never null.
      Throws:
      IllegalArgumentException - if index is not a valid column index.
      IllegalStateException - if the value for that column is undefined (null).
    • get

      public String get()
    • getInt

      public int getInt(int index)
      Returns the int value in a column by its index.
      Parameters:
      index - the target column index.
      Returns:
      any int value.
      Throws:
      IllegalArgumentException - if index is not valid.
      IllegalStateException - if index has not been initialized and contains a null.
      RuntimeException - if the value at that target column cannot be transform into an integer. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getInt

      public int getInt()
      Returns the int value in a column at the current column index and advance it.
      Returns:
      any int value.
      Throws:
      IllegalStateException - if the current column has not been initialized and contains a null.
      RuntimeException - if the value at that target column cannot be transformed into an integer. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getLong

      public long getLong(int index)
      Returns the long value in a column by its index.
      Parameters:
      index - the target column index.
      Returns:
      any long value.
      Throws:
      IllegalArgumentException - if index is not valid.
      IllegalStateException - if index has not been initialized and contains a null.
      RuntimeException - if the value at that target column cannot be transform into a long. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getLong

      public long getLong()
    • getBoolean

      public boolean getBoolean(int index)
      Returns the boolean value in a column by its index.
      Parameters:
      index - the target column index.
      Returns:
      any boolean value.
      Throws:
      IllegalArgumentException - if index is not valid.
      IllegalStateException - if index has not been initialized and contains a null.
      RuntimeException - if the value at that target column cannot be transform into a boolean. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getDouble

      public double getDouble(int index)
      Returns the double value in a column by its index.
      Parameters:
      index - the target column index.
      Returns:
      any double value.
      Throws:
      IllegalArgumentException - if index is not valid.
      IllegalStateException - if index has not been initialized and contains a null.
      RuntimeException - if the value at that target column cannot be transform into a double. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getDouble

      public double getDouble(int index, Function<String,RuntimeException> formatErrorFactory)
      Returns the double value in a column by its index.
      Parameters:
      index - the target column index.
      formatErrorFactory - format error factory.
      Returns:
      any double value.
      Throws:
      IllegalArgumentException - if index is not valid.
      IllegalStateException - if index has not been initialized and contains a null.
      RuntimeException - if the value at that target column cannot be transform into a double. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • get

      public String get(String columnName)
      Returns the string value in a column by its index.
      Parameters:
      columnName - the target column name.
      Returns:
      never null.
      Throws:
      IllegalArgumentException - if columnName is null or an unknown column name.
      IllegalStateException - if that column values is undefined (null).
    • get

      public String get(String columnName, String defaultValue)
      Returns the string value in a column by its index. If column name does not exist, returns the default value.
      Parameters:
      columnName - the target column name.
      defaultValue - default value to use if columnName not found.
      Returns:
      null iff defaultValue == null and there is not such a column with name columnName.
    • getInt

      public int getInt(String columnName)
      Returns the int value in a column by its index.
      Parameters:
      columnName - the target column name.
      Returns:
      any int value.
      Throws:
      IllegalArgumentException - if columnName is null or an unknown column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into an integer. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getLong

      public long getLong(String columnName)
      Returns the long value in a column by its index.
      Parameters:
      columnName - the target column name.
      Returns:
      any long value.
      Throws:
      IllegalArgumentException - if columnName is null or an unknown column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a long. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getLong

      public long getLong(Enum<?> column)
      Returns the long value in a column by its name expressed as an enum constant.
      Parameters:
      column - the target column name.
      Returns:
      any long value.
      Throws:
      IllegalArgumentException - if column is null or an unknown column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a long. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getBoolean

      public boolean getBoolean(String columnName)
      Returns the boolean value in a column by its index.
      Parameters:
      columnName - the target column name.
      Returns:
      any boolean value.
      Throws:
      IllegalArgumentException - if columnName is null or an unknown column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a boolean. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getDouble

      public double getDouble(String columnName)
      Returns the double value in a column by its index.
      Parameters:
      columnName - the target column name.
      Returns:
      any double value.
      Throws:
      IllegalArgumentException - if columnName is null or an unknown column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a double. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • get

      public String get(Enum<?> column)
      Returns the string value of a column by its name.

      The target column name is resolved as the string returned by toString applied to the input enum.

      Parameters:
      column - the enum value that provides the name of the column.
      Returns:
      never null.
      Throws:
      IllegalArgumentException - if column is null or it does not point to a known column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a double. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getInt

      public int getInt(Enum<?> column)
      Returns the int value of a column by its name.

      The target column name is resolved as the string returned by toString applied to the input enum.

      Parameters:
      column - the enum value that provides the name of the column.
      Returns:
      any int value.
      Throws:
      IllegalArgumentException - if column is null or it does not point to a known column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a double. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getDouble

      public double getDouble(Enum<?> column)
      Returns the double value of a column by its name.

      The target column name is resolved as the string returned by toString applied to the input enum.

      Parameters:
      column - the enum value that provides the name of the column.
      Returns:
      any double value.
      Throws:
      IllegalArgumentException - if column is null or it does not point to a known column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a double. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • append

      public DataLine append(String value)
      Sets the next string value in the data-line that correspond to a column.

      The next column index advances so that the following append operations will change the value of the following columns and so forth.

      Parameters:
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if the next column to set is beyond the last column.
    • append

      public DataLine append(int value)
      Sets the next int value in the data-line that correspond to a column.

      The next column index advances so that the following append will change the value of the following column and so forth.

      Parameters:
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if the next column to set is beyond the last column.
    • append

      public DataLine append(long value)
      Sets the next long value in the data-line that correspond to a column.

      The next column index advances so that the following append will change the value of the following column and so forth.

      Parameters:
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if the next column to set is beyond the last column.
    • append

      public DataLine append(long... values)
      Sets the next long values in the data-line that correspond to next few columns.

      The next column index advances so that the following append will change the value of the following column and so forth.

      Parameters:
      values - the new values.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if this operation goes beyond the last column index.
    • append

      public DataLine append(double value)
      Sets the next double value in the data-line that correspond to a column.

      The next column index advances so that the following append will change the value of the following column and so forth.

      Parameters:
      value - the new value.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if the next column to set is beyond the last column.
    • append

      public DataLine append(int... values)
      Sets the next int values in the data-line that correspond to next few columns.

      The next column index advances so that the following append will change the value of the following column and so forth.

      Parameters:
      values - the new values.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if this operation goes beyond the last column index.
    • append

      public DataLine append(String... values)
      Sets the next string values in the data-line that correspond to next few columns.

      The next column index advances so that the following append will change the value of the following column and so forth.

      Parameters:
      values - the new values.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if this operation goes beyond the last column index.
    • append

      public DataLine append(double... values)
      Sets the next double values in the data-line that correspond to next few columns.

      The next column index advances so that the following append will change the value of the following column and so forth.

      Parameters:
      values - the new values.
      Returns:
      reference to this data-line.
      Throws:
      IllegalStateException - if this operation goes beyond the last column index.
    • setAll

      public DataLine setAll(String... values)
      Sets all the data-line values at once.
      Parameters:
      values - the new values.
      Returns:
      a reference to this data-line.
      Throws:
      IllegalArgumentException - if values is null, its length does not match this data-line column count, or the first element starts like a comment line.
    • seek

      public DataLine seek(int index)
      Changes the index of the next value to set using append operations.
      Parameters:
      index - the new index.
      Returns:
      a reference to this data-line.
      Throws:
      IllegalArgumentException - if index is greater than the number of columns
    • seek

      public DataLine seek(String columnName)
      Changes the index of the next value to set using append operations.
      Parameters:
      columnName - the name of the column to seek to.
      Returns:
      a reference to this data-line.
      Throws:
      IllegalArgumentException - if columnName is null or an unknown column name.
    • seek

      public DataLine seek(Enum<?> column)
      Changes the index of the next value to set using append operations.

      The input enum's string conversion using toString determines the name of the target column.

      Parameters:
      column - the enum value that makes reference to the target column.
      Throws:
      IllegalArgumentException - if column is null or does not make reference to a known column.
    • toArray

      public String[] toArray()
      Returns the current values in a string array.

      The returned array is a copy that can be modified without changing the state of the data line.

      Returns:
      never null, but it can contain nulls.
    • getLineNumber

      public long getLineNumber()
      Returns the line number for this data-line.

      NO_LINE_NUMBER

      must be used to mark data-lines that do not have a line number assigned, e.g. because the actually aren't part of a file.
      Returns:
      any long value.
    • getByte

      public byte getByte(int index)
      Parameters:
      index -
      Returns:
    • getByte

      public byte getByte(String column)
      Returns the byte value of a column by its name.

      The target column name is resolved as the string returned by toString applied to the input enum.

      Parameters:
      column - the enum value that provides the name of the column.
      Returns:
      any int value.
      Throws:
      IllegalArgumentException - if column is null or it does not point to a known column name.
      IllegalStateException - if that column values is undefined (null).
      RuntimeException - if the value at that target column cannot be transform into a byte. The exact class of the exception will depend on the exception factory provided when creating this DataLine.
    • getByte

      public byte getByte()
      Returns the byte value in a column at the current column index and advance it.
      Returns:
      any byte value.
      Throws:
      IllegalStateException - if the current column has not been initialized and contains a null.
      RuntimeException - if the value at that target column cannot be transformed into a byte. The exact class of the exception will depend on the exception factory provided when creating this DataLine.