Exemplo n.º 1
0
    private void mergeToHeap(
        ActionCombinerValue newValList,
        UserActiveHistory oldVal,
        UserActiveHistory.Builder updatedBuilder) {
      HashSet<String> alreadyIn = new HashSet<String>();

      for (String newItem : newValList.getActRecodeMap().keySet()) {
        if (updatedBuilder.getActRecordsCount() >= topNum) {
          break;
        }

        if (!alreadyIn.contains(newItem)) {
          updatedBuilder.addActRecords(newValList.getActRecodeMap().get(newItem));
          alreadyIn.add(newItem);
        }
      }

      if (oldVal != null) {
        for (Recommend.UserActiveHistory.ActiveRecord eachOldVal : oldVal.getActRecordsList()) {
          if (updatedBuilder.getActRecordsCount() >= topNum) {
            break;
          }
          if (alreadyIn.contains(eachOldVal.getItem())) {
            continue;
          }
          updatedBuilder.addActRecords(eachOldVal);
        }
      }
    }