Ejemplo n.º 1
0
 /** Return the sum of <code>money</code> */
 public static Money sum(List<Money> money) {
   Money total = Money.dollars(0.00);
   for (Iterator<Money> i = money.iterator(); i.hasNext(); ) {
     total = total.plus(i.next());
   }
   return total;
 }
Ejemplo n.º 2
0
 public static Money sum(Collection<Money> monies) {
   // TODO Return Default Currency
   if (monies.isEmpty()) {
     return Money.dollars(0.00);
   }
   Iterator<Money> iterator = monies.iterator();
   Money sum = iterator.next();
   while (iterator.hasNext()) {
     Money each = iterator.next();
     sum = sum.plus(each);
   }
   return sum;
 }
Ejemplo n.º 3
0
 /** Return the min of <code>a</code> or <code>b</code> */
 public static Money min(Money a, Money b) {
   if (a.isLessThan(b)) {
     return a;
   } else {
     return b;
   }
 }
Ejemplo n.º 4
0
 /** Return the max of <code>a</code> or <code>b</code> */
 public static Money max(Money a, Money b) {
   if (a.isGreaterThan(b)) {
     return a;
   } else {
     return b;
   }
 }
Ejemplo n.º 5
0
 public OrderResponse copy() {
   OrderResponse dst = new OrderResponse();
   dst.request = request == null ? null : request.copy();
   dst.date = date == null ? null : date.copy();
   dst.who = who == null ? null : who.copy();
   dst.authority = authority == null ? null : authority.copy();
   dst.cost = cost == null ? null : cost.copy();
   dst.code = code == null ? null : code.copy();
   dst.description = description == null ? null : description.copy();
   dst.fulfillment = new ArrayList<ResourceReference>();
   for (ResourceReference i : fulfillment) dst.fulfillment.add(i.copy());
   return dst;
 }
 public boolean isEmpty() {
   return super.isEmpty()
       && (identifier == null || identifier.isEmpty())
       && (name == null || name.isEmpty())
       && (type == null || type.isEmpty())
       && (status == null || status.isEmpty())
       && (activePeriod == null || activePeriod.isEmpty())
       && (currency == null || currency.isEmpty())
       && (balance == null || balance.isEmpty())
       && (coveragePeriod == null || coveragePeriod.isEmpty())
       && (subject == null || subject.isEmpty())
       && (owner == null || owner.isEmpty())
       && (description == null || description.isEmpty());
 }
 public Account copy() {
   Account dst = new Account();
   copyValues(dst);
   if (identifier != null) {
     dst.identifier = new ArrayList<Identifier>();
     for (Identifier i : identifier) dst.identifier.add(i.copy());
   }
   ;
   dst.name = name == null ? null : name.copy();
   dst.type = type == null ? null : type.copy();
   dst.status = status == null ? null : status.copy();
   dst.activePeriod = activePeriod == null ? null : activePeriod.copy();
   dst.currency = currency == null ? null : currency.copy();
   dst.balance = balance == null ? null : balance.copy();
   dst.coveragePeriod = coveragePeriod == null ? null : coveragePeriod.copy();
   dst.subject = subject == null ? null : subject.copy();
   dst.owner = owner == null ? null : owner.copy();
   dst.description = description == null ? null : description.copy();
   return dst;
 }
Ejemplo n.º 8
0
 /**
  * WARNING: Because of the indefinite precision of double, this method must round off the value.
  */
 public static Money euros(double amount) {
   return Money.valueOf(amount, Money.EUR);
 }
Ejemplo n.º 9
0
 /**
  * This creation method is safe to use. It will adjust scale, but will not round off the amount.
  */
 public static Money valueOf(BigDecimal amount, Currency currency) {
   return Money.valueOf(amount, currency, Rounding.UNNECESSARY);
 }
Ejemplo n.º 10
0
 /**
  * This creation method is safe to use. It will adjust scale, but will not round off the amount.
  */
 public static Money dollars(BigDecimal amount) {
   return Money.valueOf(amount, Money.USD);
 }
Ejemplo n.º 11
0
 /**
  * WARNING: Because of the indefinite precision of double, thismethod must round off the value.
  */
 public static Money dollars(double amount) {
   return Money.valueOf(amount, Money.USD);
 }
Ejemplo n.º 12
0
 public boolean isZero() {
   return equals(Money.valueOf(0.0, currency));
 }
Ejemplo n.º 13
0
 /** Return the max of <code>a</code> or <code>0</code> */
 public static Money notBelowZero(Money a) {
   Money zero = Money.valueOf(0.00, a.getCurrency());
   return Money.max(zero, a);
 }
Ejemplo n.º 14
0
 /**
  * This probably should be Currency responsibility. Even then, it may need to be customized for
  * specialty apps because there are other cases, where the smallest increment is not the smallest
  * unit.
  */
 Money minimumIncrement() {
   BigDecimal one = new BigDecimal(1);
   BigDecimal increment = one.movePointLeft(currency.getDefaultFractionDigits());
   return Money.valueOf(increment, currency);
 }
Ejemplo n.º 15
0
 /**
  * TODO: BigDecimal.multiply() scale is sum of scales of two multiplied numbers. So what is scale
  * of times?
  */
 public Money times(BigDecimal factor, int roundingMode) {
   return Money.valueOf(amount.multiply(factor), currency, roundingMode);
 }
Ejemplo n.º 16
0
 public Money applying(Ratio ratio, int scale, int roundingRule) {
   BigDecimal newAmount = ratio.times(amount).decimalValue(scale, roundingRule);
   return Money.valueOf(newAmount, currency);
 }
Ejemplo n.º 17
0
 public Money dividedBy(BigDecimal divisor, int roundingMode) {
   BigDecimal newAmount = amount.divide(divisor, roundingMode);
   return Money.valueOf(newAmount, currency);
 }
Ejemplo n.º 18
0
 public Money minus(Money other) {
   return plus(other.negated());
 }
Ejemplo n.º 19
0
 public Money plus(Money other) {
   assertHasSameCurrencyAs(other);
   return Money.valueOf(amount.add(other.amount), currency);
 }
Ejemplo n.º 20
0
 /**
  * This creation method is safe to use. It will adjust scale, but will not round off the amount.
  */
 public static Money euros(BigDecimal amount) {
   return Money.valueOf(amount, Money.EUR);
 }
Ejemplo n.º 21
0
 public static Money zeroIfNull(Money money) {
   return money == null ? Money.dollars(0.00) : money;
 }
Ejemplo n.º 22
0
 public Money negated() {
   return Money.valueOf(amount.negate(), currency);
 }
Ejemplo n.º 23
0
 /**
  * WARNING: Because of the indefinite precision of double, this method must round off the value.
  */
 public static Money valueOf(double dblAmount, Currency currency) {
   return Money.valueOf(dblAmount, currency, Money.DEFAULT_ROUNDING_MODE);
 }
Ejemplo n.º 24
0
 /**
  * Because of the indefinite precision of double, this method must round off the value. This
  * method gives the client control of the rounding mode.
  */
 public static Money valueOf(double dblAmount, Currency currency, int roundingMode) {
   BigDecimal rawAmount = new BigDecimal(dblAmount);
   return Money.valueOf(rawAmount, currency, roundingMode);
 }
Ejemplo n.º 25
0
 private void assertHasSameCurrencyAs(Money aMoney) {
   if (!hasSameCurrencyAs(aMoney)) {
     throw new IllegalArgumentException(
         aMoney.toString() + " is not same currency as " + toString());
   }
 }
Ejemplo n.º 26
0
 public Money abs() {
   return Money.valueOf(amount.abs(), currency);
 }