platypus
Class Infile

java.lang.Object
  extended by platypus.Infile

public class Infile
extends java.lang.Object

Handles input file I/O functions. Note that in Platypus, all input files are read into memory (into an array of lines) when opened. They are then closed. And we work from the array of lines.

Author:
alb

Field Summary
(package private)  int commentLines
          used only for unit testing purposes
(package private)  int currLineNumber
          the line number in the original input file (from ReadLine)
private  java.lang.String filename
          the name of the input file
(package private)  GDD gdd
           
(package private)  GID gid
           
private static int textLineIndex
          this is the index to the textLines ArrayList that holds the lines of text.
(package private)  java.util.ArrayList<ReadLine> textLines
          array of ReadLines into which Infile is parsed
 
Constructor Summary
Infile(java.lang.String name)
           
 
Method Summary
(package private)  java.lang.String composeEndOfComment(int start, java.lang.String textline)
          Accepts a line of text and an index of the first character of an opening comment block.
 boolean doesExist()
          Verifies the existence of a specific file.
 java.lang.String getFilename()
           
 int getLine()
          Gets the next line in the ArrayList of parsed lines from the input file.
 int getLineCount()
          used primarily (exclusively?) in unit tests
 int getLineNumber()
          returns the current line number being handled by Infile
 java.util.ArrayList<ReadLine> getTextLines()
           
 void incrementLineCount()
          convenience function for incrementing the pointer to the next line in the input stream
 boolean isReadable()
          Verifies that the file can be read.
 int readFile()
          Reads the input file on a line basis, adding each line to an ArrayList for later processing.
(package private)  boolean startsWithEndOfBlockComment(java.lang.String line)
          Determines whether a line that starts with %% is part of a closing comment block.
 int stripBlockComments()
          Remove block comments from textLines array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filename

private java.lang.String filename
the name of the input file


textLines

java.util.ArrayList<ReadLine> textLines
array of ReadLines into which Infile is parsed


currLineNumber

int currLineNumber
the line number in the original input file (from ReadLine)


commentLines

int commentLines
used only for unit testing purposes


gid

GID gid

gdd

GDD gdd

textLineIndex

private static int textLineIndex
this is the index to the textLines ArrayList that holds the lines of text. It tells us where we are in the ArrayList for purposes of reading the next line.

Constructor Detail

Infile

public Infile(java.lang.String name)
Method Detail

readFile

public int readFile()
Reads the input file on a line basis, adding each line to an ArrayList for later processing. Lines where the first character is a comment are skipped (that is, not saved) in this process.

Returns:
the number the total number of lines read or an error code on exception

startsWithEndOfBlockComment

boolean startsWithEndOfBlockComment(java.lang.String line)
Determines whether a line that starts with %% is part of a closing comment block. Comment blocks close with %%], where the number of %% is some number >= 2

Parameters:
line - the line to check
Returns:
true if pattern found at beginning of line, false otherwise

stripBlockComments

public int stripBlockComments()
Remove block comments from textLines array. Block comments open with [%% and close with %%] The number of %'s can be up to 100 and opening and closing asterisk counts must match. So [%%% not right %%] is invalid, but [%%% is right %%] %%%] is a valid comment. The interior %%] is ignored. Block comments close upon finding a closing match regardless of where in the file it occurs.

Returns:
number of block comments found. UNCLOSED_COMMENT_BLK if an unclosed comment exists

composeEndOfComment

java.lang.String composeEndOfComment(int start,
                                     java.lang.String textline)
Accepts a line of text and an index of the first character of an opening comment block. It then creates a string that contains the corresponding closing comment marker.

Parameters:
start - index into textline that points to where the opening marker begins
textline - the line of text with the opening block comment marker embedded
Returns:
a string containing the corresponding endOfComment block marker

getLine

public int getLine()
Gets the next line in the ArrayList of parsed lines from the input file. It skips over comment lines. Empty lines are replaced by an end-of-paragraph token. The line is then trimmed of leading and trailing whitespace and placed in gid.currLine.

Returns:
Status.AT_EOF at EOF, or Status.NO_ERROR if no problem occurred.

doesExist

public boolean doesExist()
Verifies the existence of a specific file.

Returns:
boolean indicating whether file exists

isReadable

public boolean isReadable()
Verifies that the file can be read.

Returns:
boolean indicating whether file exists

incrementLineCount

public void incrementLineCount()
convenience function for incrementing the pointer to the next line in the input stream


getFilename

public java.lang.String getFilename()

getTextLines

public java.util.ArrayList<ReadLine> getTextLines()

getLineNumber

public int getLineNumber()
returns the current line number being handled by Infile

Returns:
the current line number

getLineCount

public int getLineCount()
used primarily (exclusively?) in unit tests

Returns:
the number of the current line


Copyright © 2006-7 Pacific Data Works LLC