Search in sources :

Example 41 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class CategoryToNumberCellFactory method getCells.

/**
 * {@inheritDoc}
 */
@Override
public DataCell[] getCells(final DataRow row) {
    DataCell key = row.getCell(m_index);
    if (key.isMissing()) {
        return m_mapMissingTo;
    }
    DataCell[] value = m_categories.get(key);
    if (value == null) {
        if (m_categories.size() >= m_settings.getMaxCategories()) {
            // maximum reached give error
            throw new IllegalStateException("Maximum number of categories reached for column: " + m_columnSpecs[0].getName());
        }
        int number = m_settings.getStartIndex() + m_categories.size() * m_settings.getIncrement();
        IntCell cell = new IntCell(number);
        // Keep information in two maps for performance reasons
        // This avoids creating an array every time when the category
        // already exists.
        value = new DataCell[] { cell };
        m_categories.put(key, value);
        m_map.put(key, cell);
    }
    return value;
}
Also used : DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 42 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class ColumnRowFilterPanel method getBoundCell.

/* method used from the above */
private DataCell getBoundCell(final JTextField editField, final String name) throws InvalidSettingsException {
    if (editField.getText().length() <= 0) {
        return null;
    }
    String colName = getSelectedColumnName();
    if ((colName == null) || (colName.length() == 0)) {
        throw new InvalidSettingsException("Invalid columns selection");
    }
    if (m_tSpec != null) {
        final DataType origType = m_tSpec.getColumnSpec(colName).getType();
        final DataType cType;
        if (m_deepFiltering.isSelected() && origType.isCollectionType()) {
            cType = origType.getCollectionElementType();
        } else {
            cType = origType;
        }
        if (cType.isCompatible(IntValue.class)) {
            // first try making of an IntCell
            try {
                int lb = Integer.parseInt(editField.getText());
                return new IntCell(lb);
            } catch (NumberFormatException nfe) {
                throw new InvalidSettingsException("Number format error in " + name + " bound number: Enter a valid integer.");
            }
        } else if (cType.isCompatible(LongValue.class)) {
            try {
                long lb = Long.parseLong(editField.getText());
                return new LongCell(lb);
            } catch (NumberFormatException nfe) {
                throw new InvalidSettingsException("Number format error in " + name + " bound number: Enter a valid number.");
            }
        } else if (cType.isCompatible(DoubleValue.class)) {
            try {
                double lb = Double.parseDouble(editField.getText());
                return new DoubleCell(lb);
            } catch (NumberFormatException nfe) {
                throw new InvalidSettingsException("Number format error in " + name + " bound number: enter a valid " + "float number");
            }
        } else {
            return new StringCell(editField.getText());
        }
    } else {
        // if we got no column type
        return new StringCell(editField.getText());
    }
}
Also used : LongCell(org.knime.core.data.def.LongCell) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) LongValue(org.knime.core.data.LongValue) DataType(org.knime.core.data.DataType) IntCell(org.knime.core.data.def.IntCell)

Example 43 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class GroupByTable method appendOrderColumn.

/**
 * @param exec the {@link ExecutionContext}
 * @param dataTable the {@link BufferedDataTable} to add the order column to
 * @param workingCols the names of all columns needed for grouping
 * @param retainOrderCol the name of the order column
 * @return the given table with the appended order column
 * @throws CanceledExecutionException if the operation has been canceled
 */
public static BufferedDataTable appendOrderColumn(final ExecutionContext exec, final BufferedDataTable dataTable, final Set<String> workingCols, final String retainOrderCol) throws CanceledExecutionException {
    final ColumnRearranger rearranger = new ColumnRearranger(dataTable.getSpec());
    rearranger.append(new SingleCellFactory(new DataColumnSpecCreator(retainOrderCol, IntCell.TYPE).createSpec()) {

        private int m_id = 0;

        @Override
        public DataCell getCell(final DataRow row) {
            return new IntCell(m_id++);
        }
    });
    final String[] workingColsArray = workingCols.toArray(new String[0]);
    rearranger.keepOnly(workingColsArray);
    rearranger.permute(workingColsArray);
    return exec.createColumnRearrangeTable(dataTable, rearranger, exec);
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataCell(org.knime.core.data.DataCell) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 44 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class LinearInterpolationStatisticTB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(getColumnIndex());
    if (cell.isMissing()) {
        incMissing();
    } else {
        for (int i = 0; i < getNumMissing(); i++) {
            DataCell res;
            if (getPrevious().isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev));
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) getPrevious()).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
                    if (getPrevious() instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (getPrevious() instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            addMapping(res);
        }
        resetMissing(cell);
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 45 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class AverageInterpolationStatisticTB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(getColumnIndex());
    if (cell.isMissing()) {
        incMissing();
    } else {
        for (int i = 0; i < getNumMissing(); i++) {
            DataCell res;
            if (getPrevious().isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round((prev + next) / 2);
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) getPrevious()).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = (prev + next) / 2;
                    if (getPrevious() instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (getPrevious() instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            addMapping(res);
        }
        resetMissing(cell);
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

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