public class DataSet extends Object
A data set represents a collection of database rows.
Constructor and Description |
---|
DataSet(DataSource ds)
Constructs a new data set.
|
Modifier and Type | Method and Description |
---|---|
DataSet |
add(DataSet other)
Add rows of given data set to this data set.
|
DataSetBuilder |
build()
Create a builder for this data set.
|
static DataSet |
copyOf(DataSet data)
Create data set with the same contents of given data set.
|
static DataSet |
first(DataSet data,
int count)
Create sub-set with the first
n rows. |
DataSource |
getSource()
Get data source.
|
boolean |
isEmpty()
Check if the data set is empty.
|
boolean |
isReadOnly()
Check if the data set is read-only.
|
static DataSet |
join(DataSet... dataSets)
Create data set that results from joining
several data sets.
|
static DataSet |
last(DataSet data,
int n)
Create sub-set with the last
n rows. |
DataSet |
row(Object... columnValues)
Add a row to the data set.
|
DataSet |
rows(Object[][] rows)
Add rows to the data set.
|
void |
setReadOnly()
Set data set as read-only.
|
static DataSet |
singleton(DataSet data,
int index)
Create a data set with only one row from the given
data set.
|
int |
size()
Get size of data set.
|
static DataSet |
subset(DataSet data,
int startIndex,
int count)
Create a subset of the rows of given data set.
|
String |
toString()
Get textual representation of the data set.
|
public DataSet(DataSource ds)
ds
- Data source.public final boolean isReadOnly()
Adding rows to a read-only data set will result in an exception
of type InvalidOperationException
.
true
if data set is read-only.setReadOnly()
public final void setReadOnly()
Adding rows to a read-only data set will result in an exception
of type InvalidOperationException
.
The read-only setting cannot be disabled after this method
is called.
isReadOnly()
public final DataSource getSource()
public final DataSetBuilder build()
public final boolean isEmpty()
true
is the data set has no rows.public final int size()
@SafeVarargs public final DataSet row(Object... columnValues)
columnValues
- Column values forming a row.InvalidOperationException
- if this data set is read-only.rows(Object[][])
,
add(DataSet)
,
isReadOnly()
public final DataSet rows(Object[][] rows)
rows
- Array of rows.InvalidOperationException
- if this data set is read-only.row(Object...)
,
add(DataSet)
,
isReadOnly()
public final DataSet add(DataSet other)
other
- The other data set.InvalidOperationException
- if this data set is read-only, or
if the data source of the other data set differs
from this one.row(Object...)
,
rows(Object[][])
,
isReadOnly()
public final String toString()
toString
in class Object
JDBDT.dump(DataSet, java.io.File)
,
JDBDT.dump(DataSet, java.io.PrintStream)
public static DataSet subset(DataSet data, int startIndex, int count)
data
- Source data set.startIndex
- Start index (from 0 to data.size()-1
).count
- Number of rows.InvalidOperationException
- if the given data
set is null or if the specified column range is invalid.public static DataSet singleton(DataSet data, int index)
data
- Source data set.index
- Row index (from 0 to data.size()-1
).index
-th
row of the source data set.InvalidOperationException
- if the given data
set is null or if the specified column index is invalid.public static DataSet first(DataSet data, int count)
n
rows.data
- Source data set.count
- Number of rows.count
rows in the source data set.InvalidOperationException
- if the given data
set is null or if the value of n
is invalid.public static DataSet last(DataSet data, int n)
n
rows.data
- Source data set.n
- Number of rows.n
rows in the source data set.InvalidOperationException
- if the given data
set is null or if the value of n
is invalid.public static DataSet copyOf(DataSet data)
data
- Source data set.InvalidOperationException
- if given data set is null.@SafeVarargs public static DataSet join(DataSet... dataSets)
dataSets
- Data sets to join.InvalidOperationException
- if dataSets
is null or empty or if the data source is not the
same for all data sets.Copyright © 2016–2021 JDBDT. All rights reserved.