Search in sources :

Example 96 with StringCell

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

the class MissingValueHandling2Panel method getSettings.

/**
 * Get the settings currently entered in the dialog.
 *
 * @return the current settings
 */
public MissingValueHandling2ColSetting getSettings() {
    int method;
    if (m_nothingButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
    } else if (m_removeButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS;
    } else if (m_fixButton != null && m_fixButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_FIX_VAL;
        DataCell cell;
        switch(m_setting.getType()) {
            case MissingValueHandling2ColSetting.TYPE_INT:
                Object value = ((JFormattedTextField) m_fixText).getValue();
                cell = new IntCell(((Number) value).intValue());
                break;
            case MissingValueHandling2ColSetting.TYPE_DOUBLE:
                value = ((JFormattedTextField) m_fixText).getValue();
                cell = new DoubleCell(((Number) value).doubleValue());
                break;
            case MissingValueHandling2ColSetting.TYPE_STRING:
                value = ((JComboBox) m_fixText).getEditor().getItem();
                cell = new StringCell(value.toString());
                break;
            default:
                throw new RuntimeException("You shouldn't have come here.");
        }
        m_setting.setFixCell(cell);
    } else if (m_maxButton != null && m_maxButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MAX;
    } else if (m_minButton != null && m_minButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MIN;
    } else if (m_meanButton != null && m_meanButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MEAN;
    } else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
        method = MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT;
    } else {
        assert false : "One button must be selected.";
        method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
    }
    m_setting.setMethod(method);
    return m_setting;
}
Also used : JComboBox(javax.swing.JComboBox) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) JFormattedTextField(javax.swing.JFormattedTextField) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 97 with StringCell

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

the class AbstractMany2OneCellFactory method getCells.

/**
 * {@inheritDoc}
 */
@Override
public DataCell[] getCells(final DataRow row) {
    // find matching values
    int matchingValue = findColumnIndex(row);
    DataCell newCell;
    if (matchingValue == -1) {
        newCell = DataType.getMissingCell();
    } else {
        newCell = new StringCell(m_inputSpec.getColumnSpec(matchingValue).getName());
    }
    return new DataCell[] { newCell };
}
Also used : StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 98 with StringCell

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

the class DomainDialog method addStringPosValue.

/**
 * Called when the user pressed the "Add" button to add a string value to the list of possible values.
 */
protected void addStringPosValue() {
    if (m_editField.getText().length() > 0) {
        addDataCellPossValue(new StringCell(m_editField.getText()));
        m_editField.setText("");
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell)

Example 99 with StringCell

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

the class AppendVariableToTable2NodeModel method createColumnRearranger.

@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    ColumnRearranger arranger = new ColumnRearranger(spec);
    Set<String> nameHash = new HashSet<String>();
    for (DataColumnSpec c : spec) {
        nameHash.add(c.getName());
    }
    List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
    if (vars.isEmpty()) {
        throw new InvalidSettingsException("No variables selected");
    }
    DataColumnSpec[] specs = new DataColumnSpec[vars.size()];
    final DataCell[] values = new DataCell[vars.size()];
    for (int i = 0; i < vars.size(); i++) {
        Pair<String, FlowVariable.Type> c = vars.get(i);
        String name = c.getFirst();
        final DataType type;
        switch(c.getSecond()) {
            case DOUBLE:
                type = DoubleCell.TYPE;
                try {
                    double dValue = peekFlowVariableDouble(name);
                    values[i] = new DoubleCell(dValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type double): " + name);
                }
                break;
            case INTEGER:
                type = IntCell.TYPE;
                try {
                    int iValue = peekFlowVariableInt(name);
                    values[i] = new IntCell(iValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type int): " + name);
                }
                break;
            case STRING:
                type = StringCell.TYPE;
                try {
                    String sValue = peekFlowVariableString(name);
                    sValue = sValue == null ? "" : sValue;
                    values[i] = new StringCell(sValue);
                } catch (NoSuchElementException e) {
                    throw new InvalidSettingsException("No such flow variable (of type String): " + name);
                }
                break;
            default:
                throw new InvalidSettingsException("Unsupported variable type: " + c.getSecond());
        }
        if (nameHash.contains(name) && !name.toLowerCase().endsWith("(variable)")) {
            name = name.concat(" (variable)");
        }
        String newName = name;
        int uniquifier = 1;
        while (!nameHash.add(newName)) {
            newName = name + " (#" + (uniquifier++) + ")";
        }
        specs[i] = new DataColumnSpecCreator(newName, type).createSpec();
    }
    arranger.append(new AbstractCellFactory(specs) {

        /**
         * {@inheritDoc}
         */
        @Override
        public DataCell[] getCells(final DataRow row) {
            return values;
        }
    });
    return arranger;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet) Pair(org.knime.core.util.Pair) AbstractCellFactory(org.knime.core.data.container.AbstractCellFactory) PortType(org.knime.core.node.port.PortType) DataType(org.knime.core.data.DataType) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) NoSuchElementException(java.util.NoSuchElementException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 100 with StringCell

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

the class UniqueConcatenateOperator method getResultInternal.

/**
 * {@inheritDoc}
 */
@Override
protected DataCell getResultInternal() {
    final Set<DataCell> groupMembers = getGroupMembers();
    if (groupMembers.isEmpty()) {
        return DataType.getMissingCell();
    }
    final StringBuilder buf = new StringBuilder();
    boolean first = true;
    for (final DataCell val : groupMembers) {
        if (first) {
            first = false;
        } else {
            buf.append(getValueDelimiter());
        }
        buf.append(val.toString());
    }
    return new StringCell(buf.toString());
}
Also used : StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Aggregations

StringCell (org.knime.core.data.def.StringCell)176 DataCell (org.knime.core.data.DataCell)130 DoubleCell (org.knime.core.data.def.DoubleCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)65 IntCell (org.knime.core.data.def.IntCell)55 DataRow (org.knime.core.data.DataRow)52 DataTableSpec (org.knime.core.data.DataTableSpec)49 ArrayList (java.util.ArrayList)41 DataColumnSpec (org.knime.core.data.DataColumnSpec)37 RowKey (org.knime.core.data.RowKey)36 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)26 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)26 DataType (org.knime.core.data.DataType)22 LinkedHashSet (java.util.LinkedHashSet)21 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)19 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)16 LinkedHashMap (java.util.LinkedHashMap)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)11