-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from jeffreybakker/feature/extension_6
Feature/extension 6
- Loading branch information
Showing
25 changed files
with
813 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package honours.ing.banq.account; | ||
|
||
import javax.persistence.*; | ||
import java.math.BigDecimal; | ||
|
||
/** | ||
* @author Jeffrey Bakker | ||
* @since 7-8-17 | ||
*/ | ||
@Entity | ||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) | ||
public abstract class Account { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.TABLE) | ||
private Integer id; | ||
|
||
@OneToOne(targetEntity = BankAccount.class, cascade = CascadeType.REFRESH, fetch = FetchType.LAZY) | ||
protected BankAccount account; | ||
|
||
protected BigDecimal balance; | ||
|
||
/** | ||
* @deprecated empty constructor for the Hibernate ORM | ||
*/ | ||
@Deprecated | ||
public Account() { } | ||
|
||
/** | ||
* Creates a new {@link Account}. | ||
* @param account the bank account to which this account belongs | ||
*/ | ||
public Account(BankAccount account) { | ||
this.account = account; | ||
this.balance = BigDecimal.ZERO; | ||
} | ||
|
||
/** | ||
* Returns whether the given amount can be payed from the balance on this account. | ||
* @param amount the amount the user wishes to pay | ||
* @return {@code true} if the user can pay the amount | ||
*/ | ||
public boolean canPayAmount(BigDecimal amount) { | ||
return balance.subtract(amount).compareTo(BigDecimal.ZERO) >= 0; | ||
} | ||
|
||
/** | ||
* Returns the {@link BankAccount} to which this account belongs. | ||
* @return a {@link BankAccount} | ||
*/ | ||
public BankAccount getAccount() { | ||
return account; | ||
} | ||
|
||
/** | ||
* Adds balance to the balance of the account. | ||
* @param delta the difference in balance | ||
*/ | ||
public void addBalance(BigDecimal delta) { | ||
balance = balance.add(delta); | ||
} | ||
|
||
/** | ||
* Returns the balance on the account. | ||
* @return the balance | ||
*/ | ||
public BigDecimal getBalance() { | ||
return balance; | ||
} | ||
|
||
/** | ||
* Returns the ID of the account. | ||
* @return the ID | ||
*/ | ||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.