org.tranche.tasks
Class CSVFile

java.lang.Object
  extended by org.tranche.tasks.CSVFile

public class CSVFile
extends java.lang.Object

Abstracts a comma-separated value file. Use the reader to build.

Author:
Bryan Smith - bryanesmith@gmail.com

Constructor Summary
CSVFile(java.io.File file, java.util.List<java.lang.String> legend, java.util.List<java.util.Map<java.lang.String,java.lang.String>> records)
           
 
Method Summary
 boolean appendRecord(java.util.Map<java.lang.String,java.lang.String> record)
          Appends a record to CSVFile representation.
 CSVFile clone()
          Returns a clone (deep copy).
 boolean equals(java.lang.Object o)
          Returns whether this CSV File is the same as the given CSV File.
 java.lang.Object getEntry(int index, java.lang.String key)
          Returns an entry within a particular record using a key.
 java.io.File getFile()
          Returnst the CSV file.
 java.util.List<java.lang.String> getLegend()
          Returns the list of keys in order of appearance in the file.
 java.util.Map<java.lang.String,java.lang.String> getRecord(int index)
          Returns a record found in a row.
 java.util.List<java.util.Map<java.lang.String,java.lang.String>> getRecords()
          Returns the records of the CSV file.
 void printContents(java.io.PrintStream out)
          Prints the CSV file to the given output stream.
 java.util.Map<java.lang.String,java.lang.String> removeRecord(int index)
          Remove the record with the given index.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVFile

public CSVFile(java.io.File file,
               java.util.List<java.lang.String> legend,
               java.util.List<java.util.Map<java.lang.String,java.lang.String>> records)
Parameters:
file - the file received
legend - the list of keys received
records - the records received
Method Detail

getFile

public java.io.File getFile()

Returnst the CSV file.

Returns:
the file

getLegend

public java.util.List<java.lang.String> getLegend()

Returns the list of keys in order of appearance in the file.

Returns:
the list of keys in order of appearance in the file

getRecord

public java.util.Map<java.lang.String,java.lang.String> getRecord(int index)

Returns a record found in a row. The rows are zero-indexed starting with the first valid record and incremented by subsequent valid records.

Parameters:
index - the index of the desired record
Returns:
the record found at the given index

removeRecord

public java.util.Map<java.lang.String,java.lang.String> removeRecord(int index)

Remove the record with the given index.

Parameters:
index -
Returns:

appendRecord

public boolean appendRecord(java.util.Map<java.lang.String,java.lang.String> record)

Appends a record to CSVFile representation. To store, you must rewrite the file using the writer.

Parameters:
record - the record
Returns:
true if the record is appended; false otherwise

getEntry

public java.lang.Object getEntry(int index,
                                 java.lang.String key)

Returns an entry within a particular record using a key. The list of keys are available as the legend.

Parameters:
index - the index of the record seeked
key - the key used to retrieve an entry within the seeked record
Returns:
the entry with the given key within the seeked record

getRecords

public java.util.List<java.util.Map<java.lang.String,java.lang.String>> getRecords()

Returns the records of the CSV file.

Returns:
the list of records

clone

public CSVFile clone()

Returns a clone (deep copy). Useful for:

Overrides:
clone in class java.lang.Object
Returns:

printContents

public void printContents(java.io.PrintStream out)

Prints the CSV file to the given output stream.

Parameters:
out - the output stream

equals

public boolean equals(java.lang.Object o)

Returns whether this CSV File is the same as the given CSV File.

Overrides:
equals in class java.lang.Object
Parameters:
o -
Returns:


This code is free for use both commercially and non-commercially as stated in the project's license