org.knime.core.data.collection
Class SparseListCell

java.lang.Object
  extended by org.knime.core.data.DataCell
      extended by org.knime.core.data.collection.SparseListCell
All Implemented Interfaces:
Serializable, Iterable<DataCell>, CollectionDataValue, ListDataValue, SparseListDataValue, DataValue

public class SparseListCell
extends DataCell
implements SparseListDataValue

Sparse implementation of a CollectionDataValue. The class stores a default value and a mapping of indices and values unequal to the default value.

Author:
Tobias Koetter, University of Konstanz
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.knime.core.data.collection.CollectionDataValue
CollectionDataValue.CollectionUtilityFactory
 
Nested classes/interfaces inherited from interface org.knime.core.data.DataValue
DataValue.UtilityFactory
 
Field Summary
 
Fields inherited from interface org.knime.core.data.collection.CollectionDataValue
UTILITY
 
Constructor Summary
protected SparseListCell(int size, BlobSupportDataCellList elements, int[] elementIdxs, DataCell defaultElement)
          Constructor for class SparseListCell.
 
Method Summary
 boolean containsBlobWrapperCells()
          Get whether the collection contains special BlobWrapperDataCell (framework use).
protected  boolean equalsDataCell(DataCell dc)
          Derived classes implement their specific equals function here.
 DataCell get(int index)
          Returns the cell at the specified position in the list.
 int[] getAllIndices()
          Returns a copy of the array that contains all indices of the explicitly set values of this list.
static DataCellSerializer<SparseListCell> getCellSerializer()
          Get serializer as required by DataCell.
static DataType getCollectionType(DataType elementType)
          Convenience method to determine the type of collection.
 DataCell getDefaultElement()
          
 DataType getElementType()
          Get the common super type of all elements in this collection.
protected  int getIdx(int idx)
           
protected  int getIdxLength()
           
protected  int[] getIdxs()
           
protected  BlobSupportDataCellList getValueList()
           
 int hashCode()
          This method must be implemented in order to ensure that two equal DataCell objects return the same hash code.
 Iterator<DataCell> iterator()
          
 int size()
          Get the number of elements in this collection.
 String toString()
          Returns the String representation of this cell's value.
 
Methods inherited from class org.knime.core.data.DataCell
equals, getType, isMissing
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SparseListCell

protected SparseListCell(int size,
                         BlobSupportDataCellList elements,
                         int[] elementIdxs,
                         DataCell defaultElement)
Constructor for class SparseListCell.

Parameters:
size - the size of the vector. Indices must be smaller than this number.
elements - the elements unequal to the default element
elementIdxs - the array containing the indices of the elements to store. MUST be sorted (lowest index first).
defaultElement - the element that should be returned as default value if no value is set
Throws:
IllegalArgumentException - if length is negative or if the array contains negative indices or indices larger than length - or if the array is not sorted or the arrays do not have the same length or the default element is null!
Method Detail

getCollectionType

public static DataType getCollectionType(DataType elementType)
Convenience method to determine the type of collection. This is a shortcut for DataType.getType(ListCell.class, elementType).

Parameters:
elementType - The type of the elements
Returns:
a DataType representing the collection.

getCellSerializer

public static DataCellSerializer<SparseListCell> getCellSerializer()
Get serializer as required by DataCell.

Returns:
Such a serializer.

getElementType

public DataType getElementType()
Get the common super type of all elements in this collection.

Specified by:
getElementType in interface CollectionDataValue
Returns:
The common super type, never null.

getIdx

protected int getIdx(int idx)
Parameters:
idx - the index in the index array to get the stored index for
Returns:
the index at the given position in the index array

getIdxLength

protected int getIdxLength()
Returns:
the number of explicitly stored values

getValueList

protected BlobSupportDataCellList getValueList()
Returns:
the value list

getIdxs

protected int[] getIdxs()
Returns:
the indices that corresponds to the values in the value list

get

public DataCell get(int index)
Returns the cell at the specified position in the list.

Specified by:
get in interface ListDataValue
Parameters:
index - the position of the element to return (first element has index zero).
Returns:
the cell at the specified position in the list

getDefaultElement

public DataCell getDefaultElement()

Specified by:
getDefaultElement in interface SparseListDataValue
Returns:
the default element that is returned for all indices within the range of the list but that do not have a value assigned

iterator

public Iterator<DataCell> iterator()

Specified by:
iterator in interface Iterable<DataCell>
Specified by:
iterator in interface CollectionDataValue

size

public int size()
Get the number of elements in this collection.

Specified by:
size in interface CollectionDataValue
Returns:
size of the collection.

containsBlobWrapperCells

public boolean containsBlobWrapperCells()
Get whether the collection contains special BlobWrapperDataCell (framework use). This method gives a hint to the framwork (specifically to the classes DataContainer and BufferedDataContainer) whether they should handle the cell implementing this interface with care with respect to contained BlobDataCell.

This method should return true only if

Implementation note: This method is really only a helper for the framework. The same information can be retrieved by accessing the iterator. This can be an expensive and unnecessary operation, however.

Specified by:
containsBlobWrapperCells in interface CollectionDataValue
Returns:
Whether the collection contains blob wrapper cells.

getAllIndices

public int[] getAllIndices()
Returns a copy of the array that contains all indices of the explicitly set values of this list. They are sorted in increasing order.

Specified by:
getAllIndices in interface SparseListDataValue
Returns:
all indices that have a explicitly set value attached

equalsDataCell

protected boolean equalsDataCell(DataCell dc)
Derived classes implement their specific equals function here. The argument is guaranteed to be not null or a missing value, to be of the same class like this.

Specified by:
equalsDataCell in class DataCell
Parameters:
dc - the cell to compare this to
Returns:
true if this is equal to the argument, false if not

hashCode

public int hashCode()
This method must be implemented in order to ensure that two equal DataCell objects return the same hash code.

Specified by:
hashCode in class DataCell
Returns:
the hash code of your specific DataCell
See Also:
Object.hashCode(), DataCell.equals(java.lang.Object)

toString

public String toString()
Returns the String representation of this cell's value.

Specified by:
toString in class DataCell
Returns:
a String representation of this cell's value


Copyright, 2003 - 2012. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.