Package com.swabunga.spell.event
Class AbstractWordFinder
- java.lang.Object
-
- 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)
-
-
Field Summary
Fields Modifier and Type Field Description protected Word
currentWord
The word being analyzedprotected Word
nextWord
The word following the current oneprotected java.text.BreakIterator
sentenceIterator
An iterator to work through the sentenceprotected boolean
startsSentence
Indicate if the current word starts a new sentenceprotected java.lang.String
text
Holds the text to analyze
-
Constructor Summary
Constructors Constructor Description AbstractWordFinder()
Creates a new default AbstractWordFinder object.AbstractWordFinder(java.lang.String inText)
Creates a new AbstractWordFinder object.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Word
current()
Returns the current word in the iteration .java.lang.String
getText()
Return the text being searched.boolean
hasNext()
Indicates if there is some more word to analyzeprotected int
ignore(int index, char startIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
, and until the first non letter or digit character is encountered or end of text is detected.protected int
ignore(int index, char startIgnore, char endIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
, and until theendIgnore
character is encountered or end of text is detected.protected int
ignore(int index, java.lang.Character startIgnore, java.lang.Character endIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
, and until theendIgnore
character is encountered or end of text is detected.protected int
ignore(int index, java.lang.String startIgnore, java.lang.String endIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
string, and until theendIgnore
string is encountered or end of text is detected.protected void
init()
Initializes the sentenseIteratorprotected boolean
isWordChar(char c)
Indicates if the character at the specified character is acceptable as part of a word.protected boolean
isWordChar(int posn)
Indicates if the character at the specified position is acceptable as part of a word.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)
Adjusts the sentence iterator and the startSentence flag according to the currentWord.void
setText(java.lang.String newText)
Defines the text to search.boolean
startsSentence()
Indicates if the current word starts a new sentence.java.lang.String
toString()
Return the text being searched.
-
-
-
Field Detail
-
currentWord
protected Word currentWord
The word being analyzed
-
nextWord
protected Word nextWord
The word following the current one
-
startsSentence
protected boolean startsSentence
Indicate if the current word starts a new sentence
-
text
protected java.lang.String text
Holds the text to analyze
-
sentenceIterator
protected java.text.BreakIterator sentenceIterator
An iterator to work through the sentence
-
-
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 interfaceWordFinder
- Returns:
- the following 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 interfaceWordFinder
- Returns:
- the text being searched.
-
setText
public void setText(java.lang.String newText)
Defines the text to search.- Specified by:
setText
in interfaceWordFinder
- Parameters:
newText
- The text to be analyzed
-
current
public Word current()
Returns the current word in the iteration .- Specified by:
current
in interfaceWordFinder
- Returns:
- the current word.
- Throws:
WordNotFoundException
- current word has not yet been set.
-
hasNext
public boolean hasNext()
Indicates if there is some more word to analyze- Specified by:
hasNext
in interfaceWordFinder
- 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 interfaceWordFinder
- Parameters:
newWord
- the replacement string.- Throws:
WordNotFoundException
- current word has not yet been set.
-
startsSentence
public boolean startsSentence()
Description copied from interface:WordFinder
Indicates if the current word starts a new sentence.- Specified by:
startsSentence
in interfaceWordFinder
- 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 classjava.lang.Object
- Returns:
- the text being searched.
-
setSentenceIterator
protected void setSentenceIterator(Word wd)
Adjusts the sentence iterator and the startSentence flag according to the currentWord.- Parameters:
wd
- the wd parameter is not presently used.
-
isWordChar
protected boolean isWordChar(int posn)
Indicates if the character at the specified position is acceptable as part of a word. To be acceptable, the character need to be a letter or a digit. It is also acceptable if the character is one of ''', '@', '.' or '_' and is preceded and followed by letter or digit.- Parameters:
posn
- The character position to analyze.- Returns:
- true if the character is a letter or digit
-
isWordChar
protected boolean isWordChar(char c)
Indicates if the character at the specified character is acceptable as part of a word. To be acceptable, the character need to be a letter or a digit or a ' (an apostrophe).- Parameters:
c
- The character to evaluates if it can be part of a word- Returns:
- true if the character is a letter, digit or a ' (an apostrophe).
-
ignore
protected int ignore(int index, char startIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
, and until the first non letter or digit character is encountered or end of text is detected.- Parameters:
index
- The start position in text.startIgnore
- The character that should be atindex
position to start skipping through.- Returns:
- The index position pointing after the skipped characters or the original index if the ignore condition could not be met.
-
ignore
protected int ignore(int index, char startIgnore, char endIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
, and until theendIgnore
character is encountered or end of text is detected.- Parameters:
index
- The start position in text.startIgnore
- The character that should be atindex
position to start skipping through.endIgnore
- The character which mark the end of skipping through. If the value of endIgnore isnull
, skipping characters stop at first non letter or digit character.- Returns:
- The index position pointing after the skipped characters or the original index if the ignore condition could not be met.
-
ignore
protected int ignore(int index, java.lang.Character startIgnore, java.lang.Character endIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
, and until theendIgnore
character is encountered or end of text is detected.- Parameters:
index
- The start position in text.startIgnore
- The character that should be atindex
position to start skipping through.endIgnore
- The character which mark the end of skipping through. If the value of endIgnore isnull
, skipping characters stop at first non letter or digit character.- Returns:
- The index position pointing after the skipped characters or the original index if the ignore condition could not be met.
-
ignore
protected int ignore(int index, java.lang.String startIgnore, java.lang.String endIgnore)
Ignores or skip over text starting from the index position specified if it contains thestartIgnore
string, and until theendIgnore
string is encountered or end of text is detected.- Parameters:
index
- The start position in text.startIgnore
- The string that should be atindex
position to start skipping through.endIgnore
- The string which mark the end of skipping through.- Returns:
- The index position pointing after the skipped characters or the original index if the ignore condition could not be met.
-
init
protected void init()
Initializes the sentenseIterator
-
-