Search in sources :

Example 1 with BlobWrapperDataCell

use of org.knime.core.data.container.BlobWrapperDataCell in project knime-core by knime.

the class BlobSupportDataCellList method init.

private void init(final Collection<? extends DataCell> coll) {
    ArrayList<DataCell> cellList = new ArrayList<DataCell>(coll.size());
    DataType commonType = null;
    for (DataCell c : coll) {
        if (c == null) {
            throw new NullPointerException("List element must not be null");
        }
        DataType cellType;
        if (c instanceof BlobWrapperDataCell) {
            m_containsBlobWrapperCells = true;
            cellList.add(c);
            cellType = DataType.getType(((BlobWrapperDataCell) c).getBlobClass());
        } else if (c instanceof BlobDataCell) {
            m_containsBlobWrapperCells = true;
            cellList.add(new BlobWrapperDataCell((BlobDataCell) c));
            cellType = c.getType();
        } else {
            cellList.add(c);
            cellType = c.getType();
        }
        if (!c.isMissing()) {
            if (commonType == null) {
                commonType = cellType;
            } else {
                commonType = DataType.getCommonSuperType(commonType, cellType);
            }
        }
    }
    if (commonType == null) {
        m_elementType = DataType.getMissingCell().getType();
    } else {
        m_elementType = commonType;
    }
    m_cellList = cellList;
}
Also used : BlobDataCell(org.knime.core.data.container.BlobDataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) ArrayList(java.util.ArrayList) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) BlobDataCell(org.knime.core.data.container.BlobDataCell) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType)

Example 2 with BlobWrapperDataCell

use of org.knime.core.data.container.BlobWrapperDataCell in project knime-core by knime.

the class DataTableDomainCreator method updateMinMax.

/**
 * Updates the min and max value for an respective column. This method does nothing if the min and max values don't
 * need to be stored, e.g. the column at hand contains string values.
 *
 * @param col the column of interest
 * @param cell the new value to check
 */
private void updateMinMax(final int col, final DataCell cell, final DataCell[] mins, final DataCell[] maxs, final DataValueComparator[] comparators) {
    if (mins[col] == null || cell.isMissing()) {
        return;
    }
    final DataCell unwrapped = (cell instanceof BlobWrapperDataCell) ? ((BlobWrapperDataCell) cell).getCell() : cell;
    if (isNaN(unwrapped)) {
        return;
    }
    Comparator<DataCell> comparator = comparators[col];
    if (mins[col].isMissing() || (comparator.compare(unwrapped, mins[col]) < 0)) {
        mins[col] = unwrapped;
    }
    if (maxs[col].isMissing() || (comparator.compare(unwrapped, maxs[col]) > 0)) {
        maxs[col] = unwrapped;
    }
}
Also used : BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell)

Example 3 with BlobWrapperDataCell

use of org.knime.core.data.container.BlobWrapperDataCell in project knime-core by knime.

the class SplitCellFactory method getCells.

/**
 * {@inheritDoc}
 */
@Override
public DataCell[] getCells(final DataRow row) {
    DataCell inCell = row.getCell(m_colIndex);
    DataCell[] result = new DataCell[m_colSpecs.length];
    Arrays.fill(result, DataType.getMissingCell());
    if (inCell.isMissing()) {
        if (m_warnMessage == null) {
            m_warnMessage = "Some rows contain missing values";
        }
        return result;
    }
    CollectionDataValue v = (CollectionDataValue) inCell;
    Iterator<DataCell> it = v.iterator();
    for (int i = 0; i < m_colSpecs.length && it.hasNext(); i++) {
        DataCell next;
        DataType type;
        if (it instanceof BlobSupportDataCellIterator) {
            next = ((BlobSupportDataCellIterator) it).nextWithBlobSupport();
            if (next instanceof BlobWrapperDataCell) {
                // try to not access the cell (will get deserialized)
                BlobWrapperDataCell bw = (BlobWrapperDataCell) next;
                type = DataType.getType(bw.getBlobClass());
            } else {
                type = next.getType();
            }
        } else {
            next = it.next();
            type = next.getType();
        }
        if (m_commonTypes[i] == null) {
            m_commonTypes[i] = type;
        } else {
            m_commonTypes[i] = DataType.getCommonSuperType(m_commonTypes[i], type);
        }
        result[i] = next;
    }
    if (it.hasNext()) {
        m_warnMessage = "At least one row had more elements than " + "specified; row was truncated.";
    }
    m_domainCreator.updateDomain(new DefaultRow(row.getKey(), result));
    return result;
}
Also used : BlobSupportDataCellIterator(org.knime.core.data.collection.BlobSupportDataCellIterator) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType) DefaultRow(org.knime.core.data.def.DefaultRow) CollectionDataValue(org.knime.core.data.collection.CollectionDataValue)

Example 4 with BlobWrapperDataCell

use of org.knime.core.data.container.BlobWrapperDataCell in project knime-core by knime.

the class BlobSupportDataCellSet method init.

/**
 * @param cells
 */
private void init(final Collection<? extends DataCell> cells) {
    LinkedHashSet<Wrapper> cellSet = new LinkedHashSet<Wrapper>();
    DataType commonType = null;
    for (DataCell c : cells) {
        if (c == null) {
            throw new NullPointerException("Collection element must not be null");
        }
        DataType cellType;
        Wrapper element;
        if (c instanceof BlobWrapperDataCell) {
            m_containsBlobWrapperCells = true;
            element = new Wrapper(c);
            cellType = DataType.getType(((BlobWrapperDataCell) c).getBlobClass());
        } else if (c instanceof BlobDataCell) {
            m_containsBlobWrapperCells = true;
            element = new Wrapper(new BlobWrapperDataCell((BlobDataCell) c));
            cellType = c.getType();
        } else {
            element = new Wrapper(c);
            cellType = c.getType();
        }
        cellSet.add(element);
        if (!c.isMissing()) {
            if (commonType == null) {
                commonType = cellType;
            } else {
                commonType = DataType.getCommonSuperType(commonType, cellType);
            }
        }
    }
    if (commonType == null) {
        m_elementType = DataType.getMissingCell().getType();
    } else {
        m_elementType = commonType;
    }
    m_set = Collections.unmodifiableSet(cellSet);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BlobDataCell(org.knime.core.data.container.BlobDataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) DataType(org.knime.core.data.DataType) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) BlobDataCell(org.knime.core.data.container.BlobDataCell) DataCell(org.knime.core.data.DataCell)

Example 5 with BlobWrapperDataCell

use of org.knime.core.data.container.BlobWrapperDataCell in project knime-core by knime.

the class DataCell method equals.

/**
 * Implements the equals method which returns <code>true</code> only if both
 * cells are of the same class and {@link #equalsDataCell(DataCell)} returns
 * <code>true</code>. For that, this final method calls the type specific
 * {@link #equalsDataCell(DataCell)} method, which all derived
 * <code>DataCell</code>s must provide. This method handles the missing
 * value and <code>null</code> cases, in all other cases it delegates
 * to the specific method.
 *
 * @param o the other object to check
 * @return <code>true</code> if this instance and the given object are
 *         instances of the same class and of equal value (or both
 *         representing missing values)
 */
@Override
public final boolean equals(final Object o) {
    // true of called on the same objects
    if (this == o) {
        return true;
    }
    // also handles null cases
    if (!(o instanceof DataCell)) {
        return false;
    }
    DataCell thisDelegate = this;
    while (thisDelegate instanceof BlobWrapperDataCell) {
        thisDelegate = ((BlobWrapperDataCell) thisDelegate).getCell();
    }
    DataCell otherDelegate = (DataCell) o;
    while (otherDelegate instanceof BlobWrapperDataCell) {
        otherDelegate = ((BlobWrapperDataCell) otherDelegate).getCell();
    }
    // if both cells are missing they are equal
    if (thisDelegate.isMissing() && otherDelegate.isMissing()) {
        return true;
    }
    // if only one of both cells is missing they cannot be equal
    if (thisDelegate.isMissing() || otherDelegate.isMissing()) {
        return false;
    }
    // only cells of identical classes can possibly be equal
    if (thisDelegate.getClass().equals(otherDelegate.getClass())) {
        // now call the datacell class specific equals method
        boolean b = thisDelegate.equalsDataCell(otherDelegate);
        assert (!b || thisDelegate.hashCode() == otherDelegate.hashCode()) : "\"hashCode\" implementation of " + thisDelegate.getClass() + " is not compatible with equalsDataCell. Please check the implementations!";
        return b;
    } else if (thisDelegate.getType().getPreferredValueClass().equals(otherDelegate.getType().getPreferredValueClass())) {
        // cells or for normal and adapter cells.
        assert thisDelegate.equalContent(otherDelegate) == otherDelegate.equalContent(thisDelegate) : "\"equalContent\" implementation of " + thisDelegate.getClass() + " and " + otherDelegate.getClass() + " behave differently. Please check the implementations!";
        return thisDelegate.equalContent(otherDelegate);
    }
    // not of the same class or content
    return false;
}
Also used : BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell)

Aggregations

BlobWrapperDataCell (org.knime.core.data.container.BlobWrapperDataCell)5 DataCell (org.knime.core.data.DataCell)3 DataType (org.knime.core.data.DataType)3 BlobDataCell (org.knime.core.data.container.BlobDataCell)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 BlobSupportDataCellIterator (org.knime.core.data.collection.BlobSupportDataCellIterator)1 CollectionDataValue (org.knime.core.data.collection.CollectionDataValue)1 DefaultRow (org.knime.core.data.def.DefaultRow)1