Class DataLine
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
FieldsModifier and TypeFieldDescriptionstatic final long
Constant to indicate that a data-line has no line number assigned. -
Constructor Summary
ConstructorsConstructorDescriptionDataLine
(long lineNumber, TableColumnCollection columns, Function<String, RuntimeException> formatErrorFactory) Creates a new data-line instance.DataLine
(TableColumnCollection columns, Function<String, RuntimeException> formatErrorFactory) Creates a new data-line instance with no line-number. -
Method Summary
Modifier and TypeMethodDescriptionappend
(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.Sets the next string value in the data-line that correspond to a column.Sets the next string values in the data-line that correspond to next few columns.columns()
Returns the column collection for this data-line instance.get()
get
(int index) Returns the string value in a column by its index.Returns the string value of a column by its name.Returns the string value in a column by its index.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
getByte()
Returns the byte value in a column at the current column index and advance it.byte
getByte
(int index) byte
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
Returns the double value of a column by its name.double
Returns the double value in a column by its index.int
getInt()
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
Returns the int value of a column by its name.int
Returns the int value in a column by its index.long
Returns the line number for this data-line.long
getLong()
long
getLong
(int index) Returns the long value in a column by its index.long
Returns the long value in a column by its name expressed as an enum constant.long
Returns the long value in a column by its index.seek
(int index) Changes the index of the next value to set usingappend
operations.Changes the index of the next value to set usingappend
operations.Changes the index of the next value to set usingappend
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.Sets the string value of a column given its index.Sets the boolean value in the data-line that correspond to a column by its name.Sets the double value in the data-line that correspond to a column by its name.Sets the double value in the data-line that correspond to a column by its name.Sets the int value in the data-line that correspond to a column by its name.Sets the long value in the data-line that correspond to a column by its name.Sets the string value in the data-line that correspond to a column by its name.Sets all the data-line values at once.String[]
toArray()
Returns the current values in a string array.
-
Field Details
-
NO_LINE_NUMBER
public static final long NO_LINE_NUMBERConstant 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
- ifcolumns
orformatErrorFactory
arenull
.
-
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
- ifcolumns
orformatErrorFactory
arenull
.
-
-
Method Details
-
columns
Returns the column collection for this data-line instance.- Returns:
- never
null
.
-
set
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
- ifname
isnull
or it does not match an actual column name.
-
set
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
- ifname
isnull
or it does not match an actual column name.
-
set
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
- ifname
isnull
or it does not match an actual column name.
-
set
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
- ifname
isnull
or it does not match an actual column name.
-
set
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
- ifname
isnull
or it does not match an actual column name.
-
set
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
- ifname
isnull
or it does not match an actual column name.
-
set
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
- ifindex
is not a valid column index.
-
set
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
- ifindex
is not a valid column index.
-
set
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
- ifindex
is not a valid column index.
-
set
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
- ifindex
is not a valid column index.
-
set
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
- ifindex
is not a valid column index.
-
get
Returns the string value in a column by its index.- Parameters:
index
- target column index.- Returns:
- never
null
. - Throws:
IllegalArgumentException
- ifindex
is not a valid column index.IllegalStateException
- if the value for that column is undefined (null
).
-
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
- ifindex
is not valid.IllegalStateException
- ifindex
has not been initialized and contains anull
.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 thisDataLine
.
-
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 anull
.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 thisDataLine
.
-
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
- ifindex
is not valid.IllegalStateException
- ifindex
has not been initialized and contains anull
.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 thisDataLine
.
-
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
- ifindex
is not valid.IllegalStateException
- ifindex
has not been initialized and contains anull
.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 thisDataLine
.
-
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
- ifindex
is not valid.IllegalStateException
- ifindex
has not been initialized and contains anull
.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 thisDataLine
.
-
getDouble
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
- ifindex
is not valid.IllegalStateException
- ifindex
has not been initialized and contains anull
.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 thisDataLine
.
-
get
Returns the string value in a column by its index.- Parameters:
columnName
- the target column name.- Returns:
- never
null
. - Throws:
IllegalArgumentException
- ifcolumnName
isnull
or an unknown column name.IllegalStateException
- if that column values is undefined (null
).
-
get
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
iffdefaultValue == null
and there is not such a column with namecolumnName
.
-
getInt
Returns the int value in a column by its index.- Parameters:
columnName
- the target column name.- Returns:
- any int value.
- Throws:
IllegalArgumentException
- ifcolumnName
isnull
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 thisDataLine
.
-
getLong
Returns the long value in a column by its index.- Parameters:
columnName
- the target column name.- Returns:
- any long value.
- Throws:
IllegalArgumentException
- ifcolumnName
isnull
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 thisDataLine
.
-
getLong
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
- ifcolumn
isnull
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 thisDataLine
.
-
getBoolean
Returns the boolean value in a column by its index.- Parameters:
columnName
- the target column name.- Returns:
- any boolean value.
- Throws:
IllegalArgumentException
- ifcolumnName
isnull
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 thisDataLine
.
-
getDouble
Returns the double value in a column by its index.- Parameters:
columnName
- the target column name.- Returns:
- any double value.
- Throws:
IllegalArgumentException
- ifcolumnName
isnull
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 thisDataLine
.
-
get
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
- ifcolumn
isnull
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 thisDataLine
.
-
getInt
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
- ifcolumn
isnull
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 thisDataLine
.
-
getDouble
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
- ifcolumn
isnull
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 thisDataLine
.
-
append
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
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
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
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
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
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
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
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
Sets all the data-line values at once.- Parameters:
values
- the new values.- Returns:
- a reference to this data-line.
- Throws:
IllegalArgumentException
- ifvalues
isnull
, its length does not match this data-line column count, or the first element starts like a comment line.
-
seek
Changes the index of the next value to set usingappend
operations.- Parameters:
index
- the new index.- Returns:
- a reference to this data-line.
- Throws:
IllegalArgumentException
- ifindex
is greater than the number of columns
-
seek
Changes the index of the next value to set usingappend
operations.- Parameters:
columnName
- the name of the column to seek to.- Returns:
- a reference to this data-line.
- Throws:
IllegalArgumentException
- ifcolumnName
isnull
or an unknown column name.
-
seek
Changes the index of the next value to set usingappend
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
- ifcolumn
isnull
or does not make reference to a known column.
-
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 containnull
s.
-
getLineNumber
public long getLineNumber()Returns the line number for this data-line. 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
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
- ifcolumn
isnull
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 thisDataLine
.
-
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 anull
.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 thisDataLine
.
-