com.swabunga.spell.engine
Class SpellDictionaryDisk

java.lang.Object
  extended by com.swabunga.spell.engine.SpellDictionaryASpell
      extended by com.swabunga.spell.engine.SpellDictionaryDisk
All Implemented Interfaces:
SpellDictionary

public class SpellDictionaryDisk
extends SpellDictionaryASpell

An implementation of SpellDictionary that doesn't cache any words in memory. Avoids the huge footprint of SpellDictionaryHashMap at the cost of relatively minor latency. A future version of this class that implements some caching strategies might be a good idea in the future, if there's any demand for it.

This class makes use of the "classic" Java IO library (java.io). However, it could probably benefit from the new IO APIs (java.nio) and it is anticipated that a future version of this class, probably called SpellDictionaryDiskNIO will appear at some point.

Since:
0.5
Version:
0.1
Author:
Ben Galbraith (ben@galbraiths.org)

Constructor Summary
SpellDictionaryDisk(java.io.File base, java.io.File phonetic, boolean block)
          NOTE: Do *not* create two instances of this class pointing to the same File unless you are sure that a new dictionary does not have to be created.
 
Method Summary
 void addWord(java.lang.String word)
          Add a word permanently to the dictionary.
 java.util.List getWords(java.lang.String code)
          Returns a list of words that have the same phonetic code.
 boolean isReady()
           
 
Methods inherited from class com.swabunga.spell.engine.SpellDictionaryASpell
getCode, getSuggestions, isCorrect
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpellDictionaryDisk

public SpellDictionaryDisk(java.io.File base,
                           java.io.File phonetic,
                           boolean block)
                    throws java.io.FileNotFoundException,
                           java.io.IOException
NOTE: Do *not* create two instances of this class pointing to the same File unless you are sure that a new dictionary does not have to be created. In the future, some sort of external locking mechanism may be created that handles this scenario gracefully.

Parameters:
base - the base directory in which SpellDictionaryDisk can expect to find its necessary files
block - if a new word db needs to be created, there can be a considerable delay before the constructor returns. If block is true, this method will block while the db is created and return when done. If block is false, this method will create a thread to create the new dictionary and return immediately.
Throws:
java.io.FileNotFoundException
java.io.IOException
Method Detail

addWord

public void addWord(java.lang.String word)
Description copied from interface: SpellDictionary
Add a word permanently to the dictionary.


getWords

public java.util.List getWords(java.lang.String code)
Description copied from class: SpellDictionaryASpell
Returns a list of words that have the same phonetic code.


isReady

public boolean isReady()