org.knime.base.node.io.filereader
Class DataCellFactory

java.lang.Object
  extended by org.knime.base.node.io.filereader.DataCellFactory

public class DataCellFactory
extends Object

Helper class for the file reader node. Creates data cells of a certain type from a provided string.

Author:
ohl, University of Konstanz

Constructor Summary
DataCellFactory()
          Creates a new factory that can be used to create DataCells from a string representation of data.
 
Method Summary
 void clearThousandsSeparator()
          After a call to this method no grouping of thousands in floating point numbers is supported.
 DataCell createDataCellOfType(DataType type, String data)
          Creates a DataCell of the specified type from the data passed.
 char getDecimalSeparator()
          Returns the current decimal separator of floating point numbers.
 String getErrorMessage()
          Get the error message when createDataCellOfType(DataType, String) returned null.
 String getMissingValuePattern()
          Returns the currently set missing value pattern.
 char getThousandsSeparator()
          Returns the character currently accepted as thousands separator.
 boolean hasThousandsSeparator()
          Returns true, if grouping of thousands in floating point numbers is currently supported.
 void setDecimalSeparator(char decSep)
          Sets the decimal separator to the specified character.
 void setMissingValuePattern(String missingValuePattern)
          Sets a new missing value pattern.
 void setThousandsSeparator(char thousandsSep)
          Sets the separator for groups of thousands to the specified character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataCellFactory

public DataCellFactory()
Creates a new factory that can be used to create DataCells from a string representation of data. By default the decimal separator for floating point number is a point, thousands grouping is disabled, and no missing value pattern is set.

Method Detail

setDecimalSeparator

public void setDecimalSeparator(char decSep)
Sets the decimal separator to the specified character. This separator is only honored when converting data into floating point numbers (when creating cells of type DoubleCell. It is highly discouraged to set 'e' or '-' as a decimal separator.

Parameters:
decSep - the new decimal separator (default is '.')

getDecimalSeparator

public char getDecimalSeparator()
Returns the current decimal separator of floating point numbers.

Returns:
the current decimal separator of floating point numbers.

hasThousandsSeparator

public boolean hasThousandsSeparator()
Returns true, if grouping of thousands in floating point numbers is currently supported.

Returns:
true, if grouping of thousands in floating point numbers is currently supported.

getThousandsSeparator

public char getThousandsSeparator()
Returns the character currently accepted as thousands separator. The NUL character is returned if thousands grouping is currently not supported.

Returns:
the character currently accepted as thousands separator. The NUL character is returned if thousands grouping is currently not supported.

setThousandsSeparator

public void setThousandsSeparator(char thousandsSep)
Sets the separator for groups of thousands to the specified character. This separator is only honored when converting data into floating point numbers (when creating cells of type DoubleCell. It is highly discouraged to set 'e' or '-' as a decimal separator.

Parameters:
thousandsSep - the character separating groups of thousands. if the NUL character ('\0') is provided this separator is disabled (which is the default).

clearThousandsSeparator

public void clearThousandsSeparator()
After a call to this method no grouping of thousands in floating point numbers is supported.


setMissingValuePattern

public void setMissingValuePattern(String missingValuePattern)
Sets a new missing value pattern. The method createDataCellOfType(DataType, String) creates a DataCell with a missing value, it the provided data there equals (see String.equals(Object)) the missing value pattern.

Parameters:
missingValuePattern - the new pattern to set as missing value pattern. Set to null to clear the missing value pattern.
See Also:
createDataCellOfType(DataType, String), DataType.getMissingCell()

getMissingValuePattern

public String getMissingValuePattern()
Returns the currently set missing value pattern. If null is returned, the missing value pattern is disabled.

Returns:
the missingValuePattern
See Also:
setMissingValuePattern(String)

createDataCellOfType

public final DataCell createDataCellOfType(DataType type,
                                           String data)
Creates a DataCell of the specified type from the data passed. Supported are the types of StringCell, IntCell, and DoubleCell, as well as smiles cells, if the corresponding plug-in is installed (see SmilesTypeHelper). A DataCell with a missing value is created if the passed data equals (see String.equals(Object) the currently set missing value pattern (disabled by default, see setMissingValuePattern(String)).
A StringCell can always be created, returns only null, if null was provided as data (a StringCell can't hold null).
Creating an IntCell fails, if the provided data is not a valid string representation of an integer number (see Integer.parseInt(String)).
Creation of a DoubleCell fails, if the provided data is not a valid string representation of a double number (see Double.parseDouble(String), with respect to the currently set decimal and thousands separators.

Parameters:
type - the type of the data cell to create. If the provided data can't be translated to the corresponding type, null is returned. The error message can be retrieved through the getErrorMessage().
data - the string representation of the data to store in the newly created cell. Can't be null.
Returns:
a data cell of the specified type carrying the provided data. Null is returned if the cell couldn't be created. Mostly due to incompatible string data, probably. The error message can then be retrieved through the getErrorMessage() method.
Throws:
IllegalArgumentException - if the passed type is not supported.
NullPointerException - if the passed data or type is null.
See Also:
setMissingValuePattern(String), getErrorMessage(), DataType.getMissingCell()

getErrorMessage

public String getErrorMessage()
Get the error message when createDataCellOfType(DataType, String) returned null.

Returns:
the error message of the last attempt to create a DataCell. Will be null, if creation succeeded.


Copyright, 2003 - 2010. 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.