public abstract class AbstractWordFinder extends Object implements WordFinder
Defines common methods and behaviour for various word finder subclasses.
You only have to override abstracts methods and call methodinit when your data is set. For example :
class StringWordFinder extends AbstractWordFinder
{
private String text ;
public StringWordFinder(String text)
{
this.text = text ;
init() ; // Remember call this method to setup variables.
}
}
| Constructor and Description |
|---|
AbstractWordFinder()
Create a AbstractWordFinder
|
| Modifier and Type | Method and Description |
|---|---|
Word |
current()
Returns the current word in the iteration.
|
boolean |
hasCurrent() |
boolean |
hasNext()
Tests the finder to see if any more words are available.
|
void |
init()
Call this function each time you want begin iterations.
|
void |
init(Word initWord)
Call this function to init from a word.
|
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.
|
protected abstract Word |
next(Word currentWord)
Find the next Word of the iteration.
|
void |
replace(String newWord)
Replace the current word in the search with a replacement string.
|
protected abstract void |
replace(String newWord,
Word currentWord)
Replace the current word with the new string newWord.
|
protected abstract Word next(Word currentWord)
currentWord - Current interation word. It can be null if the first iteration.public Word next()
next in interface WordFinderpublic Word current()
current in interface WordFinderWordNotFoundException - current word has not yet been set.public boolean hasCurrent()
public boolean hasNext()
WordFinderhasNext in interface WordFinderprotected abstract void replace(String newWord, Word currentWord)
newWord - The new string for the current word.currentWord - The current word.public void replace(String newWord)
replace in interface WordFindernewWord - the replacement string.WordNotFoundException - current word has not yet been set.public void init()
public void init(Word initWord)
Copyright © 2020. All rights reserved.