use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class JavaToDataCellConversionTest method testToIntCell.
/**
* Test Integer -> IntCell conversion.
*
* @throws Exception When something went wrong
*/
@Test
public void testToIntCell() throws Exception {
final IntCell cell = testSimpleConversion(Integer.class, IntCell.TYPE, IntCell.class, new Integer(42));
assertEquals(42, cell.getIntValue());
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class TestSubnode_CopyPasteWithDialogValues method checkTableContent.
private void checkTableContent(final String email, final int integer) throws Exception {
checkState(m_tableView13, InternalNodeContainerState.EXECUTED);
final NativeNodeContainer nnc = (NativeNodeContainer) getManager().getNodeContainer(m_tableView13);
BufferedDataTable table = ((BufferedDataTableHolder) nnc.getNodeModel()).getInternalTables()[0];
assertNotNull(table);
assertEquals("unexpected row count", 1, table.getRowCount());
DataRow r = table.iterator().next();
assertEquals(r.getCell(0), new StringCell(email));
assertEquals(r.getCell(1), new IntCell(integer));
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class HistogramColumn method nominalTable.
/**
* Creates the nominal table (histogram with number of missing values).
*
* @param statTable The statistics table.
* @param hlHandler The {@link HiLiteHandler}.
* @param exec An {@link ExecutionContext}.
* @param maxBinCount The maximum number of bins when we put labels to the histogram.
* @return The table containing the histograms.
* @see #createNominalHistogramTableSpec()
*/
public BufferedDataTable nominalTable(final Statistics3Table statTable, final HiLiteHandler hlHandler, final ExecutionContext exec, final int maxBinCount) {
DataTableSpec tableSpec = createNominalHistogramTableSpec();
BufferedDataContainer nominals = exec.createDataContainer(tableSpec);
for (int i = 0; i < statTable.getNominalValues().size(); ++i) {
Map<DataCell, Integer> nominalValues = statTable.getNominalValues(i);
if (nominalValues == null) {
continue;
}
final String colName = statTable.getColumnNames()[i];
DataCell[] row = new DataCell[tableSpec.getNumColumns()];
for (int u = row.length; u-- > 0; ) {
row[u] = DataType.getMissingCell();
}
row[0] = new StringCell(colName);
row[1] = new IntCell(statTable.getNumberMissingValues()[i]);
HistogramNominalModel model = new HistogramNominalModel(new LinkedHashMap<DataValue, Integer>(nominalValues), i, colName, statTable.getRowCount());
row[row.length - 1] = createImageCell(model, maxBinCount >= model.getBins().size());
nominals.addRowToTable(new DefaultRow(colName, row));
}
nominals.close();
return nominals.getTable();
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class AbstractTimeExtractorIntCellFactory method getCell.
/**
* {@inheritDoc}
*/
@Override
public DataCell getCell(final DataRow row) {
DataCell cell = row.getCell(getColumnIndex());
if (cell.isMissing()) {
return DataType.getMissingCell();
}
DateAndTimeValue value = (DateAndTimeValue) cell;
if (checkTime() && value.hasTime()) {
producedValidValue();
return new IntCell(extractTimeField(value));
}
if (checkDate() && value.hasDate()) {
producedValidValue();
return new IntCell(extractTimeField(value));
}
// no date set
increaseMissingValueCount();
return DataType.getMissingCell();
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class TimeFieldExtractorNodeModel method createColumnRearranger.
private SingleCellFactoryCompound createColumnRearranger(final DataTableSpec inSpec) {
final int colIdx = inSpec.findColumnIndex(m_selectedColumn.getStringValue());
ColumnRearranger rearranger = new ColumnRearranger(inSpec);
List<AbstractTimeExtractorCellFactory> cellFactories = new ArrayList<AbstractTimeExtractorCellFactory>();
// ************************* TIME fields factories *******************/
// hour
AbstractTimeExtractorCellFactory hourFactory = null;
if (m_useHour.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_hourColName.getStringValue());
hourFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getHourOfDay();
}
};
rearranger.append(hourFactory);
cellFactories.add(hourFactory);
}
// minute
AbstractTimeExtractorCellFactory minuteFactory = null;
if (m_useMinute.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_minuteColName.getStringValue());
minuteFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getMinute();
}
};
rearranger.append(minuteFactory);
cellFactories.add(minuteFactory);
}
// second
AbstractTimeExtractorCellFactory secondFactory = null;
if (m_useSecond.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_secondColName.getStringValue());
secondFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getSecond();
}
};
rearranger.append(secondFactory);
cellFactories.add(secondFactory);
}
// millisecond
AbstractTimeExtractorCellFactory milliFactory = null;
if (m_useMillis.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_milliColName.getStringValue());
milliFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
// here we also have to check if the value has millis
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getMillis();
}
@Override
public DataCell getCell(final DataRow row) {
DataCell cell = row.getCell(colIdx);
if (cell.isMissing()) {
return DataType.getMissingCell();
}
DateAndTimeValue value = (DateAndTimeValue) cell;
if (value.hasMillis()) {
producedValidValue();
return new IntCell(extractTimeField(value));
}
// no date set
increaseMissingValueCount();
return DataType.getMissingCell();
}
};
rearranger.append(milliFactory);
cellFactories.add(milliFactory);
}
return new SingleCellFactoryCompound(rearranger, cellFactories);
}
Aggregations