1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.inputmethod.latin.makedict; 18 19 import com.android.inputmethod.annotations.UsedForTesting; 20 21 import java.util.Arrays; 22 23 /** 24 * A string with a probability. 25 * 26 * This represents an "attribute", that is either a bigram or a shortcut. 27 */ 28 public final class WeightedString { 29 public final String mWord; 30 public ProbabilityInfo mProbabilityInfo; 31 WeightedString(final String word, final int probability)32 public WeightedString(final String word, final int probability) { 33 this(word, new ProbabilityInfo(probability)); 34 } 35 WeightedString(final String word, final ProbabilityInfo probabilityInfo)36 public WeightedString(final String word, final ProbabilityInfo probabilityInfo) { 37 mWord = word; 38 mProbabilityInfo = probabilityInfo; 39 } 40 41 @UsedForTesting getProbability()42 public int getProbability() { 43 return mProbabilityInfo.mProbability; 44 } 45 setProbability(final int probability)46 public void setProbability(final int probability) { 47 mProbabilityInfo = new ProbabilityInfo(probability); 48 } 49 50 @Override hashCode()51 public int hashCode() { 52 return Arrays.hashCode(new Object[] { mWord, mProbabilityInfo}); 53 } 54 55 @Override equals(Object o)56 public boolean equals(Object o) { 57 if (o == this) return true; 58 if (!(o instanceof WeightedString)) return false; 59 final WeightedString w = (WeightedString)o; 60 return mWord.equals(w.mWord) && mProbabilityInfo.equals(w.mProbabilityInfo); 61 } 62 }