Class Wallet

java.lang.Object
org.episteme.social.economics.money.Wallet
All Implemented Interfaces:
Serializable

public final class Wallet extends Object implements 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 Details

    • Wallet

      public Wallet()
      Creates a new empty Wallet.
    • Wallet

      public Wallet(Money initial)
      Creates a wallet with initial amount.
      Parameters:
      initial - the initial money
  • Method Details

    • getContents

      public List<Money> getContents()
      Returns an unmodifiable view of the wallet contents.
      Returns:
      the contents
    • getValue

      public Money getValue(Bank bank, Currency resultCurrency) throws UnavailableDataException
      Calculates the total value in a target currency.
      Parameters:
      bank - the bank for currency conversion
      resultCurrency - the target currency
      Returns:
      the total value
      Throws:
      UnavailableDataException - if exchange rate data cannot be retrieved
    • getBalance

      public Money getBalance(Currency currency)
      Returns the balance for a specific currency.
      Parameters:
      currency - the currency
      Returns:
      the balance
    • getCurrencies

      public Set<Currency> getCurrencies()
      Returns all currencies in the wallet.
      Returns:
      set of currencies
    • addValue

      public void addValue(Money amount)
      Adds money to the wallet.
      Parameters:
      amount - the amount to add
      Throws:
      IllegalArgumentException - if amount is null
    • removeValue

      public boolean removeValue(Money amount)
      Removes money from the wallet.
      Parameters:
      amount - the amount to remove
      Returns:
      true if the amount was found and removed
    • withdraw

      public boolean withdraw(double amount, Currency currency)
      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

      public boolean withdraw(Real amount, Currency currency)
      Withdraws a specific amount from the wallet. Internal API uses Real for precision.
      Parameters:
      amount - the amount to withdraw (Real)
      currency - the currency
      Returns:
      true if successful
    • 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

      public String toString()
      Overrides:
      toString in class Object