Search in sources :

Example 71 with IntCell

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());
}
Also used : IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Example 72 with IntCell

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));
}
Also used : StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 73 with IntCell

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataValue(org.knime.core.data.DataValue) IntCell(org.knime.core.data.def.IntCell) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 74 with IntCell

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();
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 75 with IntCell

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);
}
Also used : SingleCellFactoryCompound(org.knime.timeseries.node.extract.SingleCellFactoryCompound) AbstractTimeExtractorIntCellFactory(org.knime.timeseries.node.extract.AbstractTimeExtractorIntCellFactory) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataRow(org.knime.core.data.DataRow) AbstractTimeExtractorCellFactory(org.knime.timeseries.node.extract.AbstractTimeExtractorCellFactory) IntCell(org.knime.core.data.def.IntCell) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataCell(org.knime.core.data.DataCell)

Aggregations

IntCell (org.knime.core.data.def.IntCell)109 DataCell (org.knime.core.data.DataCell)79 DoubleCell (org.knime.core.data.def.DoubleCell)67 StringCell (org.knime.core.data.def.StringCell)55 DefaultRow (org.knime.core.data.def.DefaultRow)46 DataRow (org.knime.core.data.DataRow)33 DataTableSpec (org.knime.core.data.DataTableSpec)21 RowKey (org.knime.core.data.RowKey)21 ArrayList (java.util.ArrayList)20 DataType (org.knime.core.data.DataType)20 LongCell (org.knime.core.data.def.LongCell)14 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)14 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 Test (org.junit.Test)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 DataContainer (org.knime.core.data.container.DataContainer)8 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)8