diff options
author | 2013-08-16 12:46:06 +0000 | |
---|---|---|
committer | 2013-08-16 12:46:07 +0000 | |
commit | 606a056b530c566f3397b8083f83288fe255bff8 (patch) | |
tree | ae6f5646f0d7101e310ebdeb5865b6eb3fecc463 /java/src | |
parent | e32475611ce52671802ca8d2f9694bbb82c4b120 (diff) | |
parent | 3a73b37b30d922ea742dc69d676d66c1e8101140 (diff) | |
download | latinime-606a056b530c566f3397b8083f83288fe255bff8.tar.gz latinime-606a056b530c566f3397b8083f83288fe255bff8.tar.xz latinime-606a056b530c566f3397b8083f83288fe255bff8.zip |
Merge "Make BinaryDictIOUtils and DynamicBinaryIOUtils use BinaryDictReader."
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java | 14 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java | 19 |
2 files changed, 18 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java index 476d51b8e..9aa39e06d 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java @@ -162,15 +162,16 @@ public final class BinaryDictIOUtils { * Gets the address of the last CharGroup of the exact matching word in the dictionary. * If no match is found, returns NOT_VALID_WORD. * - * @param buffer the buffer to read. + * @param reader the reader. * @param word the word we search for. * @return the address of the terminal node. * @throws IOException if the file can't be read. * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting - public static int getTerminalPosition(final FusionDictionaryBufferInterface buffer, + public static int getTerminalPosition(final BinaryDictReader reader, final String word) throws IOException, UnsupportedFormatException { + final FusionDictionaryBufferInterface buffer = reader.getBuffer(); if (word == null) return FormatSpec.NOT_VALID_WORD; if (buffer.position() != 0) buffer.position(0); @@ -507,18 +508,19 @@ public final class BinaryDictIOUtils { } /** - * Find a word from the buffer. + * Find a word using the BinaryDictReader. * - * @param buffer the buffer representing the body of the dictionary file. + * @param reader the reader * @param word the word searched * @return the found group * @throws IOException * @throws UnsupportedFormatException */ @UsedForTesting - public static CharGroupInfo findWordFromBuffer(final FusionDictionaryBufferInterface buffer, + public static CharGroupInfo findWordByBinaryDictReader(final BinaryDictReader reader, final String word) throws IOException, UnsupportedFormatException { - int position = getTerminalPosition(buffer, word); + int position = getTerminalPosition(reader, word); + final FusionDictionaryBufferInterface buffer = reader.getBuffer(); if (position != FormatSpec.NOT_VALID_WORD) { buffer.position(0); final FileHeader header = BinaryDictDecoder.readHeader(buffer); diff --git a/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java index 5d116d79c..11f9f8a79 100644 --- a/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java @@ -49,17 +49,18 @@ public final class DynamicBinaryDictIOUtils { /** * Delete the word from the binary file. * - * @param buffer the buffer to write. + * @param reader the reader. * @param word the word we delete * @throws IOException * @throws UnsupportedFormatException */ @UsedForTesting - public static void deleteWord(final FusionDictionaryBufferInterface buffer, - final String word) throws IOException, UnsupportedFormatException { + public static void deleteWord(final BinaryDictReader reader, final String word) + throws IOException, UnsupportedFormatException { + final FusionDictionaryBufferInterface buffer = reader.getBuffer(); buffer.position(0); final FileHeader header = BinaryDictDecoder.readHeader(buffer); - final int wordPosition = BinaryDictIOUtils.getTerminalPosition(buffer, word); + final int wordPosition = BinaryDictIOUtils.getTerminalPosition(reader, word); if (wordPosition == FormatSpec.NOT_VALID_WORD) return; buffer.position(wordPosition); @@ -235,7 +236,7 @@ public final class DynamicBinaryDictIOUtils { /** * Insert a word into a binary dictionary. * - * @param buffer the buffer containing the existing dictionary. + * @param reader the reader. * @param destination a stream to the underlying file, with the pointer at the end of the file. * @param word the word to insert. * @param frequency the frequency of the new word. @@ -248,16 +249,16 @@ public final class DynamicBinaryDictIOUtils { // TODO: Support batch insertion. // TODO: Remove @UsedForTesting once UserHistoryDictionary is implemented by BinaryDictionary. @UsedForTesting - public static void insertWord(final FusionDictionaryBufferInterface buffer, - final OutputStream destination, final String word, final int frequency, - final ArrayList<WeightedString> bigramStrings, + public static void insertWord(final BinaryDictReader reader, final OutputStream destination, + final String word, final int frequency, final ArrayList<WeightedString> bigramStrings, final ArrayList<WeightedString> shortcuts, final boolean isNotAWord, final boolean isBlackListEntry) throws IOException, UnsupportedFormatException { final ArrayList<PendingAttribute> bigrams = new ArrayList<PendingAttribute>(); + final FusionDictionaryBufferInterface buffer = reader.getBuffer(); if (bigramStrings != null) { for (final WeightedString bigram : bigramStrings) { - int position = BinaryDictIOUtils.getTerminalPosition(buffer, bigram.mWord); + int position = BinaryDictIOUtils.getTerminalPosition(reader, bigram.mWord); if (position == FormatSpec.NOT_VALID_WORD) { // TODO: figure out what is the correct thing to do here. } else { |