diff options
author | 2012-03-21 18:10:21 +0900 | |
---|---|---|
committer | 2012-03-21 19:30:26 +0900 | |
commit | e276c2401e5702222b21c4dfe2a25219c2f6619f (patch) | |
tree | 46c7b2bafab5d5cf600b5ce922e34f5bd6d42617 /java/src/com/android/inputmethod/latin/makedict/Word.java | |
parent | 1fe943aabdf6c9a40c634bf4a5450cbed4f6c136 (diff) | |
download | latinime-e276c2401e5702222b21c4dfe2a25219c2f6619f.tar.gz latinime-e276c2401e5702222b21c4dfe2a25219c2f6619f.tar.xz latinime-e276c2401e5702222b21c4dfe2a25219c2f6619f.zip |
Move makedict to LatinIME android keyboard.
Bug: 6188977
Change-Id: I4d2ef504bb983abbda3cb52ee450cb46f58d95cf
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/Word.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/Word.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/Word.java b/java/src/com/android/inputmethod/latin/makedict/Word.java new file mode 100644 index 000000000..c2c01e1f8 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/makedict/Word.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.latin.makedict; + +import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; + +import java.util.ArrayList; + +/** + * Utility class for a word with a frequency. + * + * This is chiefly used to iterate a dictionary. + */ +public class Word implements Comparable<Word> { + final String mWord; + final int mFrequency; + final boolean mIsShortcutOnly; + final ArrayList<WeightedString> mShortcutTargets; + final ArrayList<WeightedString> mBigrams; + + public Word(final String word, final int frequency, + final ArrayList<WeightedString> shortcutTargets, + final ArrayList<WeightedString> bigrams, final boolean isShortcutOnly) { + mWord = word; + mFrequency = frequency; + mShortcutTargets = shortcutTargets; + mBigrams = bigrams; + mIsShortcutOnly = isShortcutOnly; + } + + /** + * Three-way comparison. + * + * A Word x is greater than a word y if x has a higher frequency. If they have the same + * frequency, they are sorted in lexicographic order. + */ + @Override + public int compareTo(Word w) { + if (mFrequency < w.mFrequency) return 1; + if (mFrequency > w.mFrequency) return -1; + return mWord.compareTo(w.mWord); + } + + /** + * Equality test. + * + * Words are equal if they have the same frequency, the same spellings, and the same + * attributes. + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof Word)) return false; + Word w = (Word)o; + return mFrequency == w.mFrequency && mWord.equals(w.mWord) + && mShortcutTargets.equals(w.mShortcutTargets) + && mBigrams.equals(w.mBigrams); + } +} |