Add sanity check to KeybaordTextsTable for debugging
Bug: 13007104 Change-Id: Id12f75da7a1c6a2a078d41721ee4016794e9dd2amain
parent
3c4f05dd66
commit
53a237323a
|
@ -85,13 +85,13 @@ public final class KeyboardTextsSet {
|
||||||
do {
|
do {
|
||||||
level++;
|
level++;
|
||||||
if (level >= MAX_STRING_REFERENCE_INDIRECTION) {
|
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 prefixLen = PREFIX_TEXT.length();
|
||||||
final int size = text.length();
|
final int size = text.length();
|
||||||
if (size < prefixLen) {
|
if (size < prefixLen) {
|
||||||
return TextUtils.isEmpty(text) ? null : text;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb = null;
|
sb = null;
|
||||||
|
|
|
@ -43,22 +43,36 @@ import java.util.HashMap;
|
||||||
public final class KeyboardTextsTable {
|
public final class KeyboardTextsTable {
|
||||||
// Name to index map.
|
// Name to index map.
|
||||||
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
|
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
|
||||||
// Language to texts map.
|
// Language to texts table map.
|
||||||
private static final HashMap<String, String[]> sLanguageToTextsMap =
|
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();
|
CollectionUtils.newHashMap();
|
||||||
|
|
||||||
public static String getText(final String name, final String[] textsTable) {
|
public static String getText(final String name, final String[] textsTable) {
|
||||||
final Integer indexObj = sNameToIndexesMap.get(name);
|
final Integer indexObj = sNameToIndexesMap.get(name);
|
||||||
if (indexObj == null) {
|
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 int index = indexObj;
|
||||||
final String text = (index < textsTable.length) ? textsTable[index] : null;
|
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) {
|
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;
|
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) {
|
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
|
||||||
final String language = (String)LANGUAGES_AND_TEXTS[i];
|
final String language = (String)LANGUAGES_AND_TEXTS[i];
|
||||||
final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
|
final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1];
|
||||||
sLanguageToTextsMap.put(language, texts);
|
sLanguageToTextsTableMap.put(language, textsTable);
|
||||||
|
sTextsTableToLanguageMap.put(textsTable, language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,22 +43,36 @@ import java.util.HashMap;
|
||||||
public final class KeyboardTextsTable {
|
public final class KeyboardTextsTable {
|
||||||
// Name to index map.
|
// Name to index map.
|
||||||
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
|
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
|
||||||
// Language to texts map.
|
// Language to texts table map.
|
||||||
private static final HashMap<String, String[]> sLanguageToTextsMap =
|
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();
|
CollectionUtils.newHashMap();
|
||||||
|
|
||||||
public static String getText(final String name, final String[] textsTable) {
|
public static String getText(final String name, final String[] textsTable) {
|
||||||
final Integer indexObj = sNameToIndexesMap.get(name);
|
final Integer indexObj = sNameToIndexesMap.get(name);
|
||||||
if (indexObj == null) {
|
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 int index = indexObj;
|
||||||
final String text = (index < textsTable.length) ? textsTable[index] : null;
|
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) {
|
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;
|
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) {
|
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
|
||||||
final String language = (String)LANGUAGES_AND_TEXTS[i];
|
final String language = (String)LANGUAGES_AND_TEXTS[i];
|
||||||
final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
|
final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1];
|
||||||
sLanguageToTextsMap.put(language, texts);
|
sLanguageToTextsTableMap.put(language, textsTable);
|
||||||
|
sTextsTableToLanguageMap.put(textsTable, language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue