Java 8 Lambda - 两个列表的交集
2022-08-31 22:40:08
我试图根据某些条件找到两个列表并执行一些步骤。找不到一种方法来做到这一点(在学习阶段):)intersection
Double totalAmount = 0.00d;
Double discount = 0.00d;
List<OrderLineEntry> orderLineEntryList = orderEntry.getOrderReleases().stream()
.flatMap(orderReleaseEntry -> orderReleaseEntry.getOrderLines().stream())
.filter(orderLineEntry -> orderLineEntry.getStatus().equals("PP") || orderLineEntry.getStatus().equals("PD"))
.collect(Collectors.toList());
for (OrderLineEntry orderLineEntry : orderLineEntryList) {
for (SplitLineEntry splitLineEntry : splitReleaseEntry.getLineEntries()) {
if (splitLineEntry.getOrderLineId().equals(orderLineEntry.getId()) && splitLineEntry.getStatusCode() != "PX") {
totalAmount += orderLineEntry.getFinalAmount();
couponDiscount += orderLineEntry.getCouponDiscount() == null ? 0.00d : orderLineEntry.getCouponDiscount();
}
}
}
如您所见,逻辑很简单
根据某些筛选器从订单中获取所有项目,并与另一个筛选器相交并执行一些操作。list
list