Rename BinaryDictEncoder to BinaryDictEncoderUtils.

Change-Id: I4dabf17da7003b1d8204a83dbd10e5be6e8fd805
main
Yuichiro Hanada 2013-08-20 21:15:52 +09:00
parent 107a5f6fb8
commit a306e08753
10 changed files with 34 additions and 33 deletions

View File

@ -20,7 +20,7 @@ import android.content.Context;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.makedict.BinaryDictEncoder;
import com.android.inputmethod.latin.makedict.BinaryDictEncoderUtils;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
@ -87,7 +87,7 @@ public class DictionaryWriter extends AbstractDictionaryWriter {
@Override
protected void writeBinaryDictionary(final FileOutputStream out)
throws IOException, UnsupportedFormatException {
BinaryDictEncoder.writeDictionaryBinary(out, mFusionDictionary, FORMAT_OPTIONS);
BinaryDictEncoderUtils.writeDictionaryBinary(out, mFusionDictionary, FORMAT_OPTIONS);
}
@Override

View File

@ -34,11 +34,11 @@ import java.util.Iterator;
*
* All the methods in this class are static.
*/
public class BinaryDictEncoder {
public class BinaryDictEncoderUtils {
private static final boolean DBG = MakedictLog.DBG;
private BinaryDictEncoder() {
private BinaryDictEncoderUtils() {
// This utility class is not publicly instantiable.
}

View File

@ -272,7 +272,7 @@ public final class BinaryDictIOUtils {
*/
private static int writeVariableAddress(final OutputStream destination, final int value)
throws IOException {
switch (BinaryDictEncoder.getByteSize(value)) {
switch (BinaryDictEncoderUtils.getByteSize(value)) {
case 1:
destination.write((byte)value);
break;
@ -286,7 +286,7 @@ public final class BinaryDictIOUtils {
destination.write((byte)(0xFF & value));
break;
}
return BinaryDictEncoder.getByteSize(value);
return BinaryDictEncoderUtils.getByteSize(value);
}
static void skipCharGroup(final DictBuffer dictBuffer,
@ -413,14 +413,14 @@ public final class BinaryDictIOUtils {
if (info.mShortcutTargets != null && info.mShortcutTargets.size() > 0) {
final int shortcutListSize =
BinaryDictEncoder.getShortcutListSize(info.mShortcutTargets);
BinaryDictEncoderUtils.getShortcutListSize(info.mShortcutTargets);
destination.write((byte)(shortcutListSize >> 8));
destination.write((byte)(shortcutListSize & 0xFF));
size += 2;
final Iterator<WeightedString> shortcutIterator = info.mShortcutTargets.iterator();
while (shortcutIterator.hasNext()) {
final WeightedString target = shortcutIterator.next();
destination.write((byte)BinaryDictEncoder.makeShortcutFlags(
destination.write((byte)BinaryDictEncoderUtils.makeShortcutFlags(
shortcutIterator.hasNext(), target.mFrequency));
size++;
size += writeString(destination, target.mWord);
@ -429,7 +429,7 @@ public final class BinaryDictIOUtils {
if (info.mBigrams != null) {
// TODO: Consolidate this code with the code that computes the size of the bigram list
// in BinaryDictEncoder#computeActualNodeArraySize
// in BinaryDictEncoderUtils#computeActualNodeArraySize
for (int i = 0; i < info.mBigrams.size(); ++i) {
final int bigramFrequency = info.mBigrams.get(i).mFrequency;
@ -439,7 +439,7 @@ public final class BinaryDictIOUtils {
final int bigramOffset = info.mBigrams.get(i).mAddress - (info.mOriginalAddress
+ size);
bigramFlags |= (bigramOffset < 0) ? FormatSpec.FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0;
switch (BinaryDictEncoder.getByteSize(bigramOffset)) {
switch (BinaryDictEncoderUtils.getByteSize(bigramOffset)) {
case 1:
bigramFlags |= FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE;
break;
@ -463,18 +463,18 @@ public final class BinaryDictIOUtils {
*/
static int computeGroupSize(final CharGroupInfo info, final FormatOptions formatOptions) {
int size = FormatSpec.GROUP_FLAGS_SIZE + FormatSpec.PARENT_ADDRESS_SIZE
+ BinaryDictEncoder.getGroupCharactersSize(info.mCharacters)
+ BinaryDictEncoderUtils.getGroupCharactersSize(info.mCharacters)
+ getChildrenAddressSize(info.mFlags, formatOptions);
if ((info.mFlags & FormatSpec.FLAG_IS_TERMINAL) != 0) {
size += FormatSpec.GROUP_FREQUENCY_SIZE;
}
if (info.mShortcutTargets != null && !info.mShortcutTargets.isEmpty()) {
size += BinaryDictEncoder.getShortcutListSize(info.mShortcutTargets);
size += BinaryDictEncoderUtils.getShortcutListSize(info.mShortcutTargets);
}
if (info.mBigrams != null) {
for (final PendingAttribute attr : info.mBigrams) {
size += FormatSpec.GROUP_FLAGS_SIZE;
size += BinaryDictEncoder.getByteSize(attr.mAddress);
size += BinaryDictEncoderUtils.getByteSize(attr.mAddress);
}
}
return size;

View File

@ -314,7 +314,7 @@ public final class DynamicBinaryDictIOUtils {
* abc - d - ef
*/
final int newNodeAddress = dictBuffer.limit();
final int flags = BinaryDictEncoder.makeCharGroupFlags(p > 1,
final int flags = BinaryDictEncoderUtils.makeCharGroupFlags(p > 1,
isTerminal, 0, hasShortcuts, hasBigrams, false /* isNotAWord */,
false /* isBlackListEntry */, fileHeader.mFormatOptions);
int written = moveGroup(newNodeAddress, currentInfo.mCharacters, p, flags,
@ -353,7 +353,7 @@ public final class DynamicBinaryDictIOUtils {
final int childrenAddress = currentInfo.mChildrenAddress;
// move prefix
final int prefixFlags = BinaryDictEncoder.makeCharGroupFlags(p > 1,
final int prefixFlags = BinaryDictEncoderUtils.makeCharGroupFlags(p > 1,
false /* isTerminal */, 0 /* childrenAddressSize*/,
false /* hasShortcut */, false /* hasBigrams */,
false /* isNotAWord */, false /* isBlackListEntry */,
@ -369,7 +369,7 @@ public final class DynamicBinaryDictIOUtils {
updateParentAddresses(dictBuffer, currentInfo.mChildrenAddress,
newNodeAddress + written + 1, fileHeader.mFormatOptions);
}
final int suffixFlags = BinaryDictEncoder.makeCharGroupFlags(
final int suffixFlags = BinaryDictEncoderUtils.makeCharGroupFlags(
suffixCharacters.length > 1,
(currentInfo.mFlags & FormatSpec.FLAG_IS_TERMINAL) != 0,
0 /* childrenAddressSize */,
@ -387,7 +387,7 @@ public final class DynamicBinaryDictIOUtils {
final int[] newCharacters = Arrays.copyOfRange(codePoints, wordPos + p,
codePoints.length);
final int flags = BinaryDictEncoder.makeCharGroupFlags(
final int flags = BinaryDictEncoderUtils.makeCharGroupFlags(
newCharacters.length > 1, isTerminal,
0 /* childrenAddressSize */, hasShortcuts, hasBigrams,
isNotAWord, isBlackListEntry, fileHeader.mFormatOptions);
@ -410,7 +410,7 @@ public final class DynamicBinaryDictIOUtils {
// only update group.
final int newNodeAddress = dictBuffer.limit();
final boolean hasMultipleChars = currentInfo.mCharacters.length > 1;
final int flags = BinaryDictEncoder.makeCharGroupFlags(hasMultipleChars,
final int flags = BinaryDictEncoderUtils.makeCharGroupFlags(hasMultipleChars,
isTerminal, 0 /* childrenAddressSize */, hasShortcuts, hasBigrams,
isNotAWord, isBlackListEntry, fileHeader.mFormatOptions);
final CharGroupInfo newInfo = new CharGroupInfo(newNodeAddress + 1,
@ -440,7 +440,7 @@ public final class DynamicBinaryDictIOUtils {
fileHeader.mFormatOptions);
final int newGroupAddress = newNodeAddress + 1;
final boolean hasMultipleChars = (wordLen - wordPos) > 1;
final int flags = BinaryDictEncoder.makeCharGroupFlags(hasMultipleChars,
final int flags = BinaryDictEncoderUtils.makeCharGroupFlags(hasMultipleChars,
isTerminal, 0 /* childrenAddressSize */, hasShortcuts, hasBigrams,
isNotAWord, isBlackListEntry, fileHeader.mFormatOptions);
final int[] characters = Arrays.copyOfRange(codePoints, wordPos, wordLen);
@ -485,7 +485,7 @@ public final class DynamicBinaryDictIOUtils {
BinaryDictIOUtils.writeSInt24ToBuffer(dictBuffer, newNodeAddress);
final int[] characters = Arrays.copyOfRange(codePoints, wordPos, wordLen);
final int flags = BinaryDictEncoder.makeCharGroupFlags(characters.length > 1,
final int flags = BinaryDictEncoderUtils.makeCharGroupFlags(characters.length > 1,
isTerminal, 0 /* childrenAddressSize */, hasShortcuts, hasBigrams,
isNotAWord, isBlackListEntry, fileHeader.mFormatOptions);
final CharGroupInfo newInfo = new CharGroupInfo(newNodeAddress + 1,

View File

@ -19,7 +19,7 @@ package com.android.inputmethod.latin.utils;
import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.makedict.BinaryDictEncoder;
import com.android.inputmethod.latin.makedict.BinaryDictEncoderUtils;
import com.android.inputmethod.latin.makedict.BinaryDictIOUtils;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary;
@ -62,7 +62,7 @@ public final class UserHistoryDictIOUtils {
final FormatOptions formatOptions) {
final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams);
try {
BinaryDictEncoder.writeDictionaryBinary(destination, fusionDict, formatOptions);
BinaryDictEncoderUtils.writeDictionaryBinary(destination, fusionDict, formatOptions);
Log.d(TAG, "end writing");
} catch (IOException e) {
Log.e(TAG, "IO exception while writing file", e);

View File

@ -44,7 +44,7 @@ import java.util.Random;
import java.util.Set;
/**
* Unit tests for BinaryDictDecoderUtils and BinaryDictEncoder.
* Unit tests for BinaryDictDecoderUtils and BinaryDictEncoderUtils.
*/
@LargeTest
public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
@ -210,7 +210,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
// If you need to dump the dict to a textual file, uncomment the line below and the
// function above
// dumpToCombinedFileForDebug(file, "/tmp/foo");
BinaryDictEncoder.writeDictionaryBinary(out, dict, formatOptions);
BinaryDictEncoderUtils.writeDictionaryBinary(out, dict, formatOptions);
diff = System.currentTimeMillis() - now;
out.flush();

View File

@ -253,7 +253,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
try {
final FileOutputStream out = new FileOutputStream(file);
BinaryDictEncoder.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
BinaryDictEncoderUtils.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
out.close();
} catch (IOException e) {
fail("IOException while writing an initial dictionary : " + e);
@ -305,7 +305,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
try {
final FileOutputStream out = new FileOutputStream(file);
BinaryDictEncoder.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
BinaryDictEncoderUtils.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
out.close();
} catch (IOException e) {
fail("IOException while writing an initial dictionary : " + e);
@ -343,7 +343,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
try {
final FileOutputStream out = new FileOutputStream(file);
BinaryDictEncoder.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
BinaryDictEncoderUtils.writeDictionaryBinary(out, dict, FORMAT_OPTIONS);
out.close();
} catch (IOException e) {
assertTrue(false);

View File

@ -17,7 +17,7 @@
package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils;
import com.android.inputmethod.latin.makedict.BinaryDictEncoder;
import com.android.inputmethod.latin.makedict.BinaryDictEncoderUtils;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.MakedictLog;
@ -358,7 +358,7 @@ public class DictionaryMaker {
throws FileNotFoundException, IOException, UnsupportedFormatException {
final File outputFile = new File(outputFilename);
final FormatSpec.FormatOptions formatOptions = new FormatSpec.FormatOptions(version);
BinaryDictEncoder.writeDictionaryBinary(new FileOutputStream(outputFilename), dict,
BinaryDictEncoderUtils.writeDictionaryBinary(new FileOutputStream(outputFilename), dict,
formatOptions);
}

View File

@ -17,7 +17,7 @@
package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils;
import com.android.inputmethod.latin.makedict.BinaryDictEncoder;
import com.android.inputmethod.latin.makedict.BinaryDictEncoderUtils;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
@ -58,7 +58,7 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase {
Compress.getCompressedStream(
new BufferedOutputStream(new FileOutputStream(dst)))));
BinaryDictEncoder.writeDictionaryBinary(out, dict, new FormatOptions(2, false));
BinaryDictEncoderUtils.writeDictionaryBinary(out, dict, new FormatOptions(2, false));
// Test for an actually compressed dictionary and its contents
final BinaryDictOffdeviceUtils.DecoderChainSpec decodeSpec =

View File

@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
/**
* Unit tests for BinaryDictEncoder.flattenTree().
* Unit tests for BinaryDictEncoderUtils.flattenTree().
*/
public class BinaryDictEncoderFlattenTreeTests extends TestCase {
// Test the flattened array contains the expected number of nodes, and
@ -39,7 +39,8 @@ public class BinaryDictEncoderFlattenTreeTests extends TestCase {
dict.add("ftb", 1, null, false /* isNotAWord */);
dict.add("bar", 1, null, false /* isNotAWord */);
dict.add("fool", 1, null, false /* isNotAWord */);
final ArrayList<PtNodeArray> result = BinaryDictEncoder.flattenTree(dict.mRootNodeArray);
final ArrayList<PtNodeArray> result =
BinaryDictEncoderUtils.flattenTree(dict.mRootNodeArray);
assertEquals(4, result.size());
while (!result.isEmpty()) {
final PtNodeArray n = result.remove(0);