Package com.inet.jortho
Class DictionaryFactory
- java.lang.Object
-
- com.inet.jortho.DictionaryFactory
-
class DictionaryFactory extends java.lang.Object
With the DictionaryFactory you can create / load a Dictionary. A Dictionary is list of word with a API for searching. The list is saved internal as a tree.- See Also:
Dictionary
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DictionaryFactory.Node
A node in the search tree.
-
Field Summary
Fields Modifier and Type Field Description private DictionaryFactory.Node
root
private int
size
private char[]
tree
-
Constructor Summary
Constructors Constructor Description DictionaryFactory()
Empty Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String word)
Add a word to the tree.(package private) void
checkSize(int newSize)
Check the size of the array and resize it if needed.Dictionary
create()
Create from the data in this factory a Dictionary object.void
loadWordList(java.net.URL filename)
Load the directory from a compressed list of words with UTF8 encoding.void
loadWords(java.util.Iterator<java.lang.String> words)
-
-
-
Field Detail
-
root
private final DictionaryFactory.Node root
-
tree
private char[] tree
-
size
private int size
-
-
Method Detail
-
loadWordList
public void loadWordList(java.net.URL filename) throws java.io.IOException
Load the directory from a compressed list of words with UTF8 encoding. The words must be delimited with newlines. This method can be called multiple times.- Parameters:
filename
- the name of the file- Throws:
java.io.IOException
- If an I/O error occurs.java.lang.NullPointerException
- If filename is null.
-
loadWords
public void loadWords(java.util.Iterator<java.lang.String> words)
-
add
public void add(java.lang.String word)
Add a word to the tree. If it already exist then it has no effect.- Parameters:
word
- the new word.
-
create
public Dictionary create()
Create from the data in this factory a Dictionary object. If there are no word added then the Dictionary is empty. The Dictionary need fewer memory as the DictionaryFactory.- Returns:
- a Dictionary object.
-
checkSize
final void checkSize(int newSize)
Check the size of the array and resize it if needed.- Parameters:
newSize
- the required size
-
-