com.swabunga.spell.event
Class AbstractWordFinder

java.lang.Object
  extended by com.swabunga.spell.event.AbstractWordFinder
All Implemented Interfaces:
WordFinder
Direct Known Subclasses:
DefaultWordFinder, JavaWordFinder, TeXWordFinder, XMLWordFinder

public abstract class AbstractWordFinder
extends java.lang.Object
implements WordFinder

Defines common methods and behaviour for the various word finding subclasses.

Author:
Anthony Roy (ajr@antroy.co.uk)

Constructor Summary
AbstractWordFinder()
           
AbstractWordFinder(java.lang.String inText)
          Creates a new AbstractWordFinder object.
 
Method Summary
 Word current()
          Returns the current word in the iteration .
 java.lang.String getText()
          Return the text being searched.
 boolean hasNext()
          Tests the finder to see if any more words are available.
abstract  Word next()
          This method scans the text from the end of the last word, and returns a new Word object corresponding to the next word.
 void replace(java.lang.String newWord)
          Replace the current word in the search with a replacement string.
 void setText(java.lang.String newText)
          This method resets the text through which the WordFinder iterates.
 boolean startsSentence()
           
 java.lang.String toString()
          Return the text being searched.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractWordFinder

public AbstractWordFinder(java.lang.String inText)
Creates a new AbstractWordFinder object.

Parameters:
inText - the String to iterate through.

AbstractWordFinder

public AbstractWordFinder()
Method Detail

next

public abstract Word next()
This method scans the text from the end of the last word, and returns a new Word object corresponding to the next word.

Specified by:
next in interface WordFinder
Returns:
the next word.

getText

public java.lang.String getText()
Return the text being searched. May have changed since first set through calls to replace.

Specified by:
getText in interface WordFinder
Returns:
the text being searched.

setText

public void setText(java.lang.String newText)
Description copied from interface: WordFinder
This method resets the text through which the WordFinder iterates. It must also re-initialize the WordFinder.

Specified by:
setText in interface WordFinder
Parameters:
newText - the new text to search.

current

public Word current()
Returns the current word in the iteration .

Specified by:
current in interface WordFinder
Returns:
the current word.
Throws:
WordNotFoundException - current word has not yet been set.

hasNext

public boolean hasNext()
Description copied from interface: WordFinder
Tests the finder to see if any more words are available.

Specified by:
hasNext in interface WordFinder
Returns:
true if there are further words in the string.

replace

public void replace(java.lang.String newWord)
Replace the current word in the search with a replacement string.

Specified by:
replace in interface WordFinder
Parameters:
newWord - the replacement string.
Throws:
WordNotFoundException - current word has not yet been set.

startsSentence

public boolean startsSentence()
Specified by:
startsSentence in interface WordFinder
Returns:
true if the current word starts a new sentence.
Throws:
WordNotFoundException - current word has not yet been set.

toString

public java.lang.String toString()
Return the text being searched. May have changed since first set through calls to replace.

Overrides:
toString in class java.lang.Object
Returns:
the text being searched.