private Money sumStockValues(List<Stock> stocks) { Money sum = MoneyFactory.fromString("0"); CurrencyService currencyService = new CurrencyService(getContext()); AccountRepository repo = new AccountRepository(getContext()); int baseCurrencyId = currencyService.getBaseCurrencyId(); for (Stock stock : stocks) { // convert the stock value to the base currency. int accountId = stock.getHeldAt(); int currencyId = repo.loadCurrencyIdFor(accountId); Money value = currencyService.doCurrencyExchange(baseCurrencyId, stock.getValue(), currencyId); sum = sum.add(value); } return sum; }
private Account loadAccount(Context context, int accountId) { AccountRepository repository = new AccountRepository(context); return repository.load(accountId); }