use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class JoinerJoinAnyTest method toIntegerArray.
/**
* Get the data of an DataTable as an integer array.
* @param dataTable the data table
* @return the data as an integer array
*/
private Integer[][] toIntegerArray(final BufferedDataTable dataTable) {
int rowCount = ConvenienceMethods.checkTableSize(dataTable.size());
int colCount = dataTable.getDataTableSpec().getNumColumns();
Integer[][] data = new Integer[rowCount][colCount];
RowIterator iter = dataTable.iterator();
int r = 0;
while (iter.hasNext()) {
DataRow row = iter.next();
Iterator<DataCell> cellIter = row.iterator();
int c = 0;
while (cellIter.hasNext()) {
DataCell cell = cellIter.next();
data[r][c] = !cell.isMissing() ? ((IntCell) cell).getIntValue() : null;
c++;
}
r++;
}
return data;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class SorterNodeModelTest method generateUnitMatrixTable.
/**
* This method produces a unit matrix -<code>DataTable</code>.
*
* @param dimension of the matrix
* @return Unit matrix
*/
public DefaultTable generateUnitMatrixTable(final int dimension) {
// generate Column names and types
String[] columnNames = new String[dimension];
for (int i = 0; i < dimension; i++) {
columnNames[i] = "col" + i;
}
DataType[] columnTypes = new DataType[dimension];
for (int i = 0; i < dimension; i++) {
columnTypes[i] = IntCell.TYPE;
}
DataRow[] unitmatrix = new DataRow[dimension];
for (int i = 0; i < dimension; i++) {
DataCell[] myRow = new DataCell[dimension];
for (int j = 0; j < dimension; j++) {
if (i == j) {
myRow[j] = new IntCell(1);
} else {
myRow[j] = new IntCell(0);
}
}
DataRow temprow = new DefaultRow(Integer.toString(i), myRow);
unitmatrix[i] = temprow;
}
return new DefaultTable(unitmatrix, columnNames, columnTypes);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class AbstractHistogramPlotter method createColumnSpec.
/**
* Returns <code>DataColumnSpec</code> object with the given properties.
*
* @param columnName name of the column.
* @param type the <code>DataType</code> of the column
* @param lowerBound the lower bound if available if not set it to
* <code>Double.NaN</code> @param upperBoundthe upper bound if available if
* not set it to <code>Double.NaN</code>
* @param values the possible values for nominal types or <code>null</code>
* for discrete types
* @return the <code>DataColumnSpec</code> object created using the
* given values
*/
private DataColumnSpec createColumnSpec(final String columnName, final DataType type, final double lowerBound, final double upperBound, final Set<DataCell> values) {
final DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
if (!Double.isNaN(lowerBound) && !Double.isNaN(upperBound)) {
DataCell lowerBoundCell = null;
DataCell upperBoundCell = null;
if (type.isCompatible(IntValue.class)) {
lowerBoundCell = new IntCell((int) lowerBound);
upperBoundCell = new IntCell((int) upperBound);
} else {
lowerBoundCell = new DoubleCell(lowerBound);
upperBoundCell = new DoubleCell(upperBound);
}
domainCreator.setLowerBound(lowerBoundCell);
domainCreator.setUpperBound(upperBoundCell);
}
if (values != null && values.size() > 0) {
domainCreator.setValues(values);
}
final DataColumnSpecCreator specCreator = new DataColumnSpecCreator(columnName, type);
specCreator.setDomain(domainCreator.createDomain());
final DataColumnSpec spec = specCreator.createSpec();
return spec;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class ExtractTableDimensionNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable data = inData[0];
BufferedDataContainer bdc = exec.createDataContainer(createDataTableSpec());
int noRows = data.getRowCount();
int noCols = data.getDataTableSpec().getNumColumns();
bdc.addRowToTable(new DefaultRow(DEF_NOROWS_VAR, new DataCell[] { new IntCell(noRows) }));
bdc.addRowToTable(new DefaultRow(DEF_NOCOLS_VAR, new DataCell[] { new IntCell(noCols) }));
bdc.close();
pushFlowVariableInt(DEF_NOROWS_VAR, noRows);
pushFlowVariableInt(DEF_NOCOLS_VAR, noCols);
return new BufferedDataTable[] { bdc.getTable() };
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class TimerinfoNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
BufferedDataContainer result = exec.createDataContainer(createSpec());
WorkflowManager wfm = NodeContext.getContext().getWorkflowManager();
for (NodeContainer nc : wfm.getNodeContainers()) {
NodeTimer nt = nc.getNodeTimer();
DataRow row = new DefaultRow(new RowKey("Node " + nc.getID().getIndex()), new StringCell(nc.getName()), nt.getLastExecutionDuration() >= 0 ? new LongCell(nt.getLastExecutionDuration()) : DataType.getMissingCell(), new LongCell(nt.getExecutionDurationSinceReset()), new LongCell(nt.getExecutionDurationSinceStart()), new IntCell(nt.getNrExecsSinceReset()), new IntCell(nt.getNrExecsSinceStart()), new StringCell(nc.getID().toString()), new StringCell(nc instanceof NativeNodeContainer ? ((NativeNodeContainer) nc).getNodeModel().getClass().getName() : "n/a"));
result.addRowToTable(row);
}
result.close();
return new PortObject[] { result.getTable() };
}
Aggregations