Class MVFieldReader

java.lang.Object
  extended byMVFieldReader

public class MVFieldReader
extends java.lang.Object

An object which can read a text file containing information about movies, making each field available in turn. The fields on the file are strings, and are separated by a delimiter. The exact meaning of the fields is unknown to this class. See the description of CSE142 Assignment 4, Spring 2004 to know the order that fields should be in on the text file.
For this assignment, you do NOT read the text file directly, although you must download and copy it to your computer along with certain .class files. The way you get movie data is by using this MVFieldReader class.
After the last field expected of each line is read, the file automatically advances to the next line. The field values returned for strings could be empty, but will not be null. All fields are trimmed of any leading and trailing spaces. The delimiter is never returned as part of any field. An error will occur if data beyond the end of file is requested. Results are unspecified if any line of the file doesn't contain at least the expected number of fields.


Field Summary
static int MOVIE_FIELD_COUNT
          Expected number of fields on each line of a movie text file.
static java.lang.String MOVIE_FILE_DELIMITER
          Expected delimiter separating fields on the underlying text file.
 
Constructor Summary
MVFieldReader(java.lang.String filename)
          Locate and open a CSE142 movie file.
 
Method Summary
 java.lang.String getNextField()
          Get the next field from the file.
 boolean hasMore()
          Tells if the file has more data.
 boolean isAtEnd()
          Tell if the file is at end.
 java.lang.String toString()
          Tells some information about this MVFieldReader object; the format and contents of this information should not be relied on.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MOVIE_FILE_DELIMITER

public static final java.lang.String MOVIE_FILE_DELIMITER
Expected delimiter separating fields on the underlying text file.

See Also:
Constant Field Values

MOVIE_FIELD_COUNT

public static final int MOVIE_FIELD_COUNT
Expected number of fields on each line of a movie text file. Fewer than this will probably cause an error; more than this will probably be ignored.

See Also:
Constant Field Values
Constructor Detail

MVFieldReader

public MVFieldReader(java.lang.String filename)
Locate and open a CSE142 movie file.

Parameters:
filename - a string identifying the file; this can be a full URL (local or remote); a full path on the local system; or a partial path (such as a simple filename). The file is searched for on the classpath first; ordinarily, if you are given a movie text file, you should put it in the same directory where the .class file is for MoveFile142. The lines of the text file must have fields in a certain expected order (CSE142 Assignment 4). In case the file cannot be located, there may be some informative messages on the console. Blank (empty) lines are ignored.
Method Detail

isAtEnd

public boolean isAtEnd()
Tell if the file is at end.

Returns:
true if there are no more records to process; false otherwise. End of file is reached after the last field of the last (non-empty) record was requested.

hasMore

public boolean hasMore()
Tells if the file has more data. Always the reverse of isAtEnd().

Returns:
the reverse of isAtEnd().

getNextField

public java.lang.String getNextField()
Get the next field from the file. If we have already read the expected number of fields from one line, we skip to the beginning of the next line. Thus, if there are more than the expected number (6 by default) on a line, any fields after that number are skipped. Any lines which are completely blank, or which have only blank fields, are skipped entirely. If a blank field occurs on a non-blank line, the blank field is returned as an empty string. The delimiters themselves are never returned as part of a field.
Example: suppose the following data is at the beginning of the file:
word1 word2/ word3 word4 /word5/ /word6 /
The the first 5 calls to getNextField would return these values:
"word1 word2", "word3 word4", "word5", "", "word6"

Returns:
the next string field from the file; might be empty, but will not be null.

toString

public java.lang.String toString()
Tells some information about this MVFieldReader object; the format and contents of this information should not be relied on.