|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knime.core.data.DataTableSpec
public final class DataTableSpec
DataTableSpec
s specify the structure of a DataTable
.
The spec specifies the characteristics i.e. column numbers, as well as column
types, names, and other column oriented information through a collection of
DataColumnSpec
objects. The names of the DataColumnSpec
s
must be unique identifiers within a DataTableSpec
.
Once a DataTableSpec
is initialized, it is immutable. That is,
if you want to add further information to a column (for instance, the
possible values in a column), you have to create a new instance of a
DataTableSpec
carrying the new information. A spec can be
propagated from node to node via the ports so that succeeding nodes know
about the table structure even if no data table is currently available.
In addition, the table spec provides a single SizeHandler
,
ColorHandler
and/or
ShapeHandler
if available. The handlers
are associated with a column. These property handlers can be used to assign
size, color, and shape to a row based on the DataCell
s value in the
corresponding column. If there is more than one column that provides a
handler of a certain type (color, shape, size) the first handler is used.
A DataTableSpec
can also have a name which does not need to be
unique.
DataTable
,
DataColumnSpec
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.knime.core.node.port.PortObjectSpec |
---|
PortObjectSpec.PortObjectSpecSerializer<T extends PortObjectSpec> |
Field Summary | |
---|---|
static String[] |
CLASS_COLUMN_NAMES
Columns used to guess class column in the order they are specified. |
Constructor Summary | |
---|---|
DataTableSpec()
Creates an empty DataTableSpec with no columns defined and
default as name. |
|
DataTableSpec(DataColumnSpec... colSpecs)
Creates a new DataTableSpec , which is built from an array
of DataColumnSpec elements. |
|
DataTableSpec(DataTableSpec spec1,
DataTableSpec spec2)
Constructor for a new DataTableSpec based on two existing
specifications that are to be concatenated. |
|
DataTableSpec(String name)
Creates an empty DataTableSpec with no columns defined. |
|
DataTableSpec(String[] names,
DataType[] types)
Creates a new DataTableSpec based on a list of names and
types. |
|
DataTableSpec(String name,
DataColumnSpec... colSpecs)
Creates a new DataTableSpec , which is built from an array
of DataColumnSpec elements. |
|
DataTableSpec(String name,
DataTableSpec spec1,
DataTableSpec spec2)
Constructor for a new DataTableSpec based on two existing
specifications that are to be concatenated. |
|
DataTableSpec(String name,
String[] names,
DataType[] types)
Creates a new DataTableSpec based on a list of names and
types. |
Method Summary | |
---|---|
boolean |
containsCompatibleType(Class<? extends DataValue> valueClass)
Checks if this spec contains a column with a type compatible to the given DataValue class. |
boolean |
containsName(String columnName)
Checks if the given column name occurs in this spec. |
static DataColumnSpec[] |
createColumnSpecs(String[] names,
DataType[] types)
Static helper method to create a DataColumnSpec array from the
given names and types. |
boolean |
equals(Object obj)
Checks if both DataTableSpec s are equal. |
boolean |
equalStructure(DataTableSpec spec)
Returns true if spec has the same column
names and types. |
int |
findColumnIndex(String columnName)
Finds the column with the specified name in the TableSpec and returns its index, or -1 if the name doesn't exist in the table. |
DataColumnSpec |
getColumnSpec(int index)
Returns column information of the column with the provided index. |
DataColumnSpec |
getColumnSpec(String column)
Returns the DataColumnSpec of the column with the provided name. |
String |
getName()
Returns the name of this DataTableSpec . |
int |
getNumColumns()
Returns the number of columns. |
static PortObjectSpec.PortObjectSpecSerializer<DataTableSpec> |
getPortObjectSpecSerializer()
Method required by the interface PortObjectSpec . |
ColorAttr |
getRowColor(DataRow row)
Returns the color that an object should have when displaying information concerning this row (for instance in a scatterplot). |
ShapeFactory.Shape |
getRowShape(DataRow row)
Return the shape that an object should have when displaying information concerning this row (for instance in a scatterplot). |
double |
getRowSize(DataRow row)
Deprecated. use row size factor instead |
double |
getRowSizeFactor(DataRow row)
Return the size (as a scaling factor) that an object should have when displaying information concerning this row (for instance in a scatterplot). |
static String |
getUniqueColumnName(DataTableSpec spec,
String columnName)
Returns a column name, which is not contained in specified DataTableSpec . |
JComponent[] |
getViews()
The returned views are displayed in the out port view of the referring node. |
static String |
guessNominalClassColumn(DataTableSpec spec,
boolean withValues)
Guesses the column in the argument spec that likely contains the class attribute. |
int |
hashCode()
|
Iterator<DataColumnSpec> |
iterator()
Returns an iterator for the contained DataColumnSpec elements. |
static DataTableSpec |
load(ConfigRO config)
Reads all DataColumnSpec objects from the given ConfigRO
and returns a new DataTableSpec object containing them. |
static DataTableSpec |
mergeDataTableSpecs(DataTableSpec... specs)
This method merges two or more DataTableSpec s. |
void |
save(ConfigWO config)
Saves the table spec name and all DataColumnSpec s to the given
ConfigWO object. |
String |
toString()
The string summary of all column specs of this table spec. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String[] CLASS_COLUMN_NAMES
Constructor Detail |
---|
public DataTableSpec()
DataTableSpec
with no columns defined and
default as name.
public DataTableSpec(DataColumnSpec... colSpecs)
DataTableSpec
, which is built from an array
of DataColumnSpec
elements.
colSpecs
- an array containing information about all columns
NullPointerException
- if the given column spec or one of its
elements is null
IllegalArgumentException
- if the parameter array contains
duplicates according to the DataColumnSpec.getName()
methodpublic DataTableSpec(DataTableSpec spec1, DataTableSpec spec2)
DataTableSpec
based on two existing
specifications that are to be concatenated. The new spec name is combined
by both specs' names, though a concatenation of
"default+default+...+default" is avoided.
spec1
- The first spec.spec2
- The second spec.
NullPointerException
- If one of the given specs is
null
.
IllegalArgumentException
- If the parameter specs contain duplicate
names.public DataTableSpec(String name)
DataTableSpec
with no columns defined.
name
- this spec's namepublic DataTableSpec(String name, DataColumnSpec... colSpecs)
DataTableSpec
, which is built from an array
of DataColumnSpec
elements.
colSpecs
- an array containing information about all columnsname
- this spec's name, if null
a default name is
assigned
NullPointerException
- if the given column spec or one of its
elements is null
IllegalArgumentException
- if the parameter array contains
duplicates according to the DataColumnSpec.getName()
methodpublic DataTableSpec(String name, DataTableSpec spec1, DataTableSpec spec2)
DataTableSpec
based on two existing
specifications that are to be concatenated.
name
- This spec's name.spec1
- The first spec.spec2
- The second spec.
NullPointerException
- If one of the given specs is
null
.
IllegalArgumentException
- If the parameter specs contain duplicate
names.public DataTableSpec(String name, String[] names, DataType[] types)
DataTableSpec
based on a list of names and
types. The constructor uses the DataColumnSpec
but does not
create additional information (values, ...).
name
- this spec's identifier, if null
a default name
will be usednames
- an array of namestypes
- an array of types
NullPointerException
- if names or types, or one of its elements is
null
IllegalArgumentException
- if the names
and
types
arrays don't have the same length or if
the parameter array names
contains duplicatespublic DataTableSpec(String[] names, DataType[] types)
DataTableSpec
based on a list of names and
types. The constructor uses the DataColumnSpec
but does not
create additional information (values, ...).
names
- an array of namestypes
- an array of types
NullPointerException
- if names or types, or one of its elements is
null
IllegalArgumentException
- if the names
and
types
arrays don't have the same length or if
the parameter array names
contains duplicatesMethod Detail |
---|
public static PortObjectSpec.PortObjectSpecSerializer<DataTableSpec> getPortObjectSpecSerializer()
PortObjectSpec
. Not meant
for public use.
public static final DataColumnSpec[] createColumnSpecs(String[] names, DataType[] types)
DataColumnSpec
array from the
given names and types.
names
- an array of column namestypes
- an array of column types
DataColumnSpec
elements
NullPointerException
- if one of the arrays is null
IllegalArgumentException
- if the arrays do not have the same
lengthpublic static DataTableSpec load(ConfigRO config) throws InvalidSettingsException
DataColumnSpec
objects from the given ConfigRO
and returns a new DataTableSpec
object containing them.
config
- object to read column specs from
InvalidSettingsException
- if the name, number of columns, or a
column spec could not be readpublic boolean containsCompatibleType(Class<? extends DataValue> valueClass)
DataValue
class. This method returns false
if the
argument is null
.
valueClass
- the class of the data value interface to check for
true
if at least one column type in the spec is
compatible to the provided valuepublic boolean containsName(String columnName)
false
if the argument is null
.
columnName
- the column name to check
true
if this spec contains the column namepublic boolean equalStructure(DataTableSpec spec)
true
if spec
has the same column
names and types. Two specs are equal if they have the same number of
columns and the column specs of the same columns are equal (that implies
that the order of the columns has to be the same). The domains,
properties, and handlers of the column specs are not included into the
comparison.
spec
- the DataTableSpec
to compare this with
true
if the two specs have the same column names,
and types, otherwise false
public boolean equals(Object obj)
DataTableSpec
s are equal. In particular it checks
the name, indices of property handlers, and the equality of the contained
column specs according to the DataColumnSpec.equals(Object)
method. This implies that both specs have to have the same number of
columns and the order of the columns has to be the same.
equals
in class Object
obj
- the DataTableSpec
to compare this with
true
if the two specs are equalequalStructure(DataTableSpec)
,
DataColumnSpec.equals(Object)
public int findColumnIndex(String columnName)
null
.
columnName
- the name to search for
public DataColumnSpec getColumnSpec(int index)
index
- the column index within the table
ArrayIndexOutOfBoundsException
- if the index is out of rangepublic DataColumnSpec getColumnSpec(String column)
DataColumnSpec
of the column with the provided name.
This method returns null
if the argument is
null
.
column
- the column name to find the spec for
null
if not availablepublic String getName()
DataTableSpec
.
public int getNumColumns()
public ColorAttr getRowColor(DataRow row)
ColorHandler
of
this spec, which is associated with exactly one column. The color
therefore depends on the value of the corresponding cell of the given
row.
row
- the row for which the color is requested
public ShapeFactory.Shape getRowShape(DataRow row)
ShapeHandler
of
this spec, which is associated with exactly one column. The shape
therefore depends on the value of the corresponding cell of the given
row.
row
- the row for which the shape is requested
@Deprecated public double getRowSize(DataRow row)
SizeHandler
of this spec, which is
associated with exactly one column. The size therefore depends on the
value of the corresponding cell of the given row.
row
- the row for which the size is requested
public double getRowSizeFactor(DataRow row)
SizeHandler
of this spec, which is
associated with exactly one column. The size therefore depends on the
value of the corresponding cell of the given row.
row
- the row for which the size is requested
public int hashCode()
hashCode
in class Object
public Iterator<DataColumnSpec> iterator()
DataColumnSpec
elements.
The iterator does not support the remove method (table specs are
immutable).
iterator
in interface Iterable<DataColumnSpec>
DataColumnSpec
sIterable.iterator()
public void save(ConfigWO config)
DataColumnSpec
s to the given
ConfigWO
object.
config
- the config object to save this table specs topublic static DataTableSpec mergeDataTableSpecs(DataTableSpec... specs)
DataTableSpec
s.
If the DataTableSpec
s have equal structure
(which is required if you call this method)
their domains, Color-, Shape and Size-Handlers are merged. That means:
DataColumnSpec.getProperties()
), they will be merged, the
merged DataColumnSpec
will contain the intersection of all
properties (key and value must be the same).domains
will be updated, the
possible values list will contain the union of all possible values and
the min/max values will be set appropriately.
This factory method is used when two or more tables shall be
(row-wise) concatenated, for instance in
ExecutionContext#createConcatenateTable
.
specs
- The DataTableSpecs to merge.
IllegalArgumentException
- if the structures of the DataTableSpecs
do not match, the array is empty, or the array or one of its elements is
null
.public static String getUniqueColumnName(DataTableSpec spec, String columnName)
DataTableSpec
. This method is used when the argument spec
serves as basis for a new DataTableSpec
, which is
extended by additional columns. In order to ensure uniqueness of column
names, one can use this method to check if the argument string is
contained in the argument spec. If this is the case, this method will
"uniquify" the argument string and append a
"(# i)" where i is a running index.
spec
- The argument spec to check.columnName
- The desired column name
columnName
if it is not contained in the argument
spec or columnName
amended by some index
otherwise.
NullPointerException
- If one of the arguments is null
.public static final String guessNominalClassColumn(DataTableSpec spec, boolean withValues)
CLASS_COLUMN_NAMES
are preferably considered. The
returned column's name, if not null, is ensured to be compatible to
NominalValue
and also has possible values attached, if so
specified by the boolean argument; it returns null
if
there are no such columns fulfilling these constraints.
spec
- the argument specwithValues
- with or without possible values
public String toString()
toString
in class Object
public JComponent[] getViews()
getViews
in interface PortObjectSpec
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |