Guest User

Untitled

a guest
Oct 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. // Before:
  2. List<InvoiceInstallment> installments = new ArrayList<InvoiceInstallment>();
  3. Money installmentAmt = amount.divide(numInstallments);
  4.  
  5. Money amountAllocated = Money.ZERO;
  6. for (int i = 1; i <= numInstallments; i++) {
  7. if (i < numInstallments) {
  8. installments.add(new InvoiceInstallment(i,
  9. source.getPlan(),
  10. installmentType,
  11. installmentAmt,
  12. payeeType,
  13. discountPct,
  14. null));
  15. } else {
  16. installments.add(new InvoiceInstallment(i,
  17. source.getPlan(),
  18. installmentType,
  19. amount.subtract(amountAllocated),
  20. payeeType,
  21. discountPct,
  22. null));
  23. }
  24. amountAllocated = amountAllocated.add(installmentAmt);
  25. }
  26. return installments;
  27.  
  28.  
  29.  
  30. // After:
  31. List<InvoiceInstallment> installments = new ArrayList<InvoiceInstallment>();
  32. Money installmentAmt = amount.divide(numInstallments);
  33.  
  34. Money amountAllocated = Money.ZERO;
  35. for (int i = 1; i <= numInstallments; i++) {
  36. installments.add(new InvoiceInstallment(i,
  37. source.getPlan(),
  38. installmentType,
  39. // Ensure installments add back up to total
  40. i < numInstallments ? installmentAmt : amount.subtract(amountAllocated),
  41. payeeType,
  42. discountPct,
  43. null));
  44. amountAllocated = amountAllocated.add(installmentAmt);
  45. }
  46. return installments;
Add Comment
Please, Sign In to add comment