使用map一次遍历赋值
/*取出它的模型名和它本身作为map*/
Map<String, Integer> applicationNumMap = new HashMap<>();
jssChainModelLogs.forEach(jssChainModelLog -> {
String modelId = jssChainModelLog.getModelId();
/*这个map被深拷贝了,重新分配了地址*/
applicationNumMap.put(modelId, applicationNumMap.getOrDefault(modelId, 0) + 1);
});
/*一次遍历赋值,不用两次for循环*/
for (ModelControlVo modelControlVo : modelControlVos) {
/*赋值调用次数*/
modelControlVo.setApplicationNumber(applicationNumMap.get(modelControlVo.getModelId()));
/*赋值分数*/
JssChainModelAVGScore jssChainModelAVGScore = jssChainModelAVGScoreMap.get(modelControlVo.getModelId());
if (jssChainModelAVGScore != null) {
if (jssChainModelAVGScore.getSynthesisAVGScore()==null){
modelControlVo.setSynthesisAVGScore("0");
}else {
modelControlVo.setSynthesisAVGScore(jssChainModelAVGScore.getSynthesisAVGScore());
}
}
}
标签:map,匹配,modelControlVo,jssChainModelAVGScore,getModelId,applicationNumMap,效率,赋值
From: https://www.cnblogs.com/brickMovingWorker/p/17138932.html