com.swabunga.spell.event
Class AbstractWordFinder

java.lang.Object
  extended bycom.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 ([email protected])

Field Summary
protected  Word currentWord
           
protected  Word nextWord
           
protected  java.text.BreakIterator sentenceIterator
           
protected  boolean startsSentence
           
protected  java.lang.String text
           
 
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.
protected  int ignore(int index, char startIgnore)
           
protected  int ignore(int index, java.lang.Character startIgnore, java.lang.Character endIgnore)
           
protected  int ignore(int index, char startIgnore, char endIgnore)
           
protected  int ignore(int index, java.lang.String startIgnore, java.lang.String endIgnore)
           
protected  void init()
           
protected  boolean isWordChar(char c)
           
protected  boolean isWordChar(int posn)
           
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.
protected  void setSentenceIterator(Word wd)
           
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentWord

protected Word currentWord

nextWord

protected Word nextWord

startsSentence

protected boolean startsSentence

text

protected java.lang.String text

sentenceIterator

protected java.text.BreakIterator sentenceIterator
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.

Returns:
the text being searched.

setSentenceIterator

protected void setSentenceIterator(Word wd)

isWordChar

protected boolean isWordChar(int posn)

isWordChar

protected boolean isWordChar(char c)

ignore

protected int ignore(int index,
                     char startIgnore)

ignore

protected int ignore(int index,
                     char startIgnore,
                     char endIgnore)

ignore

protected int ignore(int index,
                     java.lang.Character startIgnore,
                     java.lang.Character endIgnore)

ignore

protected int ignore(int index,
                     java.lang.String startIgnore,
                     java.lang.String endIgnore)

init

protected void init()