bill.util.csv
Class CSVParserSorted

java.lang.Object
  |
  +--bill.util.csv.CSVParser
        |
        +--bill.util.csv.CSVParserSorted

public class CSVParserSorted
extends CSVParser

Controls the reading of a CSV file. A CSV file is a comma delimited text data file. This class extends the standard CSV parser and implements sorting of the CSV data. The user must specify the sort columns using the setSortOrder method to enable the sorting functionality.


Fields inherited from class bill.util.csv.CSVParser
_csvLines, _fileName, _header, _modified, _reader, _skipLines, _writer
 
Constructor Summary
CSVParserSorted(OutputStream writer)
          Alternate constructor for skipping lines.
CSVParserSorted(Reader reader)
          Main constructor.
CSVParserSorted(Reader reader, int skipLines)
          Alternate constructor for skipping lines.
CSVParserSorted(Reader reader, OutputStream writer)
          Alternate constructor.
CSVParserSorted(Reader reader, OutputStream writer, int skipLines)
          Alternate constructor for skipping lines.
CSVParserSorted(String fileName)
          Main constructor.
CSVParserSorted(String fileName, int skipLines)
          Alternate constructor for skipping lines.
 
Method Summary
 void addLine(CSVLineParser line)
          Appends the specified line to the current list of lines.
 void setLineLinePart(int lineNum, int partNum, String value)
          Sets the specified line part from the specified line.
 void setLineLinePart(int lineNum, String partName, String value)
          Sets the specified line part from the specified line.
 void setReverse(boolean reverse)
          Sets the reverse sort flag.
 void setSortOrder(int[] order)
          Sets the sort order array.
 void sort()
          Sorts the list of CSV lines using the previously defined sort order.
 
Methods inherited from class bill.util.csv.CSVParser
addLine, getFileName, getHeader, getLine, getLineLinePart, getLineLinePart, getLines, getNumberOfLines, getPartNumber, hasHeader, isModified, main, removeLine, save, setFileName, setModified, swapLines
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVParserSorted

public CSVParserSorted(String fileName)
                throws CSVException
Main constructor. Opens up the CSV input file and processes its data lines.
Parameters:
fileName - The name of the CSV input file.
Throws:
CSVException - If the input file cannot be found, opened, or processed.

CSVParserSorted

public CSVParserSorted(Reader reader)
                throws CSVException
Main constructor. Reads specified CSV input stream and processes its data lines. Note that when this constructor is used the save method may not be used unless the setFileName method is first called. This is because we cannot determine a file name from just the stream.
Parameters:
reader - The CSV input stream.
Throws:
CSVException - If the input file cannot be found, opened, or processed.
See Also:
CSVParser.save(), CSVParser.setFileName(String)

CSVParserSorted

public CSVParserSorted(String fileName,
                       int skipLines)
                throws CSVException
Alternate constructor for skipping lines. Opens up the CSV input file and processes its data lines. Use this constructor when there are a set number of lines of data before the CSV header line. The extra lines are ignored.
Parameters:
fileName - The name of the CSV input file.
skipLines - Number of lines to skip before 'really' reading the file. This is to get past any lines that may be before the header.
Throws:
CSVException - If the input file cannot be found, opened, or processed.

CSVParserSorted

public CSVParserSorted(Reader reader,
                       int skipLines)
                throws CSVException
Alternate constructor for skipping lines. Reads specified CSV input stream and processes its data lines. Note that when this constructor is used the save method may not be used unless the setFileName method is first called. This is because we cannot determine a file name from just the stream.
Parameters:
reader - The CSV input stream.
skipLines - Number of lines to skip before 'really' reading the file. This is to get past any lines that may be before the header.
Throws:
CSVException - If the input file cannot be found, opened, or processed.
See Also:
CSVParser.save(), CSVParser.setFileName(String)

CSVParserSorted

public CSVParserSorted(Reader reader,
                       OutputStream writer)
                throws CSVException
Alternate constructor. Reads specified CSV input stream and processes its data lines.
Parameters:
reader - The CSV input stream.
writer - The output stream to write to when saving.
Throws:
CSVException - If the input file cannot be found, opened, or processed.

CSVParserSorted

public CSVParserSorted(Reader reader,
                       OutputStream writer,
                       int skipLines)
                throws CSVException
Alternate constructor for skipping lines. Reads specified CSV input stream and processes its data lines.
Parameters:
reader - The CSV input stream.
writer - The output stream to write to when saving.
skipLines - Number of lines to skip before 'really' reading the file. This is to get past any lines that may be before the header.
Throws:
CSVException - If the input file cannot be found, opened, or processed.

CSVParserSorted

public CSVParserSorted(OutputStream writer)
Alternate constructor for skipping lines. Reads specified CSV input stream and processes its data lines.
Parameters:
writer - The output stream to write to when saving.
Method Detail

setReverse

public void setReverse(boolean reverse)
Sets the reverse sort flag. When set to true this causes all the sort order columns to be sorted in reverse order rather than regular order.
Parameters:
reverse - Value to set the reverse flag to.

setSortOrder

public void setSortOrder(int[] order)
Sets the sort order array. This is an array of integers representing the column numbers to sort on. The first array element is the primary sort column, the second is the secondary, etc. Column numbers are 0 based.
Parameters:
order - The sort order array.

sort

public void sort()
Sorts the list of CSV lines using the previously defined sort order.

setLineLinePart

public void setLineLinePart(int lineNum,
                            int partNum,
                            String value)
Sets the specified line part from the specified line.
Overrides:
setLineLinePart in class CSVParser
Parameters:
lineNum - The data line to retrieve line part from. Uses a 0 based counter, so the first data line is considered line 0.
partName - The name of the part to be retrieved, based on the part names read from the header line.

setLineLinePart

public void setLineLinePart(int lineNum,
                            String partName,
                            String value)
                     throws CSVException
Sets the specified line part from the specified line.
Overrides:
setLineLinePart in class CSVParser
Parameters:
lineNum - The data line to retrieve line part from. Uses a 0 based counter, so the first data line is considered line 0.
partName - The name of the part to be retrieved, based on the part names read from the header line.
Throws:
CSVException - Thrown when the part name is not valid.

addLine

public void addLine(CSVLineParser line)
Appends the specified line to the current list of lines.
Overrides:
addLine in class CSVParser
Parameters:
line - The line parser information to add.