Skip to content

Commit

Permalink
Implement Comparable for Account interface
Browse files Browse the repository at this point in the history
Add Comparable interface to Account for sorting by balance. Introduced compareTo method to compare accounts based on their balance.
  • Loading branch information
NonSwag committed Aug 25, 2024
1 parent 3eb79fb commit 7823150
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/net/thenextlvl/service/api/economy/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Account is an interface representing a financial account.
*/
public interface Account {
public interface Account extends Comparable<Account> {
/**
* Deposits the specified amount into the account balance.
*
Expand Down Expand Up @@ -46,4 +46,16 @@ public interface Account {
* @return the UUID of the owner
*/
UUID getOwner();

/**
* Compares this account to the specified account based on their balance.
*
* @param account the account to be compared
* @return a negative integer, zero, or a positive integer if this account is
* less than, equal to, or greater than the specified account
*/
@Override
default int compareTo(Account account) {
return getBalance().compareTo(account.getBalance());
}
}

0 comments on commit 7823150

Please sign in to comment.