Interface WordFinder

All Known Implementing Classes:
AbstractWordFinder, DefaultWordFinder, JavaWordFinder, TeXWordFinder, XMLWordFinder

public interface WordFinder

An interface for objects which take a String as input, and iterates through the words in the string.

When the object is instantiated, and before the first call to next() is made, the following methods should throw a WordNotFoundException:
current(), startsSentence() and replace().

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

Author:
Jason Height (jheight@chariot.net.au)
  • Method Summary

    Modifier and Type
    Method
    Description
    This method should return the Word object representing the current word in the iteration.
    This method returns the text through which the WordFinder is iterating.
    boolean
    Tests the finder to see if any more words are available.
    This method should return the Word object representing the next word in the iteration (the first word if next() has not yet been called.)
    void
    replace(String newWord)
    This method should replace the current Word object with a Word object representing the String newWord.
    void
    setText(String newText)
    This method resets the text through which the WordFinder iterates.
    boolean
    Indicates if the current word starts a new sentence.
  • Method Details

    • getText

      String getText()
      This method returns the text through which the WordFinder is iterating. The text may have been modified through calls to replace().
      Returns:
      the (possibly modified) text being searched.
    • setText

      void setText(String newText)
      This method resets the text through which the WordFinder iterates. It must also re-initialize the WordFinder.
      Parameters:
      newText - the new text to search.
    • current

      Word current()
      This method should return the Word object representing the current word in the iteration. This method should not affect the state of the WordFinder object.
      Returns:
      the current Word object.
      Throws:
      WordNotFoundException - current word has not yet been set.
    • hasNext

      boolean hasNext()
      Tests the finder to see if any more words are available.
      Returns:
      true if more words are available.
    • next

      Word next()
      This method should return the Word object representing the next word in the iteration (the first word if next() has not yet been called.)
      Returns:
      the next Word in the iteration.
      Throws:
      WordNotFoundException - search string contains no more words.
    • replace

      void replace(String newWord)
      This method should replace the current Word object with a Word object representing the String newWord.
      Parameters:
      newWord - the word to replace the current word with.
      Throws:
      WordNotFoundException - current word has not yet been set.
    • startsSentence

      boolean startsSentence()
      Indicates if the current word starts a new sentence.
      Returns:
      true if the current word starts a new sentence.
      Throws:
      WordNotFoundException - current word has not yet been set.