Пример #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;
 }
Пример #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;
 }
Пример #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;
   }
 }
Пример #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;
   }
 }
Пример #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;
 }
Пример #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);
 }
Пример #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);
 }
Пример #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);
 }
Пример #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);
 }
Пример #12
0
 public boolean isZero() {
   return equals(Money.valueOf(0.0, currency));
 }
Пример #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);
 }
Пример #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);
 }
Пример #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);
 }
Пример #16
0
 public Money applying(Ratio ratio, int scale, int roundingRule) {
   BigDecimal newAmount = ratio.times(amount).decimalValue(scale, roundingRule);
   return Money.valueOf(newAmount, currency);
 }
Пример #17
0
 public Money dividedBy(BigDecimal divisor, int roundingMode) {
   BigDecimal newAmount = amount.divide(divisor, roundingMode);
   return Money.valueOf(newAmount, currency);
 }
Пример #18
0
 public Money minus(Money other) {
   return plus(other.negated());
 }
Пример #19
0
 public Money plus(Money other) {
   assertHasSameCurrencyAs(other);
   return Money.valueOf(amount.add(other.amount), currency);
 }
Пример #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);
 }
Пример #21
0
 public static Money zeroIfNull(Money money) {
   return money == null ? Money.dollars(0.00) : money;
 }
Пример #22
0
 public Money negated() {
   return Money.valueOf(amount.negate(), currency);
 }
Пример #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);
 }
Пример #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);
 }
Пример #25
0
 private void assertHasSameCurrencyAs(Money aMoney) {
   if (!hasSameCurrencyAs(aMoney)) {
     throw new IllegalArgumentException(
         aMoney.toString() + " is not same currency as " + toString());
   }
 }
Пример #26
0
 public Money abs() {
   return Money.valueOf(amount.abs(), currency);
 }