У меня есть два листа, я хочу сравнить их с друг-другом, если один объект нет в другом листе, то ввести его.
Но мой код не работает, в чем может быть проблема?
public void compare() {
List<PaymentRBS> testRBS = new ArrayList<>();
PaymentRBS rbs2 = new PaymentRBS(1998, "996552140898", false);
PaymentRBS rbs3 = new PaymentRBS(1998, "996552140898", false);
PaymentRBS rbs4 = new PaymentRBS(1998, "996552140898", false);
PaymentRBS rbs5 = new PaymentRBS(1997, "996552140897", false);
testRBS.add(rbs2);
testRBS.add(rbs3);
testRBS.add(rbs4);
testRBS.add(rbs5);
List<PaymentPartner> testPartner = new ArrayList<>();
PaymentPartner partner1 = new PaymentPartner(1998, "9965522140898", false);
PaymentPartner partner2 = new PaymentPartner(1998, "9965522140898", false);
PaymentPartner partner3 = new PaymentPartner(1998, "9965522140898", false);
PaymentPartner partner4 = new PaymentPartner(1996, "9965522140896", false);
testPartner.add(partner1);
testPartner.add(partner2);
testPartner.add(partner3);
testPartner.add(partner4);
log.info("ТРАНЗАКЦИИ КОТОРЫЕ НЕ СОВПАЛИ:");
try {
for (PaymentRBS rbs : testRBS) {
for (PaymentPartner partner : testPartner) {
if (partner.getAccount().equals(rbs.getAccount()) && partner.getSum() == rbs.getSum()) {
partner.setExist(true);
rbs.setExist(true);
}
}
}
} catch (OutOfMemoryError | ConcurrentModificationException exception) {
exception.printStackTrace();
}
notMatchedRBS = testRBS.stream().filter(r -> !r.isExist()).collect(Collectors.toList());
notMatchedPartner = testPartner.stream().filter(p -> !p.isExist()).collect(Collectors.toList());
notMatchedPartner.forEach(System.out::println);
notMatchedRBS.forEach(System.out::println);
}
результат: