org.encog.util.csv
Class ReadCSV

java.lang.Object
  extended by org.encog.util.csv.ReadCSV

public class ReadCSV
extends Object

Read and parse CSV format files.


Constructor Summary
ReadCSV(InputStream is, boolean headers, char delim)
          Construct a CSV reader from an input stream.
ReadCSV(InputStream is, boolean headers, CSVFormat format)
          Construct a CSV reader from an input stream.
ReadCSV(String filename, boolean headers, char delim)
          Construct a CSV reader from a filename.
ReadCSV(String filename, boolean headers, CSVFormat format)
          Construct a CSV reader from a filename.
 
Method Summary
 void close()
          Close the file.
static String displayDate(Date date)
          Format a date.
 String get(int i)
          Get the specified column as a string.
 String get(String column)
          Get the column by its string name, as a string.
 int getColumnCount()
          Get the column count.
 List<String> getColumnNames()
           
 Date getDate(String column)
          Get the column as a date.
 double getDouble(int index)
          Get the column as a double specified by index.
 double getDouble(String column)
          Get the specified column as a double.
 CSVFormat getFormat()
           
 int getInt(int i)
          Obtain a column as an integer referenced by a string.
 boolean hasMissing()
           
 boolean next()
          Read the next line.
static Date parseDate(String when)
          Parse a date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadCSV

public ReadCSV(InputStream is,
               boolean headers,
               char delim)
Construct a CSV reader from an input stream. Allows a delimiter character to be specified. Numbers will be parsed using the current locale.

Parameters:
is - The InputStream to read from.
headers - Are headers present?
delim - What is the delimiter.

ReadCSV

public ReadCSV(InputStream is,
               boolean headers,
               CSVFormat format)
Construct a CSV reader from an input stream. The format parameter specifies the separator character to use, as well as the number format.

Parameters:
is - The InputStream to read from.
headers - Are headers present?
format - What is the CSV format.

ReadCSV

public ReadCSV(String filename,
               boolean headers,
               char delim)
Construct a CSV reader from a filename. The format parameter specifies the separator character to use, as well as the number format.

Parameters:
filename - The filename.
headers - The headers.
delim - The delimiter.

ReadCSV

public ReadCSV(String filename,
               boolean headers,
               CSVFormat format)
Construct a CSV reader from a filename. Allows a delimiter character to be specified.

Parameters:
filename - The filename.
headers - The headers.
format - The format.
Method Detail

displayDate

public static String displayDate(Date date)
Format a date.

Parameters:
date - The date to format.
Returns:
The formatted date.

parseDate

public static Date parseDate(String when)
Parse a date.

Parameters:
when - The date string.
Returns:
The parsed date.

close

public void close()
Close the file.


get

public String get(int i)
Get the specified column as a string.

Parameters:
i - The column index, starting at zero.
Returns:
The column as a string.

get

public String get(String column)
Get the column by its string name, as a string. This will only work if column headers were defined that have string names.

Parameters:
column - The column name.
Returns:
The column data as a string.

getColumnCount

public int getColumnCount()
Get the column count.

Returns:
The column count.

getDate

public Date getDate(String column)
Get the column as a date.

Parameters:
column - The column header name.
Returns:
The column as a date.

getDouble

public double getDouble(int index)
Get the column as a double specified by index.

Parameters:
index - The column index, starting at zero.
Returns:
The data at the specified column.

getDouble

public double getDouble(String column)
Get the specified column as a double.

Parameters:
column - The column name that we want to get.
Returns:
The column data as a double.

getInt

public int getInt(int i)
Obtain a column as an integer referenced by a string.

Parameters:
i - The column header name being read.
Returns:
The column data as an integer.

next

public boolean next()
Read the next line.

Returns:
True if there are more lines to read.

getColumnNames

public List<String> getColumnNames()

getFormat

public CSVFormat getFormat()

hasMissing

public boolean hasMissing()


Copyright © 2014. All Rights Reserved.