List of usage examples for java.math BigDecimal multiply
public BigDecimal multiply(BigDecimal multiplicand)
(this × multiplicand)
, and whose scale is (this.scale() + multiplicand.scale()) . From source file:org.kuali.kfs.fp.document.service.impl.DisbursementVoucherTaxServiceImpl.java
/** * This method generates non-resident alien (NRA) tax lines for the given disbursement voucher. * //from w w w . ja v a 2 s . c o m * The NRA tax lines consist of three possible sets of tax lines: * - Gross up tax lines * - Federal tax lines * - State tax lines * * Gross up tax lines are generated if the income tax gross up code is set on the DisbursementVoucherNonResidentAlienTax * attribute of the disbursement voucher. * * Federal tax lines are generated if the federal tax rate in the DisbursementVoucherNonResidentAlienTax attribute is * other than zero. * * State tax lines are generated if the state tax rate in the DisbursementVoucherNonResidentAlienTax attribute is * other than zero. * * @param document The disbursement voucher the NRA tax lines will be added to. * * @see org.kuali.kfs.fp.document.service.DisbursementVoucherTaxService#generateNRATaxLines(org.kuali.kfs.fp.document.DisbursementVoucherDocument) */ protected void generateNRATaxLines(DisbursementVoucherDocument document) { // retrieve first accounting line for tax line attributes AccountingLine line1 = document.getSourceAccountingLine(0); List taxLineNumbers = new ArrayList(); // generate gross up if (document.getDvNonResidentAlienTax().isIncomeTaxGrossUpCode()) { AccountingLine grossLine = null; try { grossLine = (SourceAccountingLine) document.getSourceAccountingLineClass().newInstance(); } catch (IllegalAccessException e) { throw new InfrastructureException("unable to access sourceAccountingLineClass", e); } catch (InstantiationException e) { throw new InfrastructureException("unable to instantiate sourceAccountingLineClass", e); } grossLine.setDocumentNumber(document.getDocumentNumber()); grossLine.setSequenceNumber(document.getNextSourceLineNumber()); grossLine.setChartOfAccountsCode(line1.getChartOfAccountsCode()); grossLine.setAccountNumber(line1.getAccountNumber()); grossLine.setFinancialObjectCode(line1.getFinancialObjectCode()); // calculate gross up amount and set as line amount BigDecimal federalTaxPercent = document.getDvNonResidentAlienTax().getFederalIncomeTaxPercent() .bigDecimalValue(); BigDecimal stateTaxPercent = document.getDvNonResidentAlienTax().getStateIncomeTaxPercent() .bigDecimalValue(); BigDecimal documentAmount = document.getDisbVchrCheckTotalAmount().bigDecimalValue(); KualiDecimal grossAmount1 = new KualiDecimal((documentAmount.multiply(federalTaxPercent).divide( new BigDecimal(100).subtract(federalTaxPercent).subtract(stateTaxPercent), 5, BigDecimal.ROUND_HALF_UP))); KualiDecimal grossAmount2 = new KualiDecimal((documentAmount.multiply(stateTaxPercent).divide( new BigDecimal(100).subtract(federalTaxPercent).subtract(stateTaxPercent), 5, BigDecimal.ROUND_HALF_UP))); grossLine.setAmount(grossAmount1.add(grossAmount2)); // put line number in line number list, and update next line property in document taxLineNumbers.add(grossLine.getSequenceNumber()); document.setNextSourceLineNumber(new Integer(document.getNextSourceLineNumber().intValue() + 1)); // add to source accounting lines grossLine.refresh(); document.getSourceAccountingLines().add(grossLine); // update check total, is added because line amount is negative, so this will take check amount down document.setDisbVchrCheckTotalAmount(document.getDisbVchrCheckTotalAmount().add(grossLine.getAmount())); } KualiDecimal taxableAmount = document.getDisbVchrCheckTotalAmount(); // generate federal tax line if (!(KualiDecimal.ZERO.equals(document.getDvNonResidentAlienTax().getFederalIncomeTaxPercent()))) { String federalTaxChart = parameterService.getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.FEDERAL_TAX_PARM_PREFIX + DisbursementVoucherConstants.TAX_PARM_CHART_SUFFIX); String federalTaxAccount = parameterService.getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.FEDERAL_TAX_PARM_PREFIX + DisbursementVoucherConstants.TAX_PARM_ACCOUNT_SUFFIX); String federalTaxObjectCode = parameterService.getSubParameterValueAsString( DisbursementVoucherDocument.class, DisbursementVoucherConstants.FEDERAL_TAX_PARM_PREFIX + DisbursementVoucherConstants.TAX_PARM_OBJECT_BY_INCOME_CLASS_SUFFIX, document.getDvNonResidentAlienTax().getIncomeClassCode()); if (StringUtils.isBlank(federalTaxChart) || StringUtils.isBlank(federalTaxAccount) || StringUtils.isBlank(federalTaxObjectCode)) { LOG.error("Unable to retrieve federal tax parameters."); throw new RuntimeException("Unable to retrieve federal tax parameters."); } AccountingLine federalTaxLine = generateTaxAccountingLine(document, federalTaxChart, federalTaxAccount, federalTaxObjectCode, document.getDvNonResidentAlienTax().getFederalIncomeTaxPercent(), taxableAmount); // put line number in line number list, and update next line property in document taxLineNumbers.add(federalTaxLine.getSequenceNumber()); document.setNextSourceLineNumber(new Integer(document.getNextSourceLineNumber().intValue() + 1)); // add to source accounting lines federalTaxLine.refresh(); document.getSourceAccountingLines().add(federalTaxLine); // update check total, is added because line amount is negative, so this will take check amount down document.setDisbVchrCheckTotalAmount( document.getDisbVchrCheckTotalAmount().add(federalTaxLine.getAmount())); } // generate state tax line if (!(KualiDecimal.ZERO.equals(document.getDvNonResidentAlienTax().getStateIncomeTaxPercent()))) { String stateTaxChart = parameterService.getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.STATE_TAX_PARM_PREFIX + DisbursementVoucherConstants.TAX_PARM_CHART_SUFFIX); String stateTaxAccount = parameterService.getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.STATE_TAX_PARM_PREFIX + DisbursementVoucherConstants.TAX_PARM_ACCOUNT_SUFFIX); String stateTaxObjectCode = parameterService.getSubParameterValueAsString( DisbursementVoucherDocument.class, DisbursementVoucherConstants.STATE_TAX_PARM_PREFIX + DisbursementVoucherConstants.TAX_PARM_OBJECT_BY_INCOME_CLASS_SUFFIX, document.getDvNonResidentAlienTax().getIncomeClassCode()); if (StringUtils.isBlank(stateTaxChart) || StringUtils.isBlank(stateTaxAccount) || StringUtils.isBlank(stateTaxObjectCode)) { LOG.error("Unable to retrieve state tax parameters."); throw new RuntimeException("Unable to retrieve state tax parameters."); } AccountingLine stateTaxLine = generateTaxAccountingLine(document, stateTaxChart, stateTaxAccount, stateTaxObjectCode, document.getDvNonResidentAlienTax().getStateIncomeTaxPercent(), taxableAmount); // put line number in line number list, and update next line property in document taxLineNumbers.add(stateTaxLine.getSequenceNumber()); document.setNextSourceLineNumber(new Integer(document.getNextSourceLineNumber().intValue() + 1)); // add to source accounting lines stateTaxLine.refresh(); document.getSourceAccountingLines().add(stateTaxLine); // update check total, is added because line amount is negative, so this will take check amount down document.setDisbVchrCheckTotalAmount( document.getDisbVchrCheckTotalAmount().add(stateTaxLine.getAmount())); } // update line number field document.getDvNonResidentAlienTax() .setFinancialDocumentAccountingLineText(StringUtils.join(taxLineNumbers.iterator(), ",")); }
From source file:org.kuali.ole.fp.document.service.impl.DisbursementVoucherTaxServiceImpl.java
/** * Generates an accounting line for the chart, account, object code & tax percentage values given. * /*from w w w. j a va 2s . co m*/ * @param document The disbursement voucher the tax will be applied to. * @param chart The chart code to be assigned to the accounting line generated. * @param account The account code to be assigned to the accounting line generated. * @param objectCode The object code used on the accounting line generated. * @param taxPercent The tax rate to be used to calculate the tax amount. * @param taxableAmount The total amount that is taxable. This amount is used in conjunction with the tax percent * to calculate the amount for the accounting lined being generated. * @return A fully populated AccountingLine instance representing the amount of tax that will be applied to the * disbursement voucher provided. */ protected AccountingLine generateTaxAccountingLine(DisbursementVoucherDocument document, String chart, String account, String objectCode, KualiDecimal taxPercent, KualiDecimal taxableAmount) { AccountingLine taxLine = null; try { taxLine = (SourceAccountingLine) document.getSourceAccountingLineClass().newInstance(); } catch (IllegalAccessException e) { throw new IllegalArgumentException("unable to access sourceAccountingLineClass", e); } catch (InstantiationException e) { throw new IllegalArgumentException("unable to instantiate sourceAccountingLineClass", e); } taxLine.setDocumentNumber(document.getDocumentNumber()); taxLine.setSequenceNumber(document.getNextSourceLineNumber()); taxLine.setChartOfAccountsCode(chart); taxLine.setAccountNumber(account); taxLine.setFinancialObjectCode(objectCode); // calculate tax amount and set as line amount BigDecimal amount = taxableAmount.bigDecimalValue(); BigDecimal tax = taxPercent.bigDecimalValue(); BigDecimal taxDecimal = tax.divide(new BigDecimal(100), 5, BigDecimal.ROUND_HALF_UP); KualiDecimal taxAmount = new KualiDecimal( amount.multiply(taxDecimal).setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)); taxLine.setAmount(taxAmount.negated()); return taxLine; }
From source file:org.kuali.coeus.common.budget.impl.struts.BudgetExpensesAction.java
private void calculateBudgetFormulatedCost(BudgetFormulatedCostDetail budgetFormulatedCost) { BigDecimal unitCost = budgetFormulatedCost.getUnitCost().bigDecimalValue(); BigDecimal count = new ScaleTwoDecimal(budgetFormulatedCost.getCount()).bigDecimalValue(); BigDecimal frequency = new ScaleTwoDecimal(budgetFormulatedCost.getFrequency()).bigDecimalValue(); BigDecimal calculatedExpense = unitCost.multiply(count).multiply(frequency); budgetFormulatedCost.setCalculatedExpenses(new ScaleTwoDecimal(calculatedExpense)); }
From source file:org.kuali.kfs.fp.document.service.impl.DisbursementVoucherTaxServiceImpl.java
/** * Generates an accounting line for the chart, account, object code & tax percentage values given. * //from w ww.j a va2s . co m * @param document The disbursement voucher the tax will be applied to. * @param chart The chart code to be assigned to the accounting line generated. * @param account The account code to be assigned to the accounting line generated. * @param objectCode The object code used on the accounting line generated. * @param taxPercent The tax rate to be used to calculate the tax amount. * @param taxableAmount The total amount that is taxable. This amount is used in conjunction with the tax percent * to calculate the amount for the accounting lined being generated. * @return A fully populated AccountingLine instance representing the amount of tax that will be applied to the * disbursement voucher provided. */ protected AccountingLine generateTaxAccountingLine(DisbursementVoucherDocument document, String chart, String account, String objectCode, KualiDecimal taxPercent, KualiDecimal taxableAmount) { AccountingLine taxLine = null; try { taxLine = (SourceAccountingLine) document.getSourceAccountingLineClass().newInstance(); } catch (IllegalAccessException e) { throw new InfrastructureException("unable to access sourceAccountingLineClass", e); } catch (InstantiationException e) { throw new InfrastructureException("unable to instantiate sourceAccountingLineClass", e); } taxLine.setDocumentNumber(document.getDocumentNumber()); taxLine.setSequenceNumber(document.getNextSourceLineNumber()); taxLine.setChartOfAccountsCode(chart); taxLine.setAccountNumber(account); taxLine.setFinancialObjectCode(objectCode); // calculate tax amount and set as line amount BigDecimal amount = taxableAmount.bigDecimalValue(); BigDecimal tax = taxPercent.bigDecimalValue(); BigDecimal taxDecimal = tax.divide(new BigDecimal(100), 5, BigDecimal.ROUND_HALF_UP); KualiDecimal taxAmount = new KualiDecimal( amount.multiply(taxDecimal).setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)); taxLine.setAmount(taxAmount.negated()); return taxLine; }
From source file:org.codice.ddf.spatial.ogc.wfs.transformer.handlebars.HandlebarsWfsFeatureTransformer.java
private String convertToBytes(String value, String unit) { BigDecimal resourceSize = new BigDecimal(value); resourceSize = resourceSize.setScale(1, BigDecimal.ROUND_HALF_UP); switch (unit) { case B://from w w w . j ava 2 s . co m break; case KB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_KB)); break; case MB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_MB)); break; case GB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_GB)); break; case TB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_TB)); break; case PB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_PB)); break; default: break; } String resourceSizeAsString = resourceSize.toPlainString(); LOGGER.debug("resource size in bytes: {}", resourceSizeAsString); return resourceSizeAsString; }
From source file:com.salesmanager.core.module.impl.application.prices.OneTimePriceModule.java
public OrderTotalSummary calculateOrderPrice(Order order, OrderTotalSummary orderSummary, OrderProduct orderProduct, OrderProductPrice productPrice, String currency, Locale locale) { // TODO Auto-generated method stub /**//from ww w . j av a 2s.c o m * activation price goes in the oneTime fees */ BigDecimal finalPrice = null; // BigDecimal discountPrice=null; // order price this type of price needs an upfront payment BigDecimal otprice = orderSummary.getOneTimeSubTotal(); if (otprice == null) { otprice = new BigDecimal(0); } // the final price is in the product price finalPrice = productPrice.getProductPriceAmount(); int quantity = orderProduct.getProductQuantity(); finalPrice = finalPrice.multiply(new BigDecimal(quantity)); otprice = otprice.add(finalPrice); orderSummary.setOneTimeSubTotal(otprice); ProductPriceSpecial pps = productPrice.getSpecial(); // Build text StringBuffer notes = new StringBuffer(); notes.append(quantity).append(" x "); notes.append(orderProduct.getProductName()); notes.append(" "); notes.append( CurrencyUtil.displayFormatedAmountWithCurrency(productPrice.getProductPriceAmount(), currency)); notes.append(" "); notes.append(productPrice.getProductPriceName()); BigDecimal originalPrice = orderProduct.getOriginalProductPrice(); if (!productPrice.isDefaultPrice()) { originalPrice = productPrice.getProductPriceAmount(); } if (pps != null) { if (pps.getProductPriceSpecialStartDate() != null && pps.getProductPriceSpecialEndDate() != null) { if (pps.getProductPriceSpecialStartDate().before(order.getDatePurchased()) && pps.getProductPriceSpecialEndDate().after(order.getDatePurchased())) { BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue()); if (dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) { BigDecimal subTotal = originalPrice .multiply(new BigDecimal(orderProduct.getProductQuantity())); BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount() .multiply(new BigDecimal(orderProduct.getProductQuantity())); BigDecimal credit = subTotal.subtract(creditSubTotal); StringBuffer spacialNote = new StringBuffer(); spacialNote.append("<font color=\"red\">["); spacialNote.append(productPrice.getProductPriceName()); // spacialNote.append(getPriceText(currency,locale)); spacialNote.append(" "); spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency)); spacialNote.append("]</font>"); if (productPrice.getProductPriceAmount().doubleValue() > pps.getProductPriceSpecialAmount() .doubleValue()) { OrderTotalLine line = new OrderTotalLine(); line.setText(spacialNote.toString()); line.setCost(credit); line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency)); orderSummary.addDueNowCredits(line); BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge(); oneTimeCredit = oneTimeCredit.add(credit); orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit); } } } else if (pps.getProductPriceSpecialDurationDays() > -1) { Date dt = new Date(); int numDays = pps.getProductPriceSpecialDurationDays(); Date purchased = order.getDatePurchased(); Calendar c = Calendar.getInstance(); c.setTime(dt); c.add(Calendar.DATE, numDays); BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue()); if (dt.before(c.getTime()) && dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) { BigDecimal subTotal = originalPrice .multiply(new BigDecimal(orderProduct.getProductQuantity())); BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount() .multiply(new BigDecimal(orderProduct.getProductQuantity())); BigDecimal credit = subTotal.subtract(creditSubTotal); StringBuffer spacialNote = new StringBuffer(); spacialNote.append("<font color=\"red\">["); spacialNote.append(productPrice.getProductPriceName()); // spacialNote.append(getPriceText(currency,locale)); spacialNote.append(" "); spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency)); spacialNote.append("]</font>"); if (productPrice.getProductPriceAmount().doubleValue() > pps.getProductPriceSpecialAmount() .doubleValue()) { OrderTotalLine line = new OrderTotalLine(); line.setText(spacialNote.toString()); line.setCost(credit); line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency)); orderSummary.addDueNowCredits(line); BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge(); oneTimeCredit = oneTimeCredit.add(credit); orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit); } } } } } if (!productPrice.isDefaultPrice()) { // add a price description OrderTotalLine scl = new OrderTotalLine(); scl.setText(notes.toString()); scl.setCost(finalPrice); scl.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency)); orderSummary.addOtherDueNowPrice(scl); } return orderSummary; }
From source file:it.av.es.service.impl.OrderServiceHibernate.java
/** * {@inheritDoc}/*from ww w. j a v a 2 s . c om*/ */ @Override public Order forcePriceAndDiscountAndRecalculate(Order o, BigDecimal cost, BigDecimal discountForced) { for (ProductOrdered p : o.getProductsOrdered()) { p.setAmount(cost.multiply(BigDecimal.valueOf(p.getNumber()))); p.setDiscount(discountForced.intValue()); } return o; }
From source file:com.xumpy.timesheets.services.TickedJobsDetailSrv.java
@Transactional(value = "transactionManager") public Map<JobsGroupSrvPojo, Map<String, String>> tickedOverviewMonth(String month) throws ParseException { List<? extends Jobs> jobs = jobsDao.selectPeriode(CustomDateUtils.getFirstDayOfMonth(month), CustomDateUtils.getLastDayOfMonth(month)); List<JobsGroup> jobsGroups = new ArrayList<JobsGroup>(); for (Jobs job : jobs) { if (!jobsGroups.contains(job.getJobsGroup())) { jobsGroups.add(job.getJobsGroup()); }/* w w w . j ava 2s .c o m*/ } Map<JobsGroupSrvPojo, Map<String, String>> returnMap = new HashMap<JobsGroupSrvPojo, Map<String, String>>(); for (JobsGroup jobsGroup : jobsGroups) { BigDecimal actualWorked = new BigDecimal(0); BigDecimal timesheetWorked = new BigDecimal(0); Map worked = new HashMap<String, String>(); for (Jobs job : jobs) { if (jobsGroup.getPk_id().equals(job.getJobsGroup().getPk_id())) { List<? extends TickedJobs> tickedJobs = tickedJobsDao.selectTickedJobsByJob(job.getPk_id()); TickedJobsDetail jobsDetail = calculate(tickedJobs, new BigDecimal(30)); timesheetWorked = timesheetWorked.add(job.getWorkedHours()); actualWorked = actualWorked.add(jobsDetail.getActualWorked()); } } worked.put("actualWorked", actualWorked.toString()); worked.put("timesheetWorked", timesheetWorked.multiply(new BigDecimal(60)).toString()); returnMap.put(new JobsGroupSrvPojo(jobsGroup), worked); } return returnMap; }
From source file:org.openbravo.financial.FinancialUtils.java
/** * Converts an amount.//from w ww . jav a 2 s . co m * * @param amount * BigDecimal amount to convert. * @param curFrom * Currency to convert from. * @param curTo * Currency to convert to. * @param date * Date conversion is being performed. * @param org * Organization of the document that needs to be converted. * @param strPrecision * type of precision to be used to round the converted amount. * @param rateDocs * list of conversion rates defined on the document of the amount that needs to be * converted. * @return a BigDecimal representing the converted amount. * @throws OBException * when no Conversion Rate is found for the given parameters. */ public static BigDecimal getConvertedAmount(BigDecimal amount, Currency curFrom, Currency curTo, Date date, Organization org, String strPrecision, List<ConversionRateDoc> rateDocs) throws OBException { Check.isNotNull(rateDocs, OBMessageUtils.messageBD("ParameterMissing") + " (rateDocs)"); if (curFrom.getId().equals(curTo.getId()) || amount.signum() == 0) { return amount; } BigDecimal rate = null; if (rateDocs.size() > 0) { for (ConversionRateDoc rateDoc : rateDocs) { if (curFrom.getId().equals(rateDoc.getCurrency().getId()) && curTo.getId().equals(rateDoc.getToCurrency().getId())) { rate = rateDoc.getRate(); break; } } } if (rate == null) { ConversionRate cr = getConversionRate(date, curFrom, curTo, org, org.getClient()); if (cr == null) { throw new OBException("@NoCurrencyConversion@ " + curFrom.getISOCode() + " @to@ " + curTo.getISOCode() + " @ForDate@ " + OBDateUtils.formatDate(date) + " @And@ @ACCS_AD_ORG_ID_D@ " + org.getIdentifier()); } rate = cr.getMultipleRateBy(); } Long precision = curTo.getStandardPrecision(); if (PRECISION_COSTING.equals(strPrecision)) { precision = curTo.getCostingPrecision(); } else if (PRECISION_PRICE.equals(strPrecision)) { precision = curTo.getPricePrecision(); } return amount.multiply(rate).setScale(precision.intValue(), RoundingMode.HALF_UP); }
From source file:org.fede.calculator.IndexTest.java
public void youIndexARS() { MoneyAmountSeries dollar = Util.readSeries("ahorros-dolar.json"); MoneyAmountSeries gold = Util.readSeries("ahorros-oro.json"); MoneyAmountSeries peso = Util.readSeries("ahorros-peso.json"); final String target = "USD"; MoneyAmountSeries proportionInUSD = new SortedMapMoneyAmountSeries("USD"); YearMonth start = dollar.getFrom().min(gold.getFrom()); final YearMonth end = dollar.getTo().max(gold.getTo()); final MoneyAmount oneUSD = new MoneyAmount(BigDecimal.ONE, "USD"); final MoneyAmount oneARS = getForeignExchange(oneUSD.getCurrency(), "ARS").exchange(oneUSD, "ARS", start.getYear(), start.getMonth()); final MoneyAmount oneXAU = getForeignExchange(oneUSD.getCurrency(), "XAU").exchange(oneUSD, "XAU", start.getYear(), start.getMonth()); while (start.compareTo(end) <= 0) { MoneyAmount usdSavings = dollar.getAmountOrElseZero(start); MoneyAmount arsSavings = peso.getAmountOrElseZero(start); MoneyAmount xauSavings = gold.getAmountOrElseZero(start); usdSavings = getForeignExchange(usdSavings.getCurrency(), target).exchange(usdSavings, target, start.getYear(), start.getMonth()); xauSavings = getForeignExchange(xauSavings.getCurrency(), target).exchange(xauSavings, target, start.getYear(), start.getMonth()); arsSavings = getForeignExchange(arsSavings.getCurrency(), target).exchange(arsSavings, target, start.getYear(), start.getMonth()); final MoneyAmount totalSavings = usdSavings.add(xauSavings).add(arsSavings); if (totalSavings.getAmount().signum() > 0) { BigDecimal usdSavingsPercent = usdSavings.getAmount().divide(totalSavings.getAmount(), MathContext.DECIMAL128); BigDecimal arsSavingsPercent = arsSavings.getAmount().divide(totalSavings.getAmount(), MathContext.DECIMAL128); BigDecimal xauSavingsPercent = xauSavings.getAmount().divide(totalSavings.getAmount(), MathContext.DECIMAL128); System.out.print(MessageFormat.format("{0}{1}\t{2}\t{3}\t{4}\t", String.valueOf(start.getYear()), start.getMonth(), usdSavingsPercent, arsSavingsPercent, xauSavingsPercent)); BigDecimal usdPrice = getForeignExchange(oneUSD.getCurrency(), target) .exchange(oneUSD, target, start.getYear(), start.getMonth()).getAmount(); BigDecimal arsPrice = getForeignExchange(oneARS.getCurrency(), target) .exchange(oneARS, target, start.getYear(), start.getMonth()).getAmount(); BigDecimal xauPrice = getForeignExchange(oneXAU.getCurrency(), target) .exchange(oneXAU, target, start.getYear(), start.getMonth()).getAmount(); System.out.print(MessageFormat.format("{0}\t{1}\t{2}\t", usdPrice, arsPrice, xauPrice)); BigDecimal youIndex = usdPrice.multiply(usdSavingsPercent).add(arsPrice.multiply(arsSavingsPercent)) .add(xauPrice.multiply(xauSavingsPercent)); // final MoneyAmount index = new MoneyAmount(youIndex, target); //BigDecimal adjustedYouIndex = USD_INFLATION.adjust(index, start.getYear(), start.getMonth(), // USD_INFLATION.getTo().getYear(), USD_INFLATION.getTo().getMonth()).getAmount(); // System.out.println(MessageFormat.format("{0}\t{1}", youIndex, adjustedYouIndex)); proportionInUSD.putAmount(start, new MoneyAmount(youIndex, target)); }// w w w.j a v a 2s. co m start = start.next(); } //proportionInUSD.forEach(new MoneyAmountProcessor() { // @Override // public void process(int year, int month, MoneyAmount amount) throws NoSeriesDataFoundException { //System.out.println(MessageFormat.format("{0}{1}\t{2}", String.valueOf(year), month, amount.getAmount())); //} //}); }