Package com.inet.jortho
Class Dictionary
- java.lang.Object
-
- com.inet.jortho.DictionaryBase
-
- com.inet.jortho.Dictionary
-
final class Dictionary extends DictionaryBase
A container for a word list.
-
-
Field Summary
-
Fields inherited from class com.inet.jortho.DictionaryBase
idx, LAST_CHAR, size, tree
-
-
Constructor Summary
Constructors Constructor Description Dictionary()
Create an empty Dictionary.Dictionary(char[] tree)
Create an Dictionary from a serialize Dictionary.
-
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.private void
checkSize(int newSize)
Check the size of the array and resize it if needed.private int
createNewNode()
Create a new node at end of the array.int
getDataSize()
Get the size of chars that this dictionary need in memory.private void
insertChar(char c)
void
load(java.io.InputStream stream)
Load the directory from a compressed stream.void
load(java.lang.String filename)
Load the directory from a compressed file.void
save(java.io.OutputStream stream)
Save this dictionary to the OutputStream.long
save(java.lang.String filename)
Save this dictionary to a compressed file.private void
searchCharOrAdd(char c)
char[]
toArray()
Convert the directory tree to char array.(package private) void
trimToSize()
Trims the capacity of this Dictionary instance to be the current size.-
Methods inherited from class com.inet.jortho.DictionaryBase
exist, readIndex, searchSuggestions
-
-
-
-
Constructor Detail
-
Dictionary
public Dictionary()
Create an empty Dictionary.
-
Dictionary
public Dictionary(char[] tree)
Create an Dictionary from a serialize Dictionary. This is used from the DictionaryFactory.- See Also:
toArray()
,DictionaryFactory
-
-
Method Detail
-
save
public long save(java.lang.String filename) throws java.io.IOException
Save this dictionary to a compressed file.- Parameters:
filename
- the name of the file.- Returns:
- the size in bytes that was needed.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
save
public void save(java.io.OutputStream stream) throws java.io.IOException
Save this dictionary to the OutputStream. The data will be compressed. After finish the OutputStream is closed.- Parameters:
stream
- the OutputStream- Throws:
java.io.IOException
- if an I/O error occurs.
-
load
public void load(java.lang.String filename) throws java.io.IOException
Load the directory from a compressed file.- Parameters:
filename
- the name of the file.- Throws:
java.io.IOException
- if an I/O error occurs.
-
load
public void load(java.io.InputStream stream) throws java.io.IOException
Load the directory from a compressed stream.- Parameters:
stream
- the InputStream- Throws:
java.io.IOException
- if an I/O error occurs.
-
trimToSize
void trimToSize()
Trims the capacity of this Dictionary instance to be the current size. An application can use this operation to minimize the storage of an Dictionary instance. The load methods already call it.
-
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.
-
toArray
public char[] toArray()
Convert the directory tree to char array.- Returns:
- a char array that include the data of the dictionary.
-
getDataSize
public int getDataSize()
Get the size of chars that this dictionary need in memory.
-
searchCharOrAdd
private void searchCharOrAdd(char c)
-
insertChar
private void insertChar(char c)
-
createNewNode
private final int createNewNode()
Create a new node at end of the array. On the current idx position is writing the pointer. The pointer on the current idx position must be 0 without some word end flags (0x8000 on idx+1)- Returns:
- Pointer on new node.
-
checkSize
private final void checkSize(int newSize)
Check the size of the array and resize it if needed.- Parameters:
newSize
- the requied size
-
-