For loop 带有Set<;的Convert子句;地图<;字符串,对象>&燃气轮机;对forEach条款
我有以下方法:For loop 带有Set<;的Convert子句;地图<;字符串,对象>&燃气轮机;对forEach条款,for-loop,foreach,java-8,For Loop,Foreach,Java 8,我有以下方法: protected Set<Map<String, Object>> joinQueryResults(Set<Map<String, Object>> resultEmpty, Set<Map<String, Object>> resultWithValues){ for(Map<String, Object> mapEmpty: resultEmpty){
protected Set<Map<String, Object>> joinQueryResults(Set<Map<String, Object>> resultEmpty, Set<Map<String, Object>> resultWithValues){
for(Map<String, Object> mapEmpty: resultEmpty){
for(Map<String, Object> mapValue: resultWithValues){
if (mapValue.get("name").equals(mapEmpty.get("name"))){
mapEmpty.replace("totfailed", mapValue.get("totfailed"));
mapEmpty.replace("totsuccess", mapValue.get("totsuccess"));
break;
}
}
}
return resultEmpty;
}
受保护的Set-joinQueryResults(Set-Resulty,Set-ResultWithValue){
对于(Map mapepty:resulty){
用于(映射映射值:resultWithValues){
if(mapValue.get(“name”).equals(mapEmpty.get(“name”)){
mapEmpty.replace(“totfailed”,mapValue.get(“totfailed”);
mapEmpty.replace(“totsuccess”,mapValue.get(“totsuccess”);
打破
}
}
}
回报诱人;
}
如何将其转换为forEach子句?有可能吗?不赞成更新流中的共享可变变量。这应该可以做到
resultEmpty.stream().forEach(empty -> {
resultWithValues.stream()
.filter(
withValues -> withValues.get("name").equals(empty.get("name")))
.findFirst().ifPresent(withValues -> {
empty.replace("totsuccess", withValues.get("totsuccess"));
empty.replace("totfailed", withValues.get("totfailed"));
});
});