I get an PublicException: Duplicate Keys
error in this place.
Map<BgwContract, List<Fee>> bgwContractFeeMap = bgwContractList
.stream()
.filter(bgwContract -> !bgwContract.getStatus().equals(BgwContractStatus.CLOSED))
.filter(bgwContract -> availableIbans.contains(bgwContract.getFeeAccount()))
.collect(
Collectors.toMap(bgwContract -> bgwContract,
bgwContractFeeService::getContractMonthlyFees)
);
I understand that the issue is that there are some duplicates and it immediately crashes. I know that a .distinct()
would fix this error, but I don't want to lose any data. Is there a way how to enhance this mapping to fix this error without loosing any values, maybe some kind of a filter or any other kind of java 8 methods? I'm not talking about MultiMaps etc.