net.talvi.puffinplot.data.file
Class FileFormat

java.lang.Object
  extended by net.talvi.puffinplot.data.file.FileFormat

public final class FileFormat
extends java.lang.Object

This class represents an ASCII-based file format with one row per measurement. It defines the mapping from column numbers to data fields, and the number of header lines to be skipped. Columns are zero-indexed.


Constructor Summary
FileFormat(java.util.Map<java.lang.Integer,DatumField> columnMap, int headerLines, MeasType measurementType, TreatType treatmentType, java.lang.String separator, boolean useFixedWidthColumns, java.util.List<java.lang.Integer> columnWidths)
          Creates a new file format with the specified parameters.
 
Method Summary
static java.util.List<java.lang.Integer> convertStringToColumnWidths(java.lang.String widthString)
          Turns a string containing comma-separated decimal integers into a List of {@link Integer.
 java.util.Map<java.lang.Integer,DatumField> getColumnMap()
           
 java.lang.String getColumnWidthsAsString()
           
 int getHeaderLines()
           
 MeasType getMeasurementType()
           
 java.lang.String getSeparator()
           
 TreatType getTreatmentType()
           
static FileFormat readFromPrefs(java.util.prefs.Preferences prefs)
          Creates a format from a preferences object.
 Datum readLine(java.lang.String line)
          Creates a Datum from a line formatted according to this format.
 java.util.List<Datum> readLines(java.util.List<java.lang.String> lines)
          Reds a list of lines in this format and produces the corresponding Datums.
 boolean useFixedWidthColumns()
           
 void writeToPrefs(java.util.prefs.Preferences prefs)
          Saves this format to a preferences object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileFormat

public FileFormat(java.util.Map<java.lang.Integer,DatumField> columnMap,
                  int headerLines,
                  MeasType measurementType,
                  TreatType treatmentType,
                  java.lang.String separator,
                  boolean useFixedWidthColumns,
                  java.util.List<java.lang.Integer> columnWidths)
Creates a new file format with the specified parameters.

Parameters:
columnMap - a mapping from column numbers (0-indexed) to data fields
headerLines - number of header lines to skip
measurementType - type of all measurements in file
treatmentType - type of all treatments in file
separator - column separator for non-fixed-width-column formats
useFixedWidthColumns - whether this format uses fixed-width columns
columnWidths - the widths of columns for fixed-width-column formats
Method Detail

readLine

public Datum readLine(java.lang.String line)
Creates a Datum from a line formatted according to this format.

Parameters:
line - a line formatted according this this format
Returns:
the datum defined by the supplied line

readLines

public java.util.List<Datum> readLines(java.util.List<java.lang.String> lines)
Reds a list of lines in this format and produces the corresponding Datums.

Parameters:
lines - a list of lines in this format
Returns:
the data defined by the lines (in the same order)

convertStringToColumnWidths

public static java.util.List<java.lang.Integer> convertStringToColumnWidths(java.lang.String widthString)
Turns a string containing comma-separated decimal integers into a List of {@link Integer.

Parameters:
widthString - a string of comma-separated decimal integers
Returns:
the list of integers defined by the input string

getColumnWidthsAsString

public java.lang.String getColumnWidthsAsString()
Returns:
the column widths for this format as a string of comma-separated decimal integers

writeToPrefs

public void writeToPrefs(java.util.prefs.Preferences prefs)
Saves this format to a preferences object.

Parameters:
prefs - the preferences to which to save this format

readFromPrefs

public static FileFormat readFromPrefs(java.util.prefs.Preferences prefs)
Creates a format from a preferences object.

Parameters:
prefs - a preferences object containing the data for a format
Returns:
the corresponding format

getMeasurementType

public MeasType getMeasurementType()
Returns:
the measurement type for the file

getTreatmentType

public TreatType getTreatmentType()
Returns:
the treatment type for the file

getColumnMap

public java.util.Map<java.lang.Integer,DatumField> getColumnMap()
Returns:
the mapping between column numbers and data field types

getHeaderLines

public int getHeaderLines()
Returns:
the number of header lines to skip at the start of the file

getSeparator

public java.lang.String getSeparator()
Returns:
a regular expression matching the column separator

useFixedWidthColumns

public boolean useFixedWidthColumns()
Returns:
true if the format uses fixed-width columns