Package com.wesabe.api.util.money

Examples of com.wesabe.api.util.money.Money


public class MonetarySummary {
  private final SumOfMoney spending, earnings, net;
 
  public static MonetarySummary summarize(Collection<Money> amounts, Currency currency) {
    int spendingCount = 0, earningsCount = 0;
    Money spendingSum = Money.zero(currency), earningsSum = Money.zero(currency);
   
    for (Money amount : amounts) {
      if (amount.signum() > 0) {
        earningsCount++;
        earningsSum = earningsSum.add(amount);
      } else if (amount.signum() < 0) {
        spendingCount++;
        spendingSum = spendingSum.add(amount.abs());
      }
    }
   
    return new MonetarySummary(
        new SumOfMoney(spendingSum, spendingCount),
View Full Code Here


    if (!canHaveBalance()) {
      return null;
    }

    if (hasCachedBalance()) {
      return new Money(balance, getCurrency());
    }

    return calculateBalance();
  }
View Full Code Here

  public SumOfMoney getNet() {
    return net;
  }
 
  private SumOfMoney calculateNet(SumOfMoney spending, SumOfMoney earnings) {
    final Money amount = earnings.getAmount().subtract(spending.getAmount());
    final int count = earnings.getCount() + spending.getCount();
    return new SumOfMoney(amount, count);
  }
View Full Code Here

    if (accountBalance == null) {
      // FIXME coda@wesabe.com -- Apr 28, 2009: We *really* don't expect getBalance() to return null.
      return null;
    }

    Money balance = accountBalance.getBalance();
    for (Txaction txaction : getTransactionsSince(accountBalance.getDate())) {
      balance = balance.add(txaction.getAmount());
    }

    this.balance = balance.getValue();
    return balance;
  }
View Full Code Here

      assertEquals(Integer.valueOf(12), account.getPosition());
    }
   
    @Test
    public void itAllowsEnablingBalanceAsANoOp() {
      Money balance = account.getBalance();
      account.enableBalance();
      assertEquals(balance, account.getBalance());
    }
View Full Code Here

    }
    return txactionsByTag;
  }

  private Money sumForTag(final Collection<Txaction> txactions, Tag tag, Currency currency) {
    Money sum = Money.zero(currency);
    for (Txaction txaction : txactions) {
      if (tag == OTHER) {
        sum = sum.add(txaction.getConvertedAmount(currency, exchangeRateMap).abs());
      } else {
        for (TaggedAmount taggedAmount : txaction.getTaggedAmounts()) {
          if (tag.equals(taggedAmount.getTag())) {
            sum = sum.add(taggedAmount.getConvertedAmount(currency, exchangeRateMap).abs());
          }
        }
      }
     
    }
View Full Code Here

    return accounts;
  }
 
  public Money getTotal(Currency currency, CurrencyExchangeRateMap exchangeRates) {
    final DateTime now = new DateTime();
    Money total = Money.zero(currency);
    for (Account account : accounts) {
      if (account.hasBalance() && account.isActive()) {
        final Money balance = account.getBalance();
        if (balance != null) {
          total = total.add(balance.convert(exchangeRates, currency, now));
        }
       
      }
    }
    return total;
View Full Code Here

    final Multimap<Interval, Money> groupedAmounts = ArrayListMultimap.create();
    final Map<Interval, Multimap<Tag, Money>> groupedSplitAmounts = Maps.newHashMap();
    for (Txaction txaction : txactions) {
      if (isAnalyzable(txaction)) {
        final Interval interval = intervalType.currentInterval(txaction.getDatePosted());
        final Money filteredAmount = txaction.getConvertedAmountByFilteringTags(
          validFilteredTags, currency, exchangeRateMap);

        groupedAmounts.put(interval, filteredAmount);
       
        if (!groupedSplitAmounts.containsKey(interval)) {
View Full Code Here

  }
 
  // investment account "balance" is sum of market value of positions plus available cash
  @Override
  public Money getBalance() {
    Money availableCash = getAvailableCash();
    if (availableCash != null) {
      return getMarketValue().add(availableCash);     
    } else {
      return getMarketValue();
    }
View Full Code Here

    }
  }

  // market value is the sum of the market value of all current positions
  public Money getMarketValue() {
    Money marketValue = Money.zero(getCurrency());
    for (InvestmentPosition position : getCurrentInvestmentPositions()) {
      marketValue = marketValue.add(position.getMarketValue());
    }
    return marketValue;
  }
View Full Code Here

TOP

Related Classes of com.wesabe.api.util.money.Money

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.