Пример #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);
        }
      }
    }
    private void mergeToHeap(
        ActionCombinerValue newValueList,
        UserActiveDetail oldValueHeap,
        UserActiveDetail.Builder mergeValueBuilder) {

      HashMap<Long, HashMap<String, HashMap<Integer, ActType>>> detailMap =
          new HashMap<Long, HashMap<String, HashMap<Integer, ActType>>>();
      if (oldValueHeap != null && oldValueHeap.getTsegsCount() > 0) {
        mergeOldToMap(oldValueHeap, detailMap);
        if (debug) {
          logger.info("add old values,now size=" + oldValueHeap.getTsegsCount());
        }
      }

      for (String item : newValueList.getActRecodeMap().keySet()) {
        ActiveRecord action = newValueList.getActRecodeMap().get(item);
        Long winId = Utils.getDateByTime(action.getActTime());
        mergeNewRecordsToMap(winId, item, action, detailMap);
        if (debug) {
          logger.info("add new values,size=" + detailMap.get(winId).size());
        }
      }
      changeMapToPB(detailMap, mergeValueBuilder);
    }