fsmvis.data
Class CSVLoader

java.lang.Object
  |
  +--fsmvis.data.CSVLoader

public class CSVLoader
extends java.lang.Object
implements DataLoader, MonitorableTask


Field Summary
static java.util.Map CSV_TYPES
           
protected  java.io.BufferedReader csvFile
           
protected  DataItemCollection dataItemColl
           
static java.lang.String DATE_FORMAT
           
static java.lang.String DATE_NAME
           
protected  java.text.SimpleDateFormat dateF
           
static java.lang.String DEFAULT_DATE
           
static java.lang.String DEFAULT_DATE_FORMAT
           
static java.lang.String DEFAULT_DELIMITER
           
static java.lang.String DEFAULT_DOUBLE
           
static java.lang.String DEFAULT_INTEGER
           
static java.lang.String DEFAULT_STRING
           
static java.lang.String DEFAULT_UNDEFINED
           
protected  java.lang.String delim
           
static java.lang.String DELIMITER_FORMAT
           
static java.lang.String DOUBLE_NAME
           
protected  java.util.ArrayList fields
           
protected  java.lang.String fileName
           
static java.lang.String INTEGER_NAME
           
protected  int numDataItems
           
protected  Viewer parent
           
protected  int progress
           
protected  PropertiesHandler properties
           
static java.lang.String STRING_NAME
           
protected  double[] sumOfSquares
           
protected  double[] sumOfVals
           
protected  int taskLength
           
protected  java.util.ArrayList types
           
protected  java.lang.String undef
           
static java.lang.String UNDEFINED_FORMAT
           
 
Constructor Summary
CSVLoader(Viewer parent, java.lang.String fileName)
          Constructor for CSVLoader, takes a csv filename as param
 
Method Summary
 void doneWork()
          A method that is called when ever an item of work has been completed
 void doneWork(int units)
          A method that is called when ever a number of work items have been completed
 DataItemCollection getDataItemCollection()
          Returns a DataItemCollection object containing the data in the csv file
 java.util.ArrayList getFields()
          gets the field names in the csv file
 int getLengthOfTask()
          Returns the length of this current task, this is defined to be some kind of abstract work unit.
 int getProgress()
          Returns the current progress through this task.
 java.util.ArrayList getTypes()
          Gets the types that correspond to the field names,
protected  void initProperties()
          initialises the properties associated with this loader
 boolean isFinished()
          Returns whether or not the current task has been completed
 DataItem parseDataItem(java.lang.String line)
          Method to parse a data item, turns the String of fields in the data item into a dataItem object.
 void readData()
          Reads from the data source and parses its contents to create a DataItemCollection
 void readFields()
          Reads the field names from the first line of the csv file Assumes the input pointer is ready at the start of the file
 void readTypes()
          Reads the corresponding types from the second line of csv file Assumes the input pointer is at the start of the second line of the csv file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CSV_TYPES

public static java.util.Map CSV_TYPES

parent

protected Viewer parent

dataItemColl

protected DataItemCollection dataItemColl

numDataItems

protected int numDataItems

fileName

protected java.lang.String fileName

properties

protected PropertiesHandler properties

fields

protected java.util.ArrayList fields

types

protected java.util.ArrayList types

csvFile

protected java.io.BufferedReader csvFile

sumOfVals

protected double[] sumOfVals

sumOfSquares

protected double[] sumOfSquares

dateF

protected java.text.SimpleDateFormat dateF

delim

protected java.lang.String delim

undef

protected java.lang.String undef

taskLength

protected int taskLength

progress

protected int progress

DOUBLE_NAME

public static final java.lang.String DOUBLE_NAME

INTEGER_NAME

public static final java.lang.String INTEGER_NAME

STRING_NAME

public static final java.lang.String STRING_NAME

DATE_NAME

public static final java.lang.String DATE_NAME

DATE_FORMAT

public static final java.lang.String DATE_FORMAT

UNDEFINED_FORMAT

public static final java.lang.String UNDEFINED_FORMAT

DELIMITER_FORMAT

public static final java.lang.String DELIMITER_FORMAT

DEFAULT_DOUBLE

public static final java.lang.String DEFAULT_DOUBLE

DEFAULT_INTEGER

public static final java.lang.String DEFAULT_INTEGER

DEFAULT_STRING

public static final java.lang.String DEFAULT_STRING

DEFAULT_DATE

public static final java.lang.String DEFAULT_DATE

DEFAULT_UNDEFINED

public static final java.lang.String DEFAULT_UNDEFINED

DEFAULT_DELIMITER

public static final java.lang.String DEFAULT_DELIMITER

DEFAULT_DATE_FORMAT

public static final java.lang.String DEFAULT_DATE_FORMAT
Constructor Detail

CSVLoader

public CSVLoader(Viewer parent,
                 java.lang.String fileName)
          throws java.io.FileNotFoundException,
                 java.io.IOException
Constructor for CSVLoader, takes a csv filename as param
Parameters:
fileName - The csv file to be loaded
Method Detail

initProperties

protected void initProperties()
initialises the properties associated with this loader

readFields

public void readFields()
                throws java.io.IOException
Reads the field names from the first line of the csv file Assumes the input pointer is ready at the start of the file

readTypes

public void readTypes()
               throws java.io.IOException,
                      java.text.ParseException
Reads the corresponding types from the second line of csv file Assumes the input pointer is at the start of the second line of the csv file.

readData

public void readData()
              throws java.io.IOException,
                     java.text.ParseException
Reads from the data source and parses its contents to create a DataItemCollection
Specified by:
readData in interface DataLoader

parseDataItem

public DataItem parseDataItem(java.lang.String line)
                       throws java.text.ParseException
Method to parse a data item, turns the String of fields in the data item into a dataItem object. Also does work on normalization data - incremements the sumOfVals and the sumOfSquares arrays
Specified by:
parseDataItem in interface DataLoader
Parameters:
line - The line containing the data for this item
Returns:
The DataItem object that is created.

getDataItemCollection

public DataItemCollection getDataItemCollection()
Returns a DataItemCollection object containing the data in the csv file
Specified by:
getDataItemCollection in interface DataLoader
Returns:
The DataItemCollection containing all the data.

getFields

public java.util.ArrayList getFields()
gets the field names in the csv file
Specified by:
getFields in interface DataLoader
Returns:
The field names in the csv

getTypes

public java.util.ArrayList getTypes()
Gets the types that correspond to the field names,
Specified by:
getTypes in interface DataLoader
Returns:
The types of each field name in the csv

getLengthOfTask

public int getLengthOfTask()
Returns the length of this current task, this is defined to be some kind of abstract work unit. For example a 1000 line text file might return a task length of 1000, and would consider reading a line of the file as doing a unit of work
Specified by:
getLengthOfTask in interface MonitorableTask
Returns:
The length of the task in abstract work units

getProgress

public int getProgress()
Returns the current progress through this task. This is the number of units that have been completed
Specified by:
getProgress in interface MonitorableTask
Returns:
The current progress through the task

isFinished

public boolean isFinished()
Returns whether or not the current task has been completed
Specified by:
isFinished in interface MonitorableTask
Returns:
Whether or not the task has finished

doneWork

public void doneWork()
A method that is called when ever an item of work has been completed
Specified by:
doneWork in interface MonitorableTask

doneWork

public void doneWork(int units)
A method that is called when ever a number of work items have been completed
Specified by:
doneWork in interface MonitorableTask
Parameters:
units - The number of work units that where comleted