data
Class Parameter

java.lang.Object
  extended by data.Parameter
All Implemented Interfaces:
java.io.Serializable

public class Parameter
extends java.lang.Object
implements java.io.Serializable

A Parameter represents a parameter of a DataSheet.

It is used to store information about the type of data stored in a column of the DataSheet.

Two data types are supported: Numeric and Discrete.

Numeric parameters are used for columns that only contain numbers. Discrete parameters are used for all columns that contain at least one non-numeric value. All values are stored in a TreeSet and sorted in alphabetical order. This makes it possible to also treat information on parameters that are not quantifiable, such as different shapes of an object or similar.

See Also:
Serialized Form

Nested Class Summary
(package private)  class Parameter.ReverseStringComparator
          Comparator for the discrete levels TreeSet to sort the data alphabetically.
 
Field Summary
private  java.util.TreeSet<java.lang.String> discreteLevels
          The discrete levels.
private  java.lang.String name
          The parameter name.
private  boolean numeric
          Specifies whether the parameter is numeric.
(package private) static boolean printLog
          Flag to enable debug message printing for this class.
(package private) static long serialVersionUID
          The version tracking unique identifier for Serialization.
 
Constructor Summary
Parameter(java.lang.String name)
          Instantiates a new parameter.
 
Method Summary
 int getDiscreteLevelCount()
          Gets the discrete level count in the TreeSet that stores all discrete levels.
 double getDoubleValueOf(java.lang.String string)
          Gets a numeric representation of a string value for this parameter.
 java.lang.String getName()
          Gets the name.
 java.lang.String getStringValueOf(double value)
          Gets the string representation of a given double value for this parameter.
 boolean isNumeric()
          Checks whether the parameter is numeric or discrete.
private  void log(java.lang.String message)
          Prints debug information to stdout when printLog is set to true.
 void resetDiscreteLevels()
          Reset discrete levels to an empty TreeSet.
 void setName(java.lang.String name)
          Sets the name.
 void setNumeric(boolean numeric)
          Specifies whether the parameter is numeric or dicrete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
The version tracking unique identifier for Serialization.

See Also:
Constant Field Values

printLog

static final boolean printLog
Flag to enable debug message printing for this class.

See Also:
Constant Field Values

name

private java.lang.String name
The parameter name.


numeric

private boolean numeric
Specifies whether the parameter is numeric. If it is not, it is discrete.


discreteLevels

private java.util.TreeSet<java.lang.String> discreteLevels
The discrete levels. Only applies for non-numeric parameters.

Constructor Detail

Parameter

public Parameter(java.lang.String name)
Instantiates a new parameter.

Parameters:
name - the parameter name
Method Detail

getName

public java.lang.String getName()
Gets the name.

Returns:
the name

setName

public void setName(java.lang.String name)
Sets the name.

Parameters:
name - the new name

isNumeric

public boolean isNumeric()
Checks whether the parameter is numeric or discrete.

Returns:
true, if the parameter is numeric

setNumeric

public void setNumeric(boolean numeric)
Specifies whether the parameter is numeric or dicrete.

Parameters:
numeric - specifies if the parameter is numeric

getDoubleValueOf

public double getDoubleValueOf(java.lang.String string)
Gets a numeric representation of a string value for this parameter.

If the parameter is numeric, an attempt is made to parse the string as a Double. If this attempt leads to a NumberFormatException, the parameter is not considered numeric anymore, but is transformed into a discrete parameter.

If the parameter is not numeric, the string is looked up in the TreeSet discreteLevels that should contain all discrete values (that is Strings) that were found in the data sheet for this parameter. If the value is not found it is added as a new discrete level for this parameter. The treeSet is then searched again in order to get the correct index of the new discrete level.

If this second search does not yield the result, something unexpected has gone wrong and a CorruptDataException is thrown.

Parameters:
string - the string
Returns:
the numeric representation of the given string

getStringValueOf

public java.lang.String getStringValueOf(double value)
Gets the string representation of a given double value for this parameter.

If the parameter numeric, the provided value is simply converted to a String and returned.

If it is discrete, the double value is casted to an Integer value and this value is used as an index to look up the corresponding discrete value string in the TreeSet discreteLevels.

If no value is found for the given index the data is assumed to be corrupt and a CorruptDataException is thrown.

Parameters:
value - the numeric value
Returns:
the string representation of the given double value for this parameter.

getDiscreteLevelCount

public int getDiscreteLevelCount()
Gets the discrete level count in the TreeSet that stores all discrete levels.

Only applies to non-numeric parameters.

Returns:
the discrete level count

resetDiscreteLevels

public void resetDiscreteLevels()
Reset discrete levels to an empty TreeSet.


log

private void log(java.lang.String message)
Prints debug information to stdout when printLog is set to true.

Parameters:
message - the message