Example #1
0
 public CorpusResult getCorpusResult(Corpus corpus) {
   for (CorpusResult result : mCorpusResults) {
     if (result != null && corpus.equals(result.getCorpus())) {
       return result;
     }
   }
   return null;
 }
Example #2
0
 /**
  * Gets the set of corpora that have reported results to this suggestions set.
  *
  * @return A collection of corpora.
  */
 public Set<Corpus> getIncludedCorpora() {
   HashSet<Corpus> corpora = new HashSet<Corpus>();
   for (CorpusResult result : mCorpusResults) {
     if (result != null) {
       corpora.add(result.getCorpus());
     }
   }
   return corpora;
 }
Example #3
0
  /** Closes all the source results and unregisters all observers. */
  private void close() {
    if (DBG) Log.d(TAG, "close() [" + hashCode() + "]");
    if (mClosed) {
      throw new IllegalStateException("Double close()");
    }
    mClosed = true;
    mDataSetObservable.unregisterAll();
    if (mShortcuts != null) {
      mShortcuts.close();
      mShortcuts = null;
    }

    for (CorpusResult result : mCorpusResults) {
      if (result != null) {
        result.close();
      }
    }
    Arrays.fill(mCorpusResults, null);
  }
Example #4
0
  /**
   * Adds a list of corpus results. Must be called on the UI thread, or before this object is seen
   * by the UI thread.
   */
  public void addCorpusResults(List<CorpusResult> corpusResults) {
    if (isClosed()) {
      for (CorpusResult corpusResult : corpusResults) {
        corpusResult.close();
      }
      return;
    }

    for (CorpusResult corpusResult : corpusResults) {
      if (DBG) {
        Log.d(
            TAG,
            "addCorpusResult["
                + hashCode()
                + "] corpus:"
                + corpusResult.getCorpus().getName()
                + " results:"
                + corpusResult.getCount());
      }
      if (!mQuery.equals(corpusResult.getUserQuery())) {
        throw new IllegalArgumentException(
            "Got result for wrong query: " + mQuery + " != " + corpusResult.getUserQuery());
      }
      Integer pos = mCorpusPositions.get(corpusResult.getCorpus().getName());
      if (pos == null) {
        Log.w(TAG, "Got unexpected CorpusResult from corpus " + corpusResult.getCorpus().getName());
        corpusResult.close();
      } else {
        mCorpusResults[pos] = corpusResult;
        if (corpusResult.getCorpus().isWebCorpus()) {
          mWebResult = corpusResult;
        }
      }
    }
    notifyDataSetChanged();
  }