gov.sandia.cognition.io
Class ReaderTokenizer

java.lang.Object
  extended by gov.sandia.cognition.io.ReaderTokenizer

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-02-08",
            changesNeeded=true,
            comments={"Should this class be merged with CSVUtility?","To a large extend, this class seems like a generalization of CSV.","Please review."},
            response=@CodeReviewResponse(respondent="Justin Basilico",date="2008-02-18",moreChangesNeeded=false,comments="No, its different enough that it could exist on its own."))
public class ReaderTokenizer
extends Object

Reads each line from a Reader, and returns each line as a List of Strings

Since:
1.0
Author:
Kevin R. Dixon

Constructor Summary
ReaderTokenizer(Reader reader)
          Creates a new instance of ReaderTokenizer
 
Method Summary
 BufferedReader getBufferedReader()
          Getter for bufferedReader
protected  int getLastTokenNum()
          Getter for lastTokenNum
 boolean isValid()
          Returns the status of the ReaderTokenizer
 ArrayList<String> readNextLine()
          Reads the next line of the Reader, returning each token on the line as an entry in an ArrayList
 void setBufferedReader(BufferedReader bufferedReader)
          Setter for bufferedReader
protected  void setLastTokenNum(int lastTokenNum)
          Setter for lastTokenNum
protected  void setValid(boolean valid)
          Setter for valid
static ArrayList<String> tokenizeString(String data)
          Returns an ArrayList with each of the tokens as an entry in the array
static ArrayList<String> tokenizeString(String data, int expectedTokenNum)
          Returns an ArrayList with each of the tokens as an entry in the array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderTokenizer

public ReaderTokenizer(Reader reader)
Creates a new instance of ReaderTokenizer

Parameters:
reader - Input stream from which to parse lines
Method Detail

isValid

public boolean isValid()
Returns the status of the ReaderTokenizer

Returns:
true if valid, false otherwise

tokenizeString

public static ArrayList<String> tokenizeString(String data)
Returns an ArrayList with each of the tokens as an entry in the array

Parameters:
data - String to tokenize
Returns:
ArrayList where the ith entry is the ith token on the line

tokenizeString

public static ArrayList<String> tokenizeString(String data,
                                               int expectedTokenNum)
Returns an ArrayList with each of the tokens as an entry in the array

Parameters:
data - String to tokenize
expectedTokenNum - Expected number of tokens on the line, may be greater than or less than actual amount, but algorithm will be faster if the number is correct. Throws run-time exception if less than zero.
Returns:
ArrayList where the ith entry is the ith token on the line

readNextLine

public ArrayList<String> readNextLine()
                               throws IOException
Reads the next line of the Reader, returning each token on the line as an entry in an ArrayList

Returns:
ArrayList where each element is a token on the line
Throws:
IOException - if the read fails

setValid

protected void setValid(boolean valid)
Setter for valid

Parameters:
valid - status of the ReaderTokenizer

getLastTokenNum

protected int getLastTokenNum()
Getter for lastTokenNum

Returns:
Number of tokens read in the last call to readNextLine()

setLastTokenNum

protected void setLastTokenNum(int lastTokenNum)
Setter for lastTokenNum

Parameters:
lastTokenNum - Number of tokens read in the last call to readNextLine()

getBufferedReader

public BufferedReader getBufferedReader()
Getter for bufferedReader

Returns:
BufferedReader from which we will read lines

setBufferedReader

public void setBufferedReader(BufferedReader bufferedReader)
Setter for bufferedReader

Parameters:
bufferedReader - BufferedReader from which we will read lines