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

Commit 6008898b authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Move code only used for dicttool and tests under tests."

parents 3c38e1f2 93cda5bb
Loading
Loading
Loading
Loading
+0 −38
Original line number Original line Diff line number Diff line
@@ -18,9 +18,7 @@ package com.android.inputmethod.latin.makedict;


import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.DictDecoder.DictionaryBufferFactory;


import java.io.File;
import java.util.Date;
import java.util.Date;
import java.util.HashMap;
import java.util.HashMap;


@@ -363,42 +361,6 @@ public final class FormatSpec {
        }
        }
    }
    }


    /**
     * Returns new dictionary decoder.
     *
     * @param dictFile the dictionary file.
     * @param offset the offset in the file.
     * @param length the length of the file, in bytes.
     * @param bufferType The type of buffer, as one of USE_* in DictDecoder.
     * @return new dictionary decoder if the dictionary file exists, otherwise null.
     */
    public static DictDecoder getDictDecoder(final File dictFile, final long offset,
            final long length, final int bufferType) {
        if (dictFile.isDirectory()) {
            return new Ver4DictDecoder(dictFile, bufferType);
        } else if (dictFile.isFile()) {
            return new Ver2DictDecoder(dictFile, offset, length, bufferType);
        }
        return null;
    }

    @UsedForTesting
    public static DictDecoder getDictDecoder(final File dictFile, final long offset,
            final long length, final DictionaryBufferFactory factory) {
        if (dictFile.isDirectory()) {
            return new Ver4DictDecoder(dictFile, factory);
        } else if (dictFile.isFile()) {
            return new Ver2DictDecoder(dictFile, offset, length, factory);
        }
        return null;
    }

    @UsedForTesting
    public static DictDecoder getDictDecoder(final File dictFile, final long offset,
            final long length) {
        return getDictDecoder(dictFile, offset, length, DictDecoder.USE_READONLY_BYTEBUFFER);
    }

    private FormatSpec() {
    private FormatSpec() {
        // This utility class is not publicly instantiable.
        // This utility class is not publicly instantiable.
    }
    }
+0 −47
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.latin.makedict;

import android.util.Log;

/**
 * Wrapper to redirect log events to the right output medium.
 */
public final class MakedictLog {
    public static final boolean DBG = false;
    private static final String TAG = MakedictLog.class.getSimpleName();

    public static void d(String message) {
        if (DBG) {
            Log.d(TAG, message);
        }
    }

    public static void i(String message) {
        if (DBG) {
            Log.i(TAG, message);
        }
    }

    public static void w(String message) {
        Log.w(TAG, message);
    }

    public static void e(String message) {
        Log.e(TAG, message);
    }
}
+0 −2
Original line number Original line Diff line number Diff line
@@ -23,12 +23,10 @@ import android.content.res.Resources;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;


import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.AssetFileAddress;
import com.android.inputmethod.latin.AssetFileAddress;
import com.android.inputmethod.latin.BinaryDictionaryGetter;
import com.android.inputmethod.latin.BinaryDictionaryGetter;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.makedict.BinaryDictIOUtils;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+3 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Pair;
import android.util.Pair;


import com.android.inputmethod.latin.makedict.BinaryDictIOUtils;
import com.android.inputmethod.latin.makedict.CodePointUtils;
import com.android.inputmethod.latin.makedict.CodePointUtils;
import com.android.inputmethod.latin.makedict.DictDecoder;
import com.android.inputmethod.latin.makedict.DictDecoder;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
@@ -151,7 +152,8 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
        binaryDictionary.flushWithGC();
        binaryDictionary.flushWithGC();
        binaryDictionary.close();
        binaryDictionary.close();


        final DictDecoder dictDecoder = FormatSpec.getDictDecoder(dictFile, 0, dictFile.length());
        final DictDecoder dictDecoder =
                BinaryDictIOUtils.getDictDecoder(dictFile, 0, dictFile.length());
        try {
        try {
            final FusionDictionary dict =
            final FusionDictionary dict =
                    dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */);
                    dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */);
Loading