我试图找到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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,逻辑很简单
根据一些过滤器从订单获取所有项目list并与另一个过滤list并做一些事情.
我有这个清单:
private List<Set<Address>> scanList;
Run Code Online (Sandbox Code Playgroud)
所以我的列表包含多个扫描,如您所见.每次扫描后,我都会在列表中添加新集.
完成所有扫描后,我只想获取每组中出现的地址并将其放入:
private List<Address> addresses;
Run Code Online (Sandbox Code Playgroud)
Set/TreeSet/HashSet中是否存在类似的内容?
编辑:在答案之后,retainAll()是正确的方法.谢谢.这是来源:
Set<Address> addressCross = scanList.get(0);
for (int i = 1; i < scanList.size(); i++) {
addressCross.retainAll(scanList.get(i));
}
for (Address address : addressCross) {
addresses.add(address);
}
Run Code Online (Sandbox Code Playgroud) 当我深入研究gs-collection源代码时ImmutableList,它不会扩展java.util.List.但是,类javadoc提到All ImmutableList实现必须实现java.util.List.
为什么必须要求实现实现java.util.List而不是ImmutableList自己扩展java.util.List?