au.csiro.netcdf.util
Class CSVTokenizer

java.lang.Object
  extended by java.util.StringTokenizer
      extended by au.csiro.netcdf.util.CSVTokenizer
All Implemented Interfaces:
Enumeration<Object>

public class CSVTokenizer
extends StringTokenizer

Specialised StringTokenizer proxy to handle lines from a CSV file. Copyright 2010, CSIRO Australia All rights reserved.

Version:
$Revision: 78 $ $Date: 2010-07-24 16:23:13 +1000 (Sat, 24 Jul 2010) $
Author:
James Dempsey on 10/06/2010

Constructor Summary
CSVTokenizer(String str)
          Constructs a CSV string tokenizer for the specified string.
CSVTokenizer(String str, boolean returnTokens)
          Constructs a CSV string tokenizer for the specified string.
CSVTokenizer(String str, char majorDelimiter, boolean returnTokens)
          Constructs a CSV string tokenizer for the specified string.
 
Method Summary
 boolean atEOL()
           
 int countTokens()
          We have deliberately excluded the count token method as it would require caching.
 String[] getAllColumns()
          Returns all remaining columns for this tokenizer as a string.
 boolean hasMoreElements()
           
 boolean hasMoreTokens()
           
 Object nextElement()
           
 String nextToken()
           
 
Methods inherited from class java.util.StringTokenizer
nextToken
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVTokenizer

public CSVTokenizer(String str)
Constructs a CSV string tokenizer for the specified string. Delimiter characters themselves will not be treated as tokens.

Parameters:
str - a string to be parsed.

CSVTokenizer

public CSVTokenizer(String str,
                    boolean returnTokens)
Constructs a CSV string tokenizer for the specified string. Delimiter characters themselves will not be treated as tokens.

If the returnTokens flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens. NB: The quotes around some strings will never come out as delimiters.

Parameters:
str - a string to be parsed.
returnTokens - flag indicating whether to return the delimiters as tokens.

CSVTokenizer

public CSVTokenizer(String str,
                    char majorDelimiter,
                    boolean returnTokens)
Constructs a CSV string tokenizer for the specified string. Delimiter characters themselves will not be treated as tokens.

The majorDelimiter value can be used to change the major delimiter used. Normally this will be a comma, but a tab could be supplied for a tab delimited file.

If the returnTokens flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens. NB: The quotes around some strings will never come out as delimiters.

Parameters:
str - a string to be parsed.
majorDelimiter - The major delimiter of the string to be parsed.
returnTokens - flag indicating whether to return the delimiters as tokens.
Method Detail

getAllColumns

public String[] getAllColumns()
Returns all remaining columns for this tokenizer as a string. This is similar to the split function for a string.

Returns:
An array of all remaining columns as strings.

countTokens

public int countTokens()
We have deliberately excluded the count token method as it would require caching.

Overrides:
countTokens in class StringTokenizer
Returns:
0

hasMoreElements

public boolean hasMoreElements()
Specified by:
hasMoreElements in interface Enumeration<Object>
Overrides:
hasMoreElements in class StringTokenizer

hasMoreTokens

public boolean hasMoreTokens()
Overrides:
hasMoreTokens in class StringTokenizer

atEOL

public boolean atEOL()

nextElement

public Object nextElement()
Specified by:
nextElement in interface Enumeration<Object>
Overrides:
nextElement in class StringTokenizer

nextToken

public String nextToken()
Overrides:
nextToken in class StringTokenizer


Copyright © 2010. All Rights Reserved.