aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/NgramContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/NgramContext.java')
-rw-r--r--java/src/com/android/inputmethod/latin/NgramContext.java28
1 files changed, 12 insertions, 16 deletions
diff --git a/java/src/com/android/inputmethod/latin/NgramContext.java b/java/src/com/android/inputmethod/latin/NgramContext.java
index a02531cc4..82a13274d 100644
--- a/java/src/com/android/inputmethod/latin/NgramContext.java
+++ b/java/src/com/android/inputmethod/latin/NgramContext.java
@@ -19,26 +19,33 @@ package com.android.inputmethod.latin;
import android.text.TextUtils;
import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.Arrays;
+import javax.annotation.Nonnull;
+
/**
* Class to represent information of previous words. This class is used to add n-gram entries
* into binary dictionaries, to get predictions, and to get suggestions.
*/
public class NgramContext {
+ @Nonnull
public static final NgramContext EMPTY_PREV_WORDS_INFO =
new NgramContext(WordInfo.EMPTY_WORD_INFO);
+ @Nonnull
public static final NgramContext BEGINNING_OF_SENTENCE =
- new NgramContext(WordInfo.BEGINNING_OF_SENTENCE);
+ new NgramContext(WordInfo.BEGINNING_OF_SENTENCE_WORD_INFO);
/**
* Word information used to represent previous words information.
*/
public static class WordInfo {
+ @Nonnull
public static final WordInfo EMPTY_WORD_INFO = new WordInfo(null);
- public static final WordInfo BEGINNING_OF_SENTENCE = new WordInfo();
+ @Nonnull
+ public static final WordInfo BEGINNING_OF_SENTENCE_WORD_INFO = new WordInfo();
// This is an empty char sequence when mIsBeginningOfSentence is true.
public final CharSequence mWord;
@@ -48,7 +55,7 @@ public class NgramContext {
public final boolean mIsBeginningOfSentence;
// Beginning of sentence.
- public WordInfo() {
+ private WordInfo() {
mWord = "";
mIsBeginningOfSentence = true;
}
@@ -96,19 +103,8 @@ public class NgramContext {
mPrevWordsCount = prevWordsInfo.length;
}
- // Construct from WordInfo array and size. The caller shouldn't change prevWordsInfo after
- // calling this method.
- private NgramContext(final NgramContext ngramContext, final int prevWordsCount) {
- if (ngramContext.mPrevWordsCount < prevWordsCount) {
- throw new IndexOutOfBoundsException("ngramContext.mPrevWordsCount ("
- + ngramContext.mPrevWordsCount + ") is smaller than prevWordsCount ("
- + prevWordsCount + ")");
- }
- mPrevWordsInfo = ngramContext.mPrevWordsInfo;
- mPrevWordsCount = prevWordsCount;
- }
-
// Create next prevWordsInfo using current prevWordsInfo.
+ @Nonnull
public NgramContext getNextNgramContext(final WordInfo wordInfo) {
final int nextPrevWordCount = Math.min(Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM,
mPrevWordsCount + 1);