Package com.swabunga.spell.engine
Class Word
java.lang.Object
com.swabunga.spell.engine.Word
- All Implemented Interfaces:
Comparator
The Word object holds information for one suggested spelling.
It contains both the suggested word string and the distance cost, which represents how different the suggested
word is from the misspelling.
This class is now immutable.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Compares two words, mostly for the purpose of sorting words.boolean
Indicates if this word is equal to another one.int
getCost()
A cost measures how close a match this word was to the original wordgetWord()
gets suggested spellingvoid
sets suggested spellingtoString()
returns the suggested spellingMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
Word
Constructs a new Word.- Parameters:
word
- The text of a word.score
- The word's distance cost
-
Word
public Word()Constructs a new Word.
-
-
Method Details
-
compare
Compares two words, mostly for the purpose of sorting words.- Specified by:
compare
in interfaceComparator
- Parameters:
o1
- the first wordo2
- the second word- Returns:
- -1 if the first word is more similar to the misspelled word
1 if the second word is more similar to the misspelled word
0 if both words are equally similar
-
equals
Indicates if this word is equal to another one.- Specified by:
equals
in interfaceComparator
- Overrides:
equals
in classObject
- Parameters:
o
- The other word to compare- Returns:
- The indication of equality
-
getWord
gets suggested spelling- Returns:
- the actual text of the suggest spelling
-
setWord
sets suggested spelling- Parameters:
word
- The text to set for suggestd spelling
-
getCost
public int getCost()A cost measures how close a match this word was to the original word- Returns:
- 0 if an exact match. Higher numbers are worse matches.
- See Also:
-
toString
returns the suggested spelling
-