diff options
author | 2015-03-12 18:08:29 +0000 | |
---|---|---|
committer | 2015-03-12 18:08:29 +0000 | |
commit | 326261181d9c0df6c586014fa46aceaeb020886b (patch) | |
tree | 695b628e0e2bad66e5726872028d499af19e0152 /java/src | |
parent | b724ff1d11d10da8569bba472e2d3252086047cc (diff) | |
parent | 26fb83c481034cb9dbc9504e60fde40c6b213e97 (diff) | |
download | latinime-326261181d9c0df6c586014fa46aceaeb020886b.tar.gz latinime-326261181d9c0df6c586014fa46aceaeb020886b.tar.xz latinime-326261181d9c0df6c586014fa46aceaeb020886b.zip |
am 26fb83c4: Avoid creating empty String[].
* commit '26fb83c481034cb9dbc9504e60fde40c6b213e97':
Avoid creating empty String[].
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java | 6 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java | 17 |
2 files changed, 12 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index f52444154..00f69f158 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -92,7 +92,8 @@ public final class AndroidSpellCheckerService extends SpellCheckerService } } - @Override public void onCreate() { + @Override + public void onCreate() { super.onCreate(); mRecommendedThreshold = Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value)); @@ -110,7 +111,8 @@ public final class AndroidSpellCheckerService extends SpellCheckerService } } - @Override public void onDestroy() { + @Override + public void onDestroy() { if (DEBUG) { Log.d(TAG, "Closing and dereferencing mUserDictionaryLookup in onDestroy"); } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java index 5c1915c6c..da5c71738 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java @@ -41,6 +41,7 @@ import com.android.inputmethod.latin.utils.StatsUtils; import com.android.inputmethod.latin.utils.SuggestionResults; import java.util.ArrayList; +import java.util.List; import java.util.Locale; public abstract class AndroidWordLevelSpellCheckerSession extends Session { @@ -259,7 +260,6 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { final String text = inText.replaceAll( AndroidSpellCheckerService.APOSTROPHE, AndroidSpellCheckerService.SINGLE_QUOTE); final int capitalizeType = StringUtils.getCapitalizationType(text); - boolean isInDict = true; if (!mService.hasMainDictionaryForLocale(mLocale)) { return AndroidSpellCheckerService.getNotInDictEmptySuggestions( false /* reportAsTypo */); @@ -281,7 +281,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { mLocale, composer.getComposedDataSnapshot(), ngramContext, keyboard); final Result result = getResult(capitalizeType, mLocale, suggestionsLimit, mService.getRecommendedThreshold(), text, suggestionResults); - isInDict = isInDictForAnyCapitalization(text, capitalizeType); + final boolean isInDict = isInDictForAnyCapitalization(text, capitalizeType); if (DBG) { Log.i(TAG, "Spell checking results for " + text + " with suggestion limit " + suggestionsLimit); @@ -329,8 +329,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { private static final class Result { public final String[] mSuggestions; public final boolean mHasRecommendedSuggestions; - public Result(final String[] gatheredSuggestions, - final boolean hasRecommendedSuggestions) { + public Result(final String[] gatheredSuggestions, final boolean hasRecommendedSuggestions) { mSuggestions = gatheredSuggestions; mHasRecommendedSuggestions = hasRecommendedSuggestions; } @@ -364,14 +363,15 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { StringUtils.removeDupes(suggestions); // This returns a String[], while toArray() returns an Object[] which cannot be cast // into a String[]. + final List<String> gatheredSuggestionsList = + suggestions.subList(0, Math.min(suggestions.size(), suggestionsLimit)); final String[] gatheredSuggestions = - suggestions.subList(0, Math.min(suggestions.size(), suggestionsLimit)) - .toArray(EMPTY_STRING_ARRAY); + gatheredSuggestionsList.toArray(new String[gatheredSuggestionsList.size()]); final int bestScore = suggestionResults.first().mScore; final String bestSuggestion = suggestions.get(0); final float normalizedScore = BinaryDictionaryUtils.calcNormalizedScore( - originalText, bestSuggestion.toString(), bestScore); + originalText, bestSuggestion, bestScore); final boolean hasRecommendedSuggestions = (normalizedScore > recommendedThreshold); if (DBG) { Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore); @@ -390,8 +390,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { * That's what the following method does. */ @Override - public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, - final int suggestionsLimit) { + public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, final int suggestionsLimit) { long ident = Binder.clearCallingIdentity(); try { return onGetSuggestionsInternal(textInfo, suggestionsLimit); |