Class TokenScanner

java.lang.Object
  extended by TokenScanner
All Implemented Interfaces:
java.util.Iterator<Token>

public class TokenScanner
extends java.lang.Object
implements java.util.Iterator<Token>

Provides a Token Iterator for a given Reader.

Hint: See the code for the WordScanner from Lecture.

See Also:
Token

Constructor Summary
TokenScanner(java.io.Reader in)
          Creates a TokenScanner for a given Reader.
 
Method Summary
 boolean hasNext()
          Determines whether there is another token available.
 boolean isWordCharacter(int c)
          Determines whether a given character is a valid word character.
 Token next()
          Returns the next token, or throws a NoSuchElementException if none remain.
 void remove()
          This functionality isn't supported by the TokenScanner.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TokenScanner

public TokenScanner(java.io.Reader in)
             throws java.io.IOException
Creates a TokenScanner for a given Reader.

Parameters:
in - the source Reader for character data
Throws:
java.io.IOException
Method Detail

isWordCharacter

public boolean isWordCharacter(int c)
Determines whether a given character is a valid word character.

Valid word characters are letters 'a' to 'z', 'A' to 'Z' and single quote '\''

Parameters:
c - the character to check
Returns:
true if the character is a word character

hasNext

public boolean hasNext()
Determines whether there is another token available.

Specified by:
hasNext in interface java.util.Iterator<Token>

next

public Token next()
Returns the next token, or throws a NoSuchElementException if none remain.

Specified by:
next in interface java.util.Iterator<Token>

remove

public void remove()
This functionality isn't supported by the TokenScanner. Just throw new UnsupportedOperationException();

Specified by:
remove in interface java.util.Iterator<Token>