Move DictionaryOptions from FusionDictionary to FormatSpec.

Bug: 8187060
Bug:13035567

Change-Id: Id4f45e589521ae98c926a4c0607be10ce1a983f2
main
Keisuke Kuroyanagi 2014-03-05 17:42:36 +09:00
parent 516f86815d
commit 3ad4af2354
8 changed files with 48 additions and 47 deletions

View File

@ -25,7 +25,7 @@ import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.WordProperty;
import com.android.inputmethod.latin.personalization.PersonalizationHelper;

View File

@ -16,8 +16,8 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
/**
* Class representing dictionary header.

View File

@ -21,6 +21,8 @@ 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.HashMap;
/**
* Dictionary File Format Specification.
@ -322,6 +324,45 @@ public final class FormatSpec {
}
}
/**
* Options global to the dictionary.
*/
public static final class DictionaryOptions {
public final HashMap<String, String> mAttributes;
public DictionaryOptions(final HashMap<String, String> attributes) {
mAttributes = attributes;
}
@Override
public String toString() { // Convenience method
return toString(0, false);
}
public String toString(final int indentCount, final boolean plumbing) {
final StringBuilder indent = new StringBuilder();
if (plumbing) {
indent.append("H:");
} else {
for (int i = 0; i < indentCount; ++i) {
indent.append(" ");
}
}
final StringBuilder s = new StringBuilder();
for (final String optionKey : mAttributes.keySet()) {
s.append(indent);
s.append(optionKey);
s.append(" = ");
if ("date".equals(optionKey) && !plumbing) {
// Date needs a number of milliseconds, but the dictionary contains seconds
s.append(new Date(
1000 * Long.parseLong(mAttributes.get(optionKey))).toString());
} else {
s.append(mAttributes.get(optionKey));
}
s.append("\n");
}
return s.toString();
}
}
/**
* Returns new dictionary decoder.
*

View File

@ -18,12 +18,11 @@ package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@ -280,45 +279,6 @@ public final class FusionDictionary implements Iterable<WordProperty> {
}
}
/**
* Options global to the dictionary.
*/
public static final class DictionaryOptions {
public final HashMap<String, String> mAttributes;
public DictionaryOptions(final HashMap<String, String> attributes) {
mAttributes = attributes;
}
@Override
public String toString() { // Convenience method
return toString(0, false);
}
public String toString(final int indentCount, final boolean plumbing) {
final StringBuilder indent = new StringBuilder();
if (plumbing) {
indent.append("H:");
} else {
for (int i = 0; i < indentCount; ++i) {
indent.append(" ");
}
}
final StringBuilder s = new StringBuilder();
for (final String optionKey : mAttributes.keySet()) {
s.append(indent);
s.append(optionKey);
s.append(" = ");
if ("date".equals(optionKey) && !plumbing) {
// Date needs a number of milliseconds, but the dictionary contains seconds
s.append(new Date(
1000 * Long.parseLong(mAttributes.get(optionKey))).toString());
} else {
s.append(mAttributes.get(optionKey));
}
s.append("\n");
}
return s.toString();
}
}
public final DictionaryOptions mOptions;
public final PtNodeArray mRootNodeArray;

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.ProbabilityInfo;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
@ -32,7 +33,7 @@ import java.util.HashMap;
public class FusionDictionaryTests extends AndroidTestCase {
public void testFindWordInTree() {
FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
new FusionDictionary.DictionaryOptions(new HashMap<String,String>()));
new DictionaryOptions(new HashMap<String,String>()));
dict.add("abc", new ProbabilityInfo(10), null, false /* isNotAWord */);
assertNull(FusionDictionary.findWordInTree(dict.mRootNodeArray, "aaa"));

View File

@ -16,8 +16,8 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import java.io.File;
import java.util.HashMap;

View File

@ -17,8 +17,8 @@
package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.ProbabilityInfo;
import com.android.inputmethod.latin.makedict.WeightedString;

View File

@ -17,7 +17,6 @@
package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.ProbabilityInfo;
import com.android.inputmethod.latin.makedict.WeightedString;