|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--bill.util.csv.CSVLineParser
Class for parsing line of CSV data, typically from a file. Breaks the line down into its component parts, or columns, and stores those parts in a Vector. A CSV file is a comma delimited text data file with some special formatting for embedded commas and quotes.
Constructor Summary | |
CSVLineParser()
Default constructor, initializes vector for holding line parts. |
|
CSVLineParser(String line)
Main constructor, parses the specified line to break out it's parts. |
|
CSVLineParser(String line,
boolean trim)
Alternate constructor, parses the specified line to break out it's parts. |
Method Summary | |
void |
addLinePart(int partNum,
String part)
Inserts the specified line part at the specified index. |
void |
addLinePart(String part)
Appends the specified line part to the current list of line parts. |
void |
dumpParts()
For debugging purposes, dumps the list of parts to standard output. |
String |
getLine()
Returns the CSV line in the format it is persistently stored. |
String |
getLinePart(int partNum)
Retrieves a specific line part from the list of parts. |
Vector |
getLineParts()
Returns the list of the parts parsed from the line. |
int |
getNumberOfLineParts()
Determines the number of parts the parsed line contains. |
String |
getUnformattedLine()
Retrieves the CSV line in an unformatted representation. |
boolean |
isTrimmed()
Checks to see if line parts are trimmed. |
static void |
main(String[] argv)
|
protected void |
parseLine(String line)
Parses the specified line to break it up into its parts. |
protected void |
parseLine(String line,
boolean trim)
Parses the specified line to break it up into its parts. |
void |
removeLinePart(int partNum)
Deletes the line part at the specified index. |
void |
setLine(String line)
Allows the caller to specify the 'raw' line to be parsed. |
void |
setLinePart(int partNum,
String part)
Sets the value of the given line part to the specified string. |
void |
setLineParts(Vector parts)
Sets the list of parts parsed from the line. |
void |
setTrimmed(boolean trim)
Sets the trimmed flag to indicate if line part values where trimmed when this line was parsed. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CSVLineParser()
setLine(String)
public CSVLineParser(String line)
line
- The line to split up into its parts.public CSVLineParser(String line, boolean trim)
line
- The line to split up into its parts.trim
- When set to true
the column value that is
parsed out is trimmed of leading and trailing spaces. This is only
relevant for quoted values, as non quoted values are always trimmed.Method Detail |
public void setLine(String line)
line
- The line to split up into its parts.protected void parseLine(String line)
line
- The line of data to be parsedprotected void parseLine(String line, boolean trim)
line
- The line of data to be parsedtrim
- When set to true
the column value that is
parsed out is trimmed of leading and trailing spaces. This is only
relevant for quoted values, as non quoted values are always trimmed.public String getLine()
public String getUnformattedLine()
Note that if any of the values have commas in them then there may appear to be extra elements in the output if those values do not also include quotes.
public void setLinePart(int partNum, String part)
partNum
- The index of the part to be set, this is a 0
(zero) based value, so 0 = first part.part
- The string value to set the line part to.public int getNumberOfLineParts()
public boolean isTrimmed()
true
if line parts are trimmed, returns
false
otherwise.public void setTrimmed(boolean trim)
trim
- Value to set the flag to.public Vector getLineParts()
public void setLineParts(Vector parts)
parts
- List of parts to be assigned.public String getLinePart(int partNum)
partNum
- The index of the part to be retrieved, this is a 0
(zero) based value, so 0 = first part.public void addLinePart(String part)
part
- The line part to add.public void addLinePart(int partNum, String part)
partNum
- The index to insert the new line part at.part
- The line part to add.public void removeLinePart(int partNum)
partNum
- The index of the line part to remove.public void dumpParts()
public static void main(String[] argv)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |