/**
   * Determine whether a word is a distracter to words in dictionaries.
   *
   * @param prevWordsInfo the information of previous words. Not used for now.
   * @param testedWord the word that will be tested to see whether it is a distracter to words in
   *     dictionaries.
   * @param locale the locale of word.
   * @return true if testedWord is a distracter, otherwise false.
   */
  @Override
  public boolean isDistracterToWordsInDictionaries(
      final PrevWordsInfo prevWordsInfo, final String testedWord, final Locale locale) {
    if (locale == null) {
      return false;
    }
    if (!locale.equals(mDictionaryFacilitator.getLocale())) {
      synchronized (mLock) {
        if (!mLocaleToSubtypeMap.containsKey(locale)) {
          Log.e(TAG, "Locale " + locale + " is not enabled.");
          // TODO: Investigate what we should do for disabled locales.
          return false;
        }
        loadKeyboardForLocale(locale);
        // Reset dictionaries for the locale.
        try {
          mDistractersCache.evictAll();
          loadDictionariesForLocale(locale);
        } catch (final InterruptedException e) {
          Log.e(TAG, "Interrupted while waiting for loading dicts in DistracterFilter", e);
          return false;
        }
      }
    }

    if (DEBUG) {
      Log.d(TAG, "testedWord: " + testedWord);
    }
    final Boolean isCachedDistracter = mDistractersCache.get(testedWord);
    if (isCachedDistracter != null && isCachedDistracter) {
      if (DEBUG) {
        Log.d(TAG, "isDistracter: true (cache hit)");
      }
      return true;
    }

    final boolean isDistracterCheckedByGetMaxFreqencyOfExactMatches =
        checkDistracterUsingMaxFreqencyOfExactMatches(testedWord);
    if (isDistracterCheckedByGetMaxFreqencyOfExactMatches) {
      // Add the word to the cache.
      mDistractersCache.put(testedWord, Boolean.TRUE);
      return true;
    }
    final boolean isValidWord =
        mDictionaryFacilitator.isValidWord(testedWord, false /* ignoreCase */);
    if (isValidWord) {
      // Valid word is not a distractor.
      if (DEBUG) {
        Log.d(TAG, "isDistracter: false (valid word)");
      }
      return false;
    }

    final boolean isDistracterCheckedByGetSuggestion =
        checkDistracterUsingGetSuggestions(testedWord);
    if (isDistracterCheckedByGetSuggestion) {
      // Add the word to the cache.
      mDistractersCache.put(testedWord, Boolean.TRUE);
      return true;
    }
    return false;
  }