package com.swabunga.spell.event; /** *

An interface for objects which take a text-based media as input, and iterate through * the words in the text stored in that media. Examples of such media could be Strings, * Documents, Files, TextComponents etc. *

* *

* When the object is instantiated, and before the first call to next() is made, * the following methods should throw a WordNotFoundException:
* getCurrentWordEnd(), getCurrentWordPosition(), * isNewSentence() and replaceWord(). *

* *

A call to next() when hasMoreWords() returns false * should throw a WordNotFoundException.

* @author Jason Height (jheight@chariot.net.au) */ public interface WordTokenizer { //~ Methods ................................................................. /** * Returns the context text that is being tokenized (should include any * changes that have been made). * @return the text being searched. */ public String getContext(); /** * Returns the number of word tokens that have been processed thus far * @return the number of words found so far. */ public int getCurrentWordCount(); /** * Returns an index representing the end location of the current word in the text. * @return index of the end of the current word in the text. * @throws WordNotFoundException current word has not yet been set. */ public int getCurrentWordEnd(); /** * Returns an index representing the start location of the current word in the text. * @return index of the start of the current word in the text. * @throws WordNotFoundException current word has not yet been set. */ public int getCurrentWordPosition(); /** * Returns true if the current word is at the start of a sentence * @return true if the current word starts a sentence. * @throws WordNotFoundException current word has not yet been set. */ public boolean isNewSentence(); /** * Returns true if there are more words left * @return true if more words can be found in the text. */ public boolean hasMoreWords(); /** * This returns the next word in the iteration. Note that any implementation should return * the current word, and then replace the current word with the next word found in the * input text (if one exists). * @return the next word in the iteration. * @throws WordNotFoundException search string contains no more words. */ public String nextWord(); /** * Replaces the current word token * *

* When a word is replaced care should be taken that the WordTokenizer * repositions itself such that the words that were added aren't rechecked. * Of course this is not mandatory, maybe there is a case when an * application doesnt need to do this. *

* @param newWord the string which should replace the current word. * @throws WordNotFoundException current word has not yet been set. */ public void replaceWord(String newWord); }