Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 112257e4 authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Rename BinaryDictDecoder to Ver3DictDecoder.

Change-Id: Ibf9b95b658df6e2c2218bdb62e2380f326a03832
parent 66004ce2
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -21,21 +21,16 @@ import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor;
import android.util.Log;

import com.android.inputmethod.latin.makedict.BinaryDictDecoder;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.Ver3DictDecoder;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.DictionaryInfoUtils;
import com.android.inputmethod.latin.utils.LocaleUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
@@ -233,9 +228,9 @@ final public class BinaryDictionaryGetter {
    private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) {
        try {
            // Read the version of the file
            final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(f);
            final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(f);
            dictDecoder.openDictBuffer(
                    new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
                    new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
            final FileHeader header = dictDecoder.readHeader();

            final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY);
+3 −3
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import java.util.TreeMap;
 *
 * All the methods in this class are static.
 *
 * TODO: Remove calls from classes except BinaryDictDecoder
 * TODO: Remove calls from classes except Ver3DictDecoder
 * TODO: Move this file to makedict/internal.
 */
public final class BinaryDictDecoderUtils {
@@ -649,13 +649,13 @@ public final class BinaryDictDecoderUtils {
     * @return the created (or merged) dictionary.
     */
    @UsedForTesting
    public static FusionDictionary readDictionaryBinary(final BinaryDictDecoder dictDecoder,
    public static FusionDictionary readDictionaryBinary(final Ver3DictDecoder dictDecoder,
            final FusionDictionary dict) throws FileNotFoundException, IOException,
            UnsupportedFormatException {

        // if the buffer has not been opened, open the buffer with bytebuffer.
        if (dictDecoder.getDictBuffer() == null) dictDecoder.openDictBuffer(
                new BinaryDictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
                new Ver3DictDecoder.DictionaryBufferFromReadOnlyByteBufferFactory());
        if (dictDecoder.getDictBuffer() == null) {
            MakedictLog.e("Cannot open the buffer");
        }
+6 −6
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ public final class BinaryDictIOUtils {
     * @throws IOException if the file can't be read.
     * @throws UnsupportedFormatException if the format of the file is not recognized.
     */
    public static void readUnigramsAndBigramsBinary(final BinaryDictDecoder dictDecoder,
    public static void readUnigramsAndBigramsBinary(final Ver3DictDecoder dictDecoder,
            final Map<Integer, String> words, final Map<Integer, Integer> frequencies,
            final Map<Integer, ArrayList<PendingAttribute>> bigrams) throws IOException,
            UnsupportedFormatException {
@@ -169,7 +169,7 @@ public final class BinaryDictIOUtils {
     * @throws UnsupportedFormatException if the format of the file is not recognized.
     */
    @UsedForTesting
    public static int getTerminalPosition(final BinaryDictDecoder dictDecoder,
    public static int getTerminalPosition(final Ver3DictDecoder dictDecoder,
            final String word) throws IOException, UnsupportedFormatException {
        final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
        if (word == null) return FormatSpec.NOT_VALID_WORD;
@@ -508,7 +508,7 @@ public final class BinaryDictIOUtils {
    }

    /**
     * Find a word using the BinaryDictDecoder.
     * Find a word using the Ver3DictDecoder.
     *
     * @param dictDecoder the dict reader
     * @param word the word searched
@@ -517,7 +517,7 @@ public final class BinaryDictIOUtils {
     * @throws UnsupportedFormatException
     */
    @UsedForTesting
    public static CharGroupInfo findWordByBinaryDictReader(final BinaryDictDecoder dictDecoder,
    public static CharGroupInfo findWordByBinaryDictReader(final Ver3DictDecoder dictDecoder,
            final String word) throws IOException, UnsupportedFormatException {
        int position = getTerminalPosition(dictDecoder, word);
        final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
@@ -545,8 +545,8 @@ public final class BinaryDictIOUtils {
            final File file, final long offset, final long length)
            throws FileNotFoundException, IOException, UnsupportedFormatException {
        final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE];
        final BinaryDictDecoder dictDecoder = new BinaryDictDecoder(file);
        dictDecoder.openDictBuffer(new BinaryDictDecoder.DictionaryBufferFactory() {
        final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file);
        dictDecoder.openDictBuffer(new Ver3DictDecoder.DictionaryBufferFactory() {
            @Override
            public DictBuffer getDictionaryBuffer(File file)
                    throws FileNotFoundException, IOException {
+2 −2
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public final class DynamicBinaryDictIOUtils {
     * @throws UnsupportedFormatException
     */
    @UsedForTesting
    public static void deleteWord(final BinaryDictDecoder dictDecoder, final String word)
    public static void deleteWord(final Ver3DictDecoder dictDecoder, final String word)
            throws IOException, UnsupportedFormatException {
        final DictBuffer dictBuffer = dictDecoder.getDictBuffer();
        dictBuffer.position(0);
@@ -253,7 +253,7 @@ public final class DynamicBinaryDictIOUtils {
    // TODO: Support batch insertion.
    // TODO: Remove @UsedForTesting once UserHistoryDictionary is implemented by BinaryDictionary.
    @UsedForTesting
    public static void insertWord(final BinaryDictDecoder dictDecoder,
    public static void insertWord(final Ver3DictDecoder dictDecoder,
            final OutputStream destination, final String word, final int frequency,
            final ArrayList<WeightedString> bigramStrings,
            final ArrayList<WeightedString> shortcuts, final boolean isNotAWord,
+3 −3
Original line number Diff line number Diff line
@@ -33,9 +33,9 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.HashMap;

// TODO: Rename this class to "Ver3DictDecoder" or something, and make an interface "DictDecoder".
// TODO: Make an interface "DictDecoder".
@UsedForTesting
public class BinaryDictDecoder {
public class Ver3DictDecoder {

    static {
        JniUtils.loadNativeLibrary();
@@ -166,7 +166,7 @@ public class BinaryDictDecoder {
    private final File mDictionaryBinaryFile;
    private DictBuffer mDictBuffer;

    public BinaryDictDecoder(final File file) {
    public Ver3DictDecoder(final File file) {
        mDictionaryBinaryFile = file;
        mDictBuffer = null;
    }
Loading