Skip to content

Commit

Permalink
Skip 0 amount transactions on import
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Jul 6, 2024
1 parent 806f75b commit 2a476ea
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/link/biosmarcel/baka/data/Data.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package link.biosmarcel.baka.data;

import java.math.BigDecimal;
import java.util.*;

/**
Expand All @@ -21,8 +22,10 @@ public class Data {
* to import. The existing data should receive identifiers, so that this process can be repeated for the future.
*/
public Map<Payment, Payment> importPayments(final Collection<Payment> newPayments) {
final var deduplicatedPayments = newPayments
final var filteredPayments = newPayments
.stream()
// Banks sometimes add info payments at the end of the months. We don't want these for now.
.filter(payment -> payment.amount.compareTo(BigDecimal.ZERO) != 0)
.filter(newPayment -> {
// We iterate backwards to save time, as the payments are sorted by date descending.
for (int i = payments.size() - 1; i >= 0; i--) {
Expand All @@ -45,7 +48,6 @@ public Map<Payment, Payment> importPayments(final Collection<Payment> newPayment
})
.toList();


final Map<Payment, Payment> possibleDuplicates = new HashMap<>();
OUTER_LOOP:
for (final var newPayment : newPayments) {
Expand All @@ -62,7 +64,7 @@ public Map<Payment, Payment> importPayments(final Collection<Payment> newPayment
}
}

payments.addAll(deduplicatedPayments);
payments.addAll(filteredPayments);

// Since we can't guarantee the imported data to be in our desired order, we resort the whole thing.
payments.sort((o1, o2) -> {
Expand Down

0 comments on commit 2a476ea

Please sign in to comment.