-bottom

net.sf.csv4j
Class CSVTokenizer

java.lang.Object
  extended by net.sf.csv4j.CSVTokenizer
All Implemented Interfaces:
Iterable<String>, Enumeration<String>, Iterator<String>, Tokenizer<String>

public class CSVTokenizer
extends Object
implements Tokenizer<String>, Enumeration<String>, Iterator<String>, Iterable<String>

Provides an API similar to StringTokenizer. In addition to StringTokenizer's two interfaces, this class also supports the Iterator interface. It supports too many style of iterations as a result:

Since:
1.0
Author:
Shawn Boyce
See Also:
Comma Separated Values on Wikipedia, StringTokenizer

Constructor Summary
CSVTokenizer(String line)
          Creates a tokenizer from the specified CSV line.
 
Method Summary
 int countTokens()
          Indicates how many tokens are left.
 boolean hasMoreElements()
          
 boolean hasMoreTokens()
          Indicates if more tokens are available.
 boolean hasNext()
          
 Iterator<String> iterator()
          
 String next()
          
 String nextElement()
          
 String nextToken()
          Returns the next token.
 void remove()
          Not supported.
 void reset()
          Reset the iterator back to the beginning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVTokenizer

public CSVTokenizer(String line)
             throws ParseException
Creates a tokenizer from the specified CSV line.

Parameters:
line - string to tokenize
Throws:
ParseException - if the line cannot be tokenized
Method Detail

nextToken

public String nextToken()
Returns the next token.

Specified by:
nextToken in interface Tokenizer<String>
Returns:
next token string

hasMoreTokens

public boolean hasMoreTokens()
Indicates if more tokens are available.

Specified by:
hasMoreTokens in interface Tokenizer<String>
Returns:
true if more tokens; false if not

countTokens

public int countTokens()
Indicates how many tokens are left. Note the value returned is not constant; calls to Tokenizer.nextToken() will cause the count to reduce.

Specified by:
countTokens in interface Tokenizer<String>
Returns:
number of tokens left

hasMoreElements

public boolean hasMoreElements()

Specified by:
hasMoreElements in interface Enumeration<String>

nextElement

public String nextElement()

Specified by:
nextElement in interface Enumeration<String>

hasNext

public boolean hasNext()

Specified by:
hasNext in interface Iterator<String>

next

public String next()

Specified by:
next in interface Iterator<String>

remove

public void remove()
Not supported.

Specified by:
remove in interface Iterator<String>
Throws:
RuntimeException - always thrown

reset

public void reset()
Reset the iterator back to the beginning.


iterator

public Iterator<String> iterator()

Specified by:
iterator in interface Iterable<String>

-bottom