|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.vt.middleware.dictionary.AbstractWordList
edu.vt.middleware.dictionary.FileWordList
public class FileWordList
Provides an implementation of a WordList that is backed by a file.
Each word is read from the file for every get, though the implementation
supports a simple memory cache to improve read performance.
| Field Summary | |
|---|---|
protected java.util.TreeMap<java.lang.Integer,java.lang.Long> |
cache
cache of indexes to file positions. |
static int |
DEFAULT_CACHE_SIZE
default cache size. |
protected java.io.RandomAccessFile |
file
file containing words. |
protected int |
size
size of the file. |
| Fields inherited from class edu.vt.middleware.dictionary.AbstractWordList |
|---|
comparator |
| Constructor Summary | |
|---|---|
FileWordList(java.io.RandomAccessFile raf)
Creates a new case-sensitive word list from the supplied file. |
|
FileWordList(java.io.RandomAccessFile raf,
boolean caseSensitive)
Creates a new word list from the supplied file. |
|
FileWordList(java.io.RandomAccessFile raf,
boolean caseSensitive,
int cachePercent)
Creates a new word list from the supplied file. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the underlying file and make the cache available for garbage collection. |
java.lang.String |
get(int index)
Gets the word at the given 0-based index. |
java.io.RandomAccessFile |
getFile()
Returns the file backing this list. |
int |
size()
Gets the number of words in the list. |
| Methods inherited from class edu.vt.middleware.dictionary.AbstractWordList |
|---|
checkIsString, checkRange, getComparator, iterator, medianIterator |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_CACHE_SIZE
protected java.io.RandomAccessFile file
protected int size
protected java.util.TreeMap<java.lang.Integer,java.lang.Long> cache
| Constructor Detail |
|---|
public FileWordList(java.io.RandomAccessFile raf)
throws java.io.IOException
NOTE Attempts to close the source file will cause
IOException when get(int) is called subsequently.
raf - File containing words, one per line.
java.io.IOException - if an error occurs reading the supplied file
public FileWordList(java.io.RandomAccessFile raf,
boolean caseSensitive)
throws java.io.IOException
NOTE Attempts to close the source file will cause
IOException when get(int) is called subsequently.
raf - File containing words, one per line.caseSensitive - Set to true to create case-sensitive word list,
false otherwise.
java.io.IOException - if an error occurs reading the supplied file
public FileWordList(java.io.RandomAccessFile raf,
boolean caseSensitive,
int cachePercent)
throws java.io.IOException
NOTE Attempts to close the source file will cause
IOException when get(int) is called subsequently.
raf - File containing words, one per line.caseSensitive - Set to true to create case-sensitive word list,
false otherwise.cachePercent - Percent (0-100) of file to cache in memory for
improved read performance.
java.lang.IllegalArgumentException - if cache percent is out of range.
java.io.IOException - if an error occurs reading the supplied file| Method Detail |
|---|
public java.lang.String get(int index)
index - 0-based index.
public int size()
public java.io.RandomAccessFile getFile()
RandomAccessFile that is backing this list
public void close()
throws java.io.IOException
java.io.IOException - if an error occurs closing the file
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||