Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f0ea52a authored by Ken Wakasa's avatar Ken Wakasa
Browse files

Add missing Word.hashCode()

Some cleanups too.

bug: 6209651
Change-Id: I94e2e29c92e90e554e4952d277d590e093766c4f
parent e7cfe436
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ public class Key {
        mY = y;
        mHitBox.set(x, y, x + width + 1, y + height);

        mHashCode = hashCode(this);
        mHashCode = computeHashCode(this);
    }

    /**
@@ -334,7 +334,7 @@ public class Key {
        mAltCode = adjustCaseOfCodeForKeyboardId(style.getInt(keyAttr,
                R.styleable.Keyboard_Key_altCode, Keyboard.CODE_UNSPECIFIED), preserveCase,
                params.mId);
        mHashCode = hashCode(this);
        mHashCode = computeHashCode(this);

        keyAttr.recycle();

@@ -366,7 +366,7 @@ public class Key {
        }
    }

    private static int hashCode(Key key) {
    private static int computeHashCode(Key key) {
        return Arrays.hashCode(new Object[] {
                key.mX,
                key.mY,
+28 −28
Original line number Diff line number Diff line
@@ -70,23 +70,23 @@ public class KeyboardId {
    public KeyboardId(int elementId, Locale locale, int orientation, int width, int mode,
            EditorInfo editorInfo, boolean clobberSettingsKey, boolean shortcutKeyEnabled,
            boolean hasShortcutKey, boolean languageSwitchKeyEnabled) {
        this.mLocale = locale;
        this.mOrientation = orientation;
        this.mWidth = width;
        this.mMode = mode;
        this.mElementId = elementId;
        this.mEditorInfo = editorInfo;
        this.mClobberSettingsKey = clobberSettingsKey;
        this.mShortcutKeyEnabled = shortcutKeyEnabled;
        this.mHasShortcutKey = hasShortcutKey;
        this.mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled;
        this.mCustomActionLabel = (editorInfo.actionLabel != null)
        mLocale = locale;
        mOrientation = orientation;
        mWidth = width;
        mMode = mode;
        mElementId = elementId;
        mEditorInfo = editorInfo;
        mClobberSettingsKey = clobberSettingsKey;
        mShortcutKeyEnabled = shortcutKeyEnabled;
        mHasShortcutKey = hasShortcutKey;
        mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled;
        mCustomActionLabel = (editorInfo.actionLabel != null)
                ? editorInfo.actionLabel.toString() : null;

        this.mHashCode = hashCode(this);
        mHashCode = computeHashCode(this);
    }

    private static int hashCode(KeyboardId id) {
    private static int computeHashCode(KeyboardId id) {
        return Arrays.hashCode(new Object[] {
                id.mOrientation,
                id.mElementId,
@@ -109,21 +109,21 @@ public class KeyboardId {
    private boolean equals(KeyboardId other) {
        if (other == this)
            return true;
        return other.mOrientation == this.mOrientation
                && other.mElementId == this.mElementId
                && other.mMode == this.mMode
                && other.mWidth == this.mWidth
                && other.passwordInput() == this.passwordInput()
                && other.mClobberSettingsKey == this.mClobberSettingsKey
                && other.mShortcutKeyEnabled == this.mShortcutKeyEnabled
                && other.mHasShortcutKey == this.mHasShortcutKey
                && other.mLanguageSwitchKeyEnabled == this.mLanguageSwitchKeyEnabled
                && other.isMultiLine() == this.isMultiLine()
                && other.imeAction() == this.imeAction()
                && TextUtils.equals(other.mCustomActionLabel, this.mCustomActionLabel)
                && other.navigateNext() == this.navigateNext()
                && other.navigatePrevious() == this.navigatePrevious()
                && other.mLocale.equals(this.mLocale);
        return other.mOrientation == mOrientation
                && other.mElementId == mElementId
                && other.mMode == mMode
                && other.mWidth == mWidth
                && other.passwordInput() == passwordInput()
                && other.mClobberSettingsKey == mClobberSettingsKey
                && other.mShortcutKeyEnabled == mShortcutKeyEnabled
                && other.mHasShortcutKey == mHasShortcutKey
                && other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled
                && other.isMultiLine() == isMultiLine()
                && other.imeAction() == imeAction()
                && TextUtils.equals(other.mCustomActionLabel, mCustomActionLabel)
                && other.navigateNext() == navigateNext()
                && other.navigatePrevious() == navigatePrevious()
                && other.mLocale.equals(mLocale);
    }

    public boolean isAlphabetKeyboard() {
+13 −0
Original line number Diff line number Diff line
@@ -64,6 +64,19 @@ public class FusionDictionary implements Iterable<Word> {
            mWord = word;
            mFrequency = frequency;
        }

        @Override
        public int hashCode() {
            return Arrays.hashCode(new Object[] { mWord, mFrequency });
        }

        @Override
        public boolean equals(Object o) {
            if (o == this) return true;
            if (!(o instanceof WeightedString)) return false;
            WeightedString w = (WeightedString)o;
            return mWord.equals(w.mWord) && mFrequency == w.mFrequency;
        }
    }

    /**
+22 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Utility class for a word with a frequency.
@@ -32,6 +33,8 @@ public class Word implements Comparable<Word> {
    final ArrayList<WeightedString> mShortcutTargets;
    final ArrayList<WeightedString> mBigrams;

    private int mHashCode = 0;

    public Word(final String word, final int frequency,
            final ArrayList<WeightedString> shortcutTargets,
            final ArrayList<WeightedString> bigrams, final boolean isShortcutOnly) {
@@ -42,6 +45,16 @@ public class Word implements Comparable<Word> {
        mIsShortcutOnly = isShortcutOnly;
    }

    private static int computeHashCode(Word word) {
        return Arrays.hashCode(new Object[] {
                word.mWord,
                word.mFrequency,
                word.mIsShortcutOnly,
                word.mShortcutTargets.hashCode(),
                word.mBigrams.hashCode()
        });
    }

    /**
     * Three-way comparison.
     *
@@ -63,10 +76,19 @@ public class Word implements Comparable<Word> {
     */
    @Override
    public boolean equals(Object o) {
        if (o == this) return true;
        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);
    }

    @Override
    public int hashCode() {
        if (mHashCode == 0) {
            mHashCode = computeHashCode(this);
        }
        return mHashCode;
    }
}