Add sanity check to KeybaordTextsTable for debugging

Bug: 13007104
Change-Id: Id12f75da7a1c6a2a078d41721ee4016794e9dd2a
main
Tadashi G. Takaoka 2014-02-14 18:44:34 +09:00
parent 3c4f05dd66
commit 53a237323a
3 changed files with 46 additions and 16 deletions

View File

@ -85,13 +85,13 @@ public final class KeyboardTextsSet {
do {
level++;
if (level >= MAX_STRING_REFERENCE_INDIRECTION) {
throw new RuntimeException("too many @string/resource indirection: " + text);
throw new RuntimeException("Too many " + PREFIX_TEXT + "name indirection: " + text);
}
final int prefixLen = PREFIX_TEXT.length();
final int size = text.length();
if (size < prefixLen) {
return TextUtils.isEmpty(text) ? null : text;
break;
}
sb = null;

View File

@ -43,22 +43,36 @@ import java.util.HashMap;
public final class KeyboardTextsTable {
// Name to index map.
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
// Language to texts map.
private static final HashMap<String, String[]> sLanguageToTextsMap =
// Language to texts table map.
private static final HashMap<String, String[]> sLanguageToTextsTableMap =
CollectionUtils.newHashMap();
// TODO: Remove this variable after debugging.
// Texts table to language maps.
private static final HashMap<String[], String> sTextsTableToLanguageMap =
CollectionUtils.newHashMap();
public static String getText(final String name, final String[] textsTable) {
final Integer indexObj = sNameToIndexesMap.get(name);
if (indexObj == null) {
throw new RuntimeException("Unknown text name: " + name);
throw new RuntimeException("Unknown text name=" + name + " language="
+ sTextsTableToLanguageMap.get(textsTable));
}
final int index = indexObj;
final String text = (index < textsTable.length) ? textsTable[index] : null;
return (text != null) ? text : LANGUAGE_DEFAULT[index];
if (text != null) {
return text;
}
// Sanity check.
if (index >= 0 && index < LANGUAGE_DEFAULT.length) {
return LANGUAGE_DEFAULT[index];
}
// Throw exception for debugging purpose.
throw new RuntimeException("Illegal index=" + index + " for name=" + name
+ " language=" + sTextsTableToLanguageMap.get(textsTable));
}
public static String[] getTextsTable(final String language) {
final String[] textsTable = sLanguageToTextsMap.get(language);
final String[] textsTable = sLanguageToTextsTableMap.get(language);
return textsTable != null ? textsTable : LANGUAGE_DEFAULT;
}
@ -3632,8 +3646,9 @@ public final class KeyboardTextsTable {
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
final String language = (String)LANGUAGES_AND_TEXTS[i];
final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
sLanguageToTextsMap.put(language, texts);
final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1];
sLanguageToTextsTableMap.put(language, textsTable);
sTextsTableToLanguageMap.put(textsTable, language);
}
}
}

View File

@ -43,22 +43,36 @@ import java.util.HashMap;
public final class KeyboardTextsTable {
// Name to index map.
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
// Language to texts map.
private static final HashMap<String, String[]> sLanguageToTextsMap =
// Language to texts table map.
private static final HashMap<String, String[]> sLanguageToTextsTableMap =
CollectionUtils.newHashMap();
// TODO: Remove this variable after debugging.
// Texts table to language maps.
private static final HashMap<String[], String> sTextsTableToLanguageMap =
CollectionUtils.newHashMap();
public static String getText(final String name, final String[] textsTable) {
final Integer indexObj = sNameToIndexesMap.get(name);
if (indexObj == null) {
throw new RuntimeException("Unknown text name: " + name);
throw new RuntimeException("Unknown text name=" + name + " language="
+ sTextsTableToLanguageMap.get(textsTable));
}
final int index = indexObj;
final String text = (index < textsTable.length) ? textsTable[index] : null;
return (text != null) ? text : LANGUAGE_DEFAULT[index];
if (text != null) {
return text;
}
// Sanity check.
if (index >= 0 && index < LANGUAGE_DEFAULT.length) {
return LANGUAGE_DEFAULT[index];
}
// Throw exception for debugging purpose.
throw new RuntimeException("Illegal index=" + index + " for name=" + name
+ " language=" + sTextsTableToLanguageMap.get(textsTable));
}
public static String[] getTextsTable(final String language) {
final String[] textsTable = sLanguageToTextsMap.get(language);
final String[] textsTable = sLanguageToTextsTableMap.get(language);
return textsTable != null ? textsTable : LANGUAGE_DEFAULT;
}
@ -89,8 +103,9 @@ public final class KeyboardTextsTable {
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
final String language = (String)LANGUAGES_AND_TEXTS[i];
final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
sLanguageToTextsMap.put(language, texts);
final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1];
sLanguageToTextsTableMap.put(language, textsTable);
sTextsTableToLanguageMap.put(textsTable, language);
}
}
}