-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBankBalance.java
32 lines (27 loc) · 1.01 KB
/
BankBalance.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.github.programmingwithmati.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BankBalance {
private Long id;
private BigDecimal amount = BigDecimal.ZERO;
private Date lastUpdate;
private BankTransaction latestTransaction;
public BankBalance process(BankTransaction bankTransaction) {
this.id = bankTransaction.getBalanceId();
this.latestTransaction = bankTransaction;
if(this.amount.add(bankTransaction.getAmount()).compareTo(BigDecimal.ZERO) >= 0) {
this.latestTransaction.setState(BankTransaction.BankTransactionState.APPROVED);
this.amount = this.amount.add(bankTransaction.getAmount());
} else {
this.latestTransaction.setState(BankTransaction.BankTransactionState.REJECTED);
}
this.lastUpdate = bankTransaction.getTime();
return this;
}
}