我正在尝试避免使用lambda表达式:
for (OrderEntity o: onEntryL) {
for(GeoFenceEventEntity g: o.getGeoFenceEvent()){
if(null != g.getEndAt() && g.getDynamoGeofenceType().equalsIgnoreCase("WAREHOUSE")){
//all of them, get data
}
}
}
然后在Lambda上尝试类似的操作(有错误):
List<OrderEntity> chargingL = onEntryL.stream()
.map(o->o.getGeoFenceEvent().stream()
.map(g->null != g.getEndAt() && g.getDynamoGeofenceType().equalsIgnoreCase("WAREHOUSE"))
.collect(Collectors.toList()));
感谢您的帮助。
答案 0 :(得分:3)
好,更新评论。假设您有OrderEntry
个符合条件的GeoFenceEventEntity
,则可以使用
List<OrderEntity> chargingL = onEntryL
.stream()
.filter(o -> o.getGeoFenceEvent().stream().anyMatch(g -> null != g.getEndAt() && g.getDynamoGeofenceType().equalsIgnoreCase("WAREHOUSE")))
.collect(Collectors.toList());
答案 1 :(得分:0)
我认为您希望flatMap
与filter
一起使用。
onEntryL.stream()
.map(OrderEntity::getGeoFenceEvent)
.flatMap(e -> e.stream().filter(g -> null != g.getEndAt() && g.getDynamoGeofenceType().equalsIgnoreCase("WAREHOUSE")))
.flatMap(g -> g.getData().stream())
.collect(Collectors.toList());