Example usage for java.math BigDecimal multiply

List of usage examples for java.math BigDecimal multiply

Introduction

In this page you can find the example usage for java.math BigDecimal multiply.

Prototype

public BigDecimal multiply(BigDecimal multiplicand) 

Source Link

Document

Returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()) .

Usage

From source file:egovframework.rte.fdl.idgnr.impl.EgovUUIdGnrService.java

/**
 * BigDecimal ? ? //from  ww w .j  a va 2s. com
 * @return BigDecimal  ID
 * @throws FdlException
 *         ? ??  
 */
public BigDecimal getNextBigDecimalId() throws FdlException {
    String newId = getNextStringId();
    byte[] bytes = newId.getBytes(); // get 16
    // bytes
    BigDecimal bd = new BigDecimal(0);

    for (int i = 0; i < bytes.length; i++) {
        bd = bd.multiply(new BigDecimal(256));
        bd = bd.add(new BigDecimal(((int) bytes[i]) & 0xFF));
    }

    return bd;
}

From source file:org.egov.ptis.actions.citizen.collection.CollectionAction.java

/**
 * @return/*  w  w  w .  j a  v  a  2  s.  c o m*/
 */
@Action(value = "/collection-generateBill")
public String generateBill() {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Entered method generatePropertyTaxBill, assessment Number: " + assessmentNumber);

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("generatePropertyTaxBill : BasicProperty :" + basicProperty);
    final Map<String, BigDecimal> demandCollMap = propertyTaxUtil
            .getDemandAndCollection(basicProperty.getProperty());
    final BigDecimal currDue = demandCollMap.get(CURR_DMD_STR).subtract(demandCollMap.get(CURR_COLL_STR));
    final BigDecimal arrDue = demandCollMap.get(ARR_DMD_STR).subtract(demandCollMap.get(ARR_COLL_STR));
    /*
     * Advance collection should also be considered for full payment validation. 
     * Current year second installment demand will be the demand for all the advance installments
     */
    BigDecimal advanceCollected = demandCollMap.get(ADVANCE_COLLECTION_STR);
    BigDecimal secondHalfTax = demandCollMap.get(CURR_SECONDHALF_DMD_STR);
    BigDecimal actualAdvanceToBeCollected = secondHalfTax.multiply(new BigDecimal(MAX_ADVANCES_ALLOWED));
    BigDecimal advanceBalance = actualAdvanceToBeCollected.subtract(advanceCollected);

    if (currDue.compareTo(BigDecimal.ZERO) <= 0 && arrDue.compareTo(BigDecimal.ZERO) <= 0
            && advanceBalance.compareTo(BigDecimal.ZERO) <= 0)
        return RESULT_TAXPAID;

    if (OWNERSHIP_TYPE_VAC_LAND
            .equals(basicProperty.getProperty().getPropertyDetail().getPropertyTypeMaster().getCode())) {
        propertyTaxBillable.setVacantLandTaxPayment(Boolean.TRUE);
    }
    propertyTaxBillable.setBasicProperty(basicProperty);
    propertyTaxBillable.setLevyPenalty(true);
    propertyTaxBillable.setReferenceNumber(propertyTaxNumberGenerator
            .generateBillNumber(basicProperty.getPropertyID().getWard().getBoundaryNum().toString()));
    propertyTaxBillable.setBillType(propertyTaxUtil.getBillTypeByCode(BILLTYPE_AUTO));
    try {
        collectXML = URLEncoder.encode(ptBillServiceImpl.getBillXML(propertyTaxBillable), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage());
    }
    if (LOGGER.isDebugEnabled())
        LOGGER.info("Exiting method generatePropertyTaxBill, collectXML: " + collectXML);

    return RESULT_COLLECTTAX;
}

From source file:org.libreplan.business.planner.entities.SigmoidFunction.java

private BigDecimal[] generatePointValuesForDays(int days) {
    final BigDecimal dayIntervalConstant = getDayIntervalConstant(days);

    BigDecimal[] result = new BigDecimal[days];
    for (int i = 0; i < days; i++) {
        result[i] = BigDecimal.valueOf(-6).add(dayIntervalConstant.multiply(BigDecimal.valueOf(i)));
    }/*from  w ww  . j  a v  a 2 s .  c  om*/
    return result;
}

From source file:io.silverware.microservices.monitoring.MetricsManager.java

/**
 * Method responsible for adding new time to values collection and also updating min, max, avg and count metrics.
 *
 * @param elapsedTime/*from   ww  w .  j a  v  a  2 s  . c  om*/
 *       runtime of microservice method.
 */
public void addTime(BigDecimal elapsedTime) {

    if (elapsedTime.compareTo(BigDecimal.ZERO) <= 0) {
        throw new IllegalArgumentException("Elapsed time is negative or zero");
    }

    mapValues.put(longAdder.longValue(), elapsedTime);

    longAdder.increment();

    final BigDecimal count = new BigDecimal(metrics.getCount());
    final BigDecimal averageTime = metrics.getAverageTime();
    final BigDecimal minTime = metrics.getMinTime();
    final BigDecimal maxTime = metrics.getMaxTime();

    metrics.incrementCount();

    metrics.setAverageTime((averageTime.multiply(count).add(elapsedTime)).divide(count.add(BigDecimal.ONE),
            BigDecimal.ROUND_HALF_UP));

    if (elapsedTime.compareTo(maxTime) >= 1) {
        metrics.setMaxTime(elapsedTime);
    } else {
        metrics.setMinTime(elapsedTime);
    }
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.PolygonZone.java

public PolarCoordinate getCenterOfGravity() {
    BigDecimal x = new BigDecimal(0), y = new BigDecimal(0);
    BigDecimal doubleArea = new BigDecimal(0);

    for (int k = 0, l = vertices.length - 1; k < l; ++k) {
        BigDecimal ax = new BigDecimal(vertices[k].x);
        BigDecimal ay = new BigDecimal(vertices[k].y);
        BigDecimal bx = new BigDecimal(vertices[k + 1].x);
        BigDecimal by = new BigDecimal(vertices[k + 1].y);
        BigDecimal t = ax.multiply(by).subtract(bx.multiply(ay));
        x = x.add(ax.add(bx).multiply(t));
        y = y.add(ay.add(by).multiply(t));
        doubleArea = doubleArea.add(ax.multiply(by).subtract(bx.multiply(ay)));
    }//from  ww w . j av a 2 s  .  c om

    double sixTimesArea = 3.0 * doubleArea.doubleValue();
    return new PolarCoordinate(x.doubleValue() / sixTimesArea, y.doubleValue() / sixTimesArea, 0);
}

From source file:org.marketcetera.core.position.impl.PositionMetricsCalculatorImpl.java

/**
 * Processes a position close, updating realized P&L and the unrealized cost
 * //from  w ww  . j  a  va2  s  .  co  m
 * @param quantity
 *            the quantity being closed, negative when closing a long position and positive when
 *            closing a short position
 * @param openPrice
 *            the price at which the position was opened
 * @param closePrice
 *            the price at which the position is closing
 */
private void processClose(final BigDecimal quantity, final BigDecimal openPrice, final BigDecimal closePrice) {
    // subtract closePrice from openPrice since quantity has opposite sign
    // more readable may be:
    // quantity.negate().multiply(closePrice.subtract(openPrice))
    mRealizedPL = mRealizedPL.add(quantity.multiply(openPrice.subtract(closePrice)));
    mUnrealizedCost.add(quantity, openPrice);
}

From source file:com.trenako.entities.Scale.java

/**
 * Sets the {@code Scale} ratio from a {@link java.math.BigDecimal}
 * value.//from  www  .  j av a 2 s . com
 *
 * @param ratio the {@code Scale} ratio
 */
public void setRatio(BigDecimal ratio) {
    this.ratio = ratio.multiply(RATIO_FACTOR).intValue();
}

From source file:org.kuali.ole.select.document.web.struts.OleDisbursementVoucherAction.java

/**
 * This action executes an insert of a SourceAccountingLine into a document only after validating the accounting line and
 * checking any appropriate business rules.
 *
 * @param mapping/*w ww.j  a  va 2s. com*/
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
@Override
public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    OleDisbursementVoucherForm disbursementVoucherForm = (OleDisbursementVoucherForm) form;
    OleDisbursementVoucherDocument disbursementDocument = disbursementVoucherForm
            .getDisbursementVoucherDocument();
    OleDisbursementVoucherAccountingLine line = (OleDisbursementVoucherAccountingLine) disbursementVoucherForm
            .getNewSourceLine();
    KualiDecimal totalAmount = disbursementDocument.getDisbVchrCheckTotalAmount();
    if ((totalAmount != null) && KualiDecimal.ZERO.compareTo(totalAmount) != 0) {
        if (ObjectUtils.isNotNull(line.getAccountLinePercent())) {
            BigDecimal pct = new BigDecimal(line.getAccountLinePercent().toString())
                    .divide(new BigDecimal(100));
            line.setAmount(new KualiDecimal(pct.multiply(new BigDecimal(totalAmount.toString()))
                    .setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
        } else if (ObjectUtils.isNotNull(line.getAmount())
                && ObjectUtils.isNull(line.getAccountLinePercent())) {
            KualiDecimal dollar = line.getAmount().multiply(new KualiDecimal(100));
            BigDecimal dollarToPercent = dollar.bigDecimalValue().divide((totalAmount.bigDecimalValue()), 0,
                    RoundingMode.FLOOR);
            line.setAccountLinePercent(dollarToPercent);
        }
    }
    return super.insertSourceLine(mapping, disbursementVoucherForm, request, response);
}

From source file:com.autentia.tnt.businessobject.Project.java

public BigDecimal getTotalCost() {
    BigDecimal ret = new BigDecimal(0);

    if (getCosts() != null) {
        for (ProjectCost cost : getCosts()) {
            BigDecimal c = cost.getCost();
            if (c != null) {
                ret = ret.add(c);//from w ww  . jav  a 2 s .c  om
            }
        }
    }
    if (getRoles() != null) {
        for (ProjectRole role : getRoles()) {
            BigDecimal cph = role.getCostPerHour();
            if (cph != null) {
                BigDecimal eh = new BigDecimal(role.getExpectedHours());
                ret = ret.add(cph.multiply(eh));
            }
        }
    }

    return ret;
}

From source file:org.kuali.ole.select.document.web.struts.OleDisbursementVoucherAction.java

private void updateAccountAmountsWithTotal(List<OleDisbursementVoucherAccountingLine> sourceAccountingLines,
        KualiDecimal totalAmount) {//from  w w w . j a v  a2 s  .c o m
    if ((totalAmount != null) && KualiDecimal.ZERO.compareTo(totalAmount) != 0) {

        KualiDecimal accountTotal = KualiDecimal.ZERO;
        OleDisbursementVoucherAccountingLine lastAccount = null;

        for (OleDisbursementVoucherAccountingLine account : sourceAccountingLines) {
            if (ObjectUtils.isNotNull(account.getAccountLinePercent())) {
                BigDecimal pct = new BigDecimal(account.getAccountLinePercent().toString())
                        .divide(new BigDecimal(100));
                account.setAmount(new KualiDecimal(pct.multiply(new BigDecimal(totalAmount.toString()))
                        .setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
            } else if (ObjectUtils.isNotNull(account.getAmount())
                    && ObjectUtils.isNull(account.getAccountLinePercent())) {
                KualiDecimal dollar = account.getAmount().multiply(new KualiDecimal(100));
                BigDecimal dollarToPercent = dollar.bigDecimalValue().divide((totalAmount.bigDecimalValue()), 0,
                        RoundingMode.FLOOR);
                account.setAccountLinePercent(dollarToPercent);
            }
            accountTotal = accountTotal.add(account.getAmount());
            lastAccount = account;
        }
    }
}