com.conradroche.matra.data
Class Data

java.lang.Object
  |
  +--com.conradroche.matra.data.Data
Direct Known Subclasses:
ParseableData

public class Data
extends java.lang.Object

Utility class to parse a String.

Author:
Conrad Roche

Field Summary
static int CHAR_NOT_FOUND
          Denotes that the char searched was not found.
static char END_OF_DATA_CHAR
          Denotes end of data stream.
static int FOUND_CHAR
          Denotes that the char searched was found.
 
Constructor Summary
Data()
          Data constructor.
Data(Data newData)
          Data copy constructor.
Data(java.lang.String strData)
          Data Constructor.
 
Method Summary
 int checkNextChar(char lookupChar)
          Checks if the next char is the one specified.
 boolean endOfData()
          Check if the end of the data stream is reached.
 int getColumn()
          Returns the current column being read.
 CursorLocation getCurrentLocation()
          Returns the current location in terms of rows and columns.
 int getCurrentPosition()
          Get the current reading position in the Data stream - as measured in the number of chars from the beginning of the data.
 char getNextChar()
          Read the next char from the data stream.
 char getPrevChar()
          Get the previous char read from the data stream.
 java.lang.String getRemaining()
          Get the unread part of the data stream.
 int getRow()
          Returns the current row being read.
 int length()
          Get the total length of the data stream.
 char lookNextChar()
          Peek at the next char to be read.
 char peekAhead(int numChars)
          Peek ahead n number of chars from the data.
 void reset()
          Reset the data for use.
 void rewind()
          Move the current read position back to the beginning of the data stream.
 java.lang.String toString()
          Return the String representation of the data stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

END_OF_DATA_CHAR

public static final char END_OF_DATA_CHAR
Denotes end of data stream. This is used in the lookNextChar and getPreviousChar methods when at the edge of the data.

FOUND_CHAR

public static final int FOUND_CHAR
Denotes that the char searched was found.

CHAR_NOT_FOUND

public static final int CHAR_NOT_FOUND
Denotes that the char searched was not found.
Constructor Detail

Data

public Data()
Data constructor.

Data

public Data(Data newData)
Data copy constructor.

Data

public Data(java.lang.String strData)
Data Constructor.
Parameters:
StrData - The data to be parsed.
Method Detail

endOfData

public boolean endOfData()
Check if the end of the data stream is reached.
Returns:
true of end of data is reached; false if end of data is not reached.

getCurrentLocation

public CursorLocation getCurrentLocation()
Returns the current location in terms of rows and columns.
Returns:
The current location.

getRow

public int getRow()
Returns the current row being read.
Returns:
The current row.

getColumn

public int getColumn()
Returns the current column being read.
Returns:
The current column.

getCurrentPosition

public int getCurrentPosition()
Get the current reading position in the Data stream - as measured in the number of chars from the beginning of the data.
Returns:
The current position.

getNextChar

public char getNextChar()
Read the next char from the data stream.
Returns:
The next char.

checkNextChar

public int checkNextChar(char lookupChar)
Checks if the next char is the one specified. If the next char is the char specified, move ahead by one char (i.e. read the char).
Returns:
Returns FOUND_CHAR if the next char is the one specified, returns CHAR_NOT_FOUND if not.

getPrevChar

public char getPrevChar()
Get the previous char read from the data stream.
Returns:
The previous char.

getRemaining

public java.lang.String getRemaining()
Get the unread part of the data stream.
Returns:
The remaining data string.

length

public int length()
Get the total length of the data stream.
Returns:
Total length of data.

lookNextChar

public char lookNextChar()
Peek at the next char to be read.
Returns:
The next unread character in the data.

peekAhead

public char peekAhead(int numChars)
Peek ahead n number of chars from the data.
Parameters:
numChars - Number of characters to peek ahead. 0 will return current char, 1 will return next char
Returns:
The peeked char.

reset

public void reset()
Reset the data for use.

rewind

public void rewind()
Move the current read position back to the beginning of the data stream.

toString

public java.lang.String toString()
Return the String representation of the data stream.
Overrides:
toString in class java.lang.Object
Returns:
The string data.