private void printOut(Recommend.UserActiveDetail mergeValue) { for (UserActiveDetail.TimeSegment tsegs : mergeValue.getTsegsList()) { logger.info("--id=" + tsegs.getTimeId()); for (UserActiveDetail.TimeSegment.ItemInfo item : tsegs.getItemsList()) { logger.info("-------item=" + item.getItem()); for (UserActiveDetail.TimeSegment.ItemInfo.ActType act : item.getActsList()) { logger.info( "-----------act=" + act.getActType() + ",count=" + act.getCount() + ",time=" + act.getLastUpdateTime()); } } } }
private void mergeOldToMap( UserActiveDetail oldValList, HashMap<Long, HashMap<String, HashMap<Integer, ActType>>> detailMap) { if (oldValList == null || oldValList.getTsegsCount() <= 0) { return; } for (UserActiveDetail.TimeSegment tsegs : oldValList.getTsegsList()) { HashMap<String, HashMap<Integer, ActType>> itemMap; if (detailMap.containsKey(tsegs.getTimeId())) { itemMap = detailMap.get(tsegs.getTimeId()); } else { itemMap = new HashMap<String, HashMap<Integer, ActType>>(); } for (UserActiveDetail.TimeSegment.ItemInfo item : tsegs.getItemsList()) { HashMap<Integer, ActType> actMap; if (itemMap.containsKey(item.getItem())) { actMap = itemMap.get(item.getItem()); } else { actMap = new HashMap<Integer, ActType>(); } for (UserActiveDetail.TimeSegment.ItemInfo.ActType act : item.getActsList()) { Long count = act.getCount(); if (actMap.containsKey(act.getActType())) { count = count + actMap.get(act.getActType()).getCount(); } ActType newActInfo = ActType.newBuilder() .setActType(act.getActType()) .setCount(count) .setLastUpdateTime(act.getLastUpdateTime()) .build(); actMap.put(act.getActType(), newActInfo); } itemMap.put(item.getItem(), actMap); } detailMap.put(tsegs.getTimeId(), itemMap); } }