예제 #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);
 }