Class Wallet
java.lang.Object
org.episteme.social.economics.money.Wallet
- All Implemented Interfaces:
Serializable
Represents a wallet for storing money.
A wallet can hold multiple currencies and provides methods for calculating totals and managing balances. Modernized to use Real for internal calculations and balance management.
- Since:
- 1.0
- Version:
- 1.1
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds money to the wallet.voidclear()Clears all contents from the wallet.getBalance(Currency currency) Returns the balance for a specific currency.Returns an unmodifiable view of the wallet contents.Returns all currencies in the wallet.Calculates the total value in a target currency.booleanisEmpty()Checks if the wallet is empty.booleanremoveValue(Money amount) Removes money from the wallet.intsize()Returns the number of items in the wallet.toString()booleanWithdraws a specific amount from the wallet.booleanWithdraws a specific amount from the wallet.
-
Constructor Details
-
Wallet
public Wallet()Creates a new empty Wallet. -
Wallet
Creates a wallet with initial amount.- Parameters:
initial- the initial money
-
-
Method Details
-
getContents
-
getValue
Calculates the total value in a target currency.- Parameters:
bank- the bank for currency conversionresultCurrency- the target currency- Returns:
- the total value
- Throws:
UnavailableDataException- if exchange rate data cannot be retrieved
-
getBalance
-
getCurrencies
-
addValue
Adds money to the wallet.- Parameters:
amount- the amount to add- Throws:
IllegalArgumentException- if amount is null
-
removeValue
Removes money from the wallet.- Parameters:
amount- the amount to remove- Returns:
- true if the amount was found and removed
-
withdraw
Withdraws a specific amount from the wallet. Accepts a double for compatibility with UI/devices.- Parameters:
amount- the amount to withdraw (double)currency- the currency- Returns:
- true if successful
-
withdraw
-
isEmpty
public boolean isEmpty()Checks if the wallet is empty.- Returns:
- true if empty
-
size
public int size()Returns the number of items in the wallet.- Returns:
- the count
-
clear
public void clear()Clears all contents from the wallet. -
toString
-