FileDocCategorySizeDatePackage
TermsAccessor.javaAPI DocExample1612Thu Apr 06 13:43:14 BST 2000None

TermsAccessor

public class TermsAccessor extends Object
This class provides access to the list of terms and definitions, hiding the physical location and organization of the data.

Fields Summary
protected BufferedReader
is
protected String
ident
Constructors Summary
public TermsAccessor(String inputFileName)
constructor that takes a FileName

		is = new BufferedReader(new FileReader("terms.txt"));
		String ident = is.readLine();
	
Methods Summary
public java.lang.StringgetIdent()
return the identifier string from the source

		return ident;
	
public java.util.Iteratoriterator()
This iterator() method simply defines an inner class that each time hasNext() succeeds, calling next() will a Term object, containing the term and definition.

		return new Iterator() {
			String line, term, defn;

			/** The hasNext() method returns true up until end of file. */
			public boolean hasNext() {
				try {
					return ((line = is.readLine()) != null);
				} catch (IOException e) {
					System.err.println("IO Error: " + e);
					return false;
				}
			}

			/** The next() method returns the next available Term object */
			public Object next() {
				int i;
				// loop, ignoring invalid lines.
				while ((i = line.indexOf("\t"))<0 && hasNext());
					;
				if (line == null)
					throw new IllegalStateException("Invalid EOF state");
				term = line.substring(0, i);
				defn = line.substring(i+1);
				return new Term(term, defn);
			}

			/** The remove method is not implemented: just throws. */
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};