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:org.esupportail.papercut.webportlet.EsupPapercutPortletController.java

@RequestMapping
public ModelAndView renderView(RenderRequest request, RenderResponse response) {

    ModelMap model = new ModelMap();

    model.put("htmlHeader", request.getPreferences().getValue("htmlHeader", ""));
    model.put("htmlFooter", request.getPreferences().getValue("htmlFooter", ""));
    model.put("payboxMontantMin", request.getPreferences().getValue("payboxMontantMin", "0.5"));
    model.put("payboxMontantMax", request.getPreferences().getValue("payboxMontantMax", "5.0"));
    model.put("payboxMontantStep", request.getPreferences().getValue("payboxMontantStep", "0.5"));
    model.put("payboxMontantDefaut", request.getPreferences().getValue("payboxMontantDefaut", "2.0"));

    double papercutSheetCost = Double.parseDouble(request.getPreferences().getValue("papercutSheetCost", "-1"));
    double papercutColorSheetCost = Double
            .parseDouble(request.getPreferences().getValue("papercutColorSheetCost", "-1"));

    String paperCutContext = request.getPreferences().getValue(PREF_PAPERCUT_CONTEXT, null);
    EsupPaperCutService esupPaperCutService = esupPaperCutServices.get(paperCutContext);

    String uid = getUid(request);
    String userMail = getUserMail(request);

    // check if the user can make a transaction
    int transactionNbMax = Integer.parseInt(request.getPreferences().getValue("transactionNbMax", "-1"));
    BigDecimal transactionMontantMax = new BigDecimal(
            request.getPreferences().getValue("transactionMontantMax", "-1"));
    boolean canMakeTransaction = true;

    // constraints via transactionNbMax
    if (transactionNbMax > -1) {
        long nbTransactionsNotArchived = PayboxPapercutTransactionLog
                .countFindPayboxPapercutTransactionLogsByUidEqualsAndPaperCutContextEqualsAndArchived(uid,
                        paperCutContext, false);
        if (transactionNbMax <= nbTransactionsNotArchived) {
            canMakeTransaction = false;/* ww w .j  ava  2 s .c o  m*/
        }
    }

    BigDecimal payboxMontantMin = new BigDecimal(request.getPreferences().getValue("payboxMontantMin", "0.5"));
    BigDecimal payboxMontantMax = new BigDecimal(request.getPreferences().getValue("payboxMontantMax", "5.0"));
    BigDecimal payboxMontantStep = new BigDecimal(
            request.getPreferences().getValue("payboxMontantStep", "0.5"));
    BigDecimal payboxMontantDefaut = new BigDecimal(
            request.getPreferences().getValue("payboxMontantDefaut", "2.0"));
    // constraints on the slider via transactionMontantMax
    if (canMakeTransaction && transactionMontantMax.intValue() > -1) {
        List<PayboxPapercutTransactionLog> transactionsNotArchived = PayboxPapercutTransactionLog
                .findPayboxPapercutTransactionLogsByUidEqualsAndPaperCutContextEqualsAndArchived(uid,
                        paperCutContext, false)
                .getResultList();
        BigDecimal montantTotalTransactionsNotArchived = new BigDecimal("0");
        for (PayboxPapercutTransactionLog txLog : transactionsNotArchived) {
            montantTotalTransactionsNotArchived = montantTotalTransactionsNotArchived
                    .add(new BigDecimal(txLog.getMontant()));
        }
        transactionMontantMax = transactionMontantMax.multiply(new BigDecimal("100"))
                .subtract(montantTotalTransactionsNotArchived);
        if (transactionMontantMax.doubleValue() < payboxMontantMax.doubleValue() * 100) {
            payboxMontantMax = transactionMontantMax.divide(payboxMontantStep).multiply(payboxMontantStep);
            payboxMontantMax = payboxMontantMax.divide(new BigDecimal("100"));
            if (payboxMontantDefaut.compareTo(payboxMontantMax) == 1) {
                payboxMontantDefaut = payboxMontantMax;
            }
            if (payboxMontantMax.compareTo(payboxMontantMin) == -1) {
                canMakeTransaction = false;
            }
            model.put("payboxMontantMax", payboxMontantMax.doubleValue());
            model.put("payboxMontantDefaut", payboxMontantDefaut.doubleValue());
        }
    }

    // generation de l'ensemble des payboxForm :  payboxMontantMin -> payboxMontantMax par pas de payboxMontantStep
    String portletContextPath = ((RenderResponse) response).createRenderURL().toString();
    Map<Integer, PayBoxForm> payboxForms = new HashMap<Integer, PayBoxForm>();
    for (BigDecimal montant = payboxMontantMin; montant.compareTo(payboxMontantMax) <= 0; montant = montant
            .add(payboxMontantStep)) {
        PayBoxForm payBoxForm = esupPaperCutService.getPayBoxForm(uid, userMail, montant.doubleValue(),
                paperCutContext, portletContextPath);
        if (papercutSheetCost > 0) {
            int nbSheets = (int) (montant.doubleValue() / papercutSheetCost);
            payBoxForm.setNbSheets(nbSheets);
        }
        if (papercutColorSheetCost > 0) {
            int nbColorSheets = (int) (montant.doubleValue() / papercutColorSheetCost);
            payBoxForm.setNbColorSheets(nbColorSheets);
        }

        payboxForms.put(montant.multiply(new BigDecimal(100)).intValue(), payBoxForm);
    }
    Map<Integer, PayBoxForm> sortedMap = new TreeMap<Integer, PayBoxForm>(payboxForms);

    model.put("payboxForms", sortedMap);
    model.put("payboxMontantDefautCents", payboxMontantDefaut.multiply(new BigDecimal(100)).intValue());

    model.put("canMakeTransaction", canMakeTransaction);

    UserPapercutInfos userPapercutInfos = esupPaperCutService.getUserPapercutInfos(uid);
    model.put("userPapercutInfos", userPapercutInfos);

    boolean isAdmin = isAdmin(request);
    boolean isManager = isManager(request);
    model.put("isAdmin", isAdmin);
    model.put("isManager", isManager);
    model.put("active", "home");
    return new ModelAndView(getViewName(request, "index"), model);
}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * The inverse trigonometric sine.//from   w  ww .ja  v  a  2s.co  m
 *
 * @param x the argument.
 * @return the arcsin(x) in radians.
 */
static public BigDecimal asin(final BigDecimal x) {
    if (x.compareTo(BigDecimal.ONE) > 0 || x.compareTo(BigDecimal.ONE.negate()) < 0) {
        throw new ArithmeticException("Out of range argument " + x.toString() + " of asin");

    } else if (x.compareTo(BigDecimal.ZERO) == 0) {
        return BigDecimal.ZERO;
    } else if (x.compareTo(BigDecimal.ONE) == 0) {
        /* arcsin(1) = pi/2
         */
        double errpi = Math.sqrt(x.ulp().doubleValue());
        MathContext mc = new MathContext(err2prec(3.14159, errpi));

        return pi(mc).divide(new BigDecimal(2));

    } else if (x.compareTo(BigDecimal.ZERO) < 0) {
        return asin(x.negate()).negate();

    } else if (x.doubleValue() > 0.7) {
        final BigDecimal xCompl = BigDecimal.ONE.subtract(x);
        final double xDbl = x.doubleValue();
        final double xUlpDbl = x.ulp().doubleValue() / 2.;
        final double eps = xUlpDbl / 2. / Math.sqrt(1. - Math.pow(xDbl, 2.));

        final BigDecimal xhighpr = scalePrec(xCompl, 3);
        final BigDecimal xhighprV = divideRound(xhighpr, 4);
        BigDecimal resul = BigDecimal.ONE;
        /* x^(2i+1) */
        BigDecimal xpowi = BigDecimal.ONE;
        /* i factorial */
        BigInteger ifacN = BigInteger.ONE;
        BigInteger ifacD = BigInteger.ONE;

        for (int i = 1;; i++) {
            ifacN = ifacN.multiply(new BigInteger("" + (2 * i - 1)));
            ifacD = ifacD.multiply(new BigInteger("" + i));

            if (i == 1) {
                xpowi = xhighprV;
            } else {
                xpowi = multiplyRound(xpowi, xhighprV);
            }
            BigDecimal c = divideRound(multiplyRound(xpowi, ifacN),
                    ifacD.multiply(new BigInteger("" + (2 * i + 1))));
            resul = resul.add(c);
            /* series started 1+x/12+... which yields an estimate of the sums error
             */

            if (Math.abs(c.doubleValue()) < xUlpDbl / 120.) {
                break;
            }

        }
        /* sqrt(2*z)*(1+...)
         */
        xpowi = sqrt(xhighpr.multiply(new BigDecimal(2)));
        resul = multiplyRound(xpowi, resul);
        MathContext mc = new MathContext(resul.precision());
        BigDecimal pihalf = pi(mc).divide(new BigDecimal(2));
        mc = new MathContext(err2prec(resul.doubleValue(), eps));

        return pihalf.subtract(resul, mc);

    } else {
        /* absolute error in the result is err(x)/sqrt(1-x^2) to lowest order
         */
        final double xDbl = x.doubleValue();
        final double xUlpDbl = x.ulp().doubleValue() / 2.;
        final double eps = xUlpDbl / 2. / Math.sqrt(1. - Math.pow(xDbl, 2.));
        final BigDecimal xhighpr = scalePrec(x, 2);
        final BigDecimal xhighprSq = multiplyRound(xhighpr, xhighpr);
        BigDecimal resul = xhighpr.plus();
        /* x^(2i+1) */
        BigDecimal xpowi = xhighpr;
        /* i factorial */
        BigInteger ifacN = BigInteger.ONE;
        BigInteger ifacD = BigInteger.ONE;

        for (int i = 1;; i++) {
            ifacN = ifacN.multiply(new BigInteger("" + (2 * i - 1)));
            ifacD = ifacD.multiply(new BigInteger("" + (2 * i)));
            xpowi = multiplyRound(xpowi, xhighprSq);
            BigDecimal c = divideRound(multiplyRound(xpowi, ifacN),
                    ifacD.multiply(new BigInteger("" + (2 * i + 1))));
            resul = resul.add(c);

            if (Math.abs(c.doubleValue()) < 0.1 * eps) {
                break;
            }

        }
        MathContext mc = new MathContext(err2prec(resul.doubleValue(), eps));

        return resul.round(mc);

    }
}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * The hyperbolic cosine./*from   ww w.  j a  v  a  2  s.  c o m*/
 *
 * @param x The argument.
 * @return The cosh(x) = (exp(x)+exp(-x))/2 .
 */
static public BigDecimal cosh(final BigDecimal x) {
    if (x.compareTo(BigDecimal.ZERO) < 0) {
        return cos(x.negate());
    } else if (x.compareTo(BigDecimal.ZERO) == 0) {
        return BigDecimal.ONE;
    } else {
        if (x.doubleValue() > 1.5) {
            /* cosh^2(x) = 1+ sinh^2(x).
             */
            return hypot(1, sinh(x));

        } else {
            BigDecimal xhighpr = scalePrec(x, 2);
            /* Simple Taylor expansion, sum_{0=1..infinity} x^(2i)/(2i)! */
            BigDecimal resul = BigDecimal.ONE;
            /* x^i */
            BigDecimal xpowi = BigDecimal.ONE;
            /* 2i factorial */
            BigInteger ifac = BigInteger.ONE;
            /* The absolute error in the result is the error in x^2/2 which is x times the error in x.
             */

            double xUlpDbl = 0.5 * x.ulp().doubleValue() * x.doubleValue();
            /* The error in the result is set by the error in x^2/2 itself, xUlpDbl.
             * We need at most k terms to push x^(2k)/(2k)! below this value.
             * x^(2k) < xUlpDbl; (2k)*log(x) < log(xUlpDbl);
             */

            int k = (int) (Math.log(xUlpDbl) / Math.log(x.doubleValue())) / 2;
            /* The individual terms are all smaller than 1, so an estimate of 1.0 for
             * the absolute value will give a safe relative error estimate for the indivdual terms
             */
            MathContext mcTay = new MathContext(err2prec(1., xUlpDbl / k));

            for (int i = 1;; i++) {
                /* TBD: at which precision will 2*i-1 or 2*i overflow?
                 */
                ifac = ifac.multiply(new BigInteger("" + (2 * i - 1)));
                ifac = ifac.multiply(new BigInteger("" + (2 * i)));
                xpowi = xpowi.multiply(xhighpr).multiply(xhighpr);
                BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
                resul = resul.add(corr);

                if (corr.abs().doubleValue() < 0.5 * xUlpDbl) {
                    break;
                }

            } /* The error in the result is governed by the error in x itself.
              */
            MathContext mc = new MathContext(err2prec(resul.doubleValue(), xUlpDbl));

            return resul.round(mc);

        }
    }
}

From source file:org.kuali.ole.select.document.service.impl.OlePaymentRequestServiceImpl.java

/**
 * This method is for caluclate the total amount without select proprate by Quantity,doller and manual
 *
 * @see org.kuali.ole.select.document.service.OlePaymentRequestService#calculateWithoutProrates(org.kuali.ole.select.document.OlePaymentRequestDocument)
 *///from w w w  . j  ava  2  s  .com
@Override
public void calculateWithoutProrates(OlePaymentRequestDocument paymentRequestDocument) {
    LOG.debug("Inside Calculation for with out  prorate");
    BigDecimal addChargeItem = BigDecimal.ZERO;
    List<OlePaymentRequestItem> items = paymentRequestDocument.getItems();

    for (OlePaymentRequestItem item : items) {
        if (item.getItemTitleId() != null && !"".equals(item.getItemTitleId())) {
            if (!item.getItemListPrice().equals(item.getExtendedPrice())) {
                item.setItemUnitPrice(item.getItemListPrice().bigDecimalValue());
                item.setExtendedPrice(item.getItemListPrice());
                item.setItemSurcharge(BigDecimal.ZERO);
            }
        }
    }

    for (OlePaymentRequestItem item : items) {
        if (!item.getItemType().isQuantityBasedGeneralLedgerIndicator()
                && !item.getItemTypeCode()
                        .equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE)
                && item.getItemUnitPrice() != null) {
            addChargeItem = addChargeItem.add(item.getItemUnitPrice());
        }
    }
    List<BigDecimal> newUnitPriceList = new ArrayList<BigDecimal>();
    BigDecimal totalExtPrice = new BigDecimal(0);
    BigDecimal newUnitPrice = new BigDecimal(0);
    BigDecimal extPrice = new BigDecimal(0);
    BigDecimal unitPricePercent = new BigDecimal(0);
    BigDecimal hundred = new BigDecimal(100);
    BigDecimal one = new BigDecimal(1);
    BigDecimal totalSurCharge = new BigDecimal(0);
    BigDecimal totalItemQuantity = new BigDecimal(0);
    BigDecimal itemSurchargeCons = new BigDecimal(0);
    for (int i = 0; items.size() > i; i++) {
        OlePaymentRequestItem item = (OlePaymentRequestItem) paymentRequestDocument.getItem(i);
        if ((item.getItemType().isQuantityBasedGeneralLedgerIndicator())
                && !ObjectUtils.isNull(item.getItemQuantity())) {
            if (item.getItemSurcharge() == null) {
                item.setItemSurcharge(BigDecimal.ZERO);
            }
            if (paymentRequestDocument.getProrateBy() == null) {
                if (item.getItemDiscount() == null) {
                    item.setItemDiscount(KualiDecimal.ZERO);
                }
                if (item.getItemDiscountType() != null && item.getItemDiscountType()
                        .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
                    newUnitPrice = SpringContext.getBean(OlePurapService.class).calculateDiscount(item)
                            .setScale(2, BigDecimal.ROUND_HALF_UP);
                } else {
                    newUnitPrice = SpringContext.getBean(OlePurapService.class).calculateDiscount(item)
                            .setScale(2, BigDecimal.ROUND_HALF_UP);
                }
                newUnitPriceList.add(newUnitPrice);
                extPrice = newUnitPrice.multiply(item.getItemQuantity().bigDecimalValue());
                totalExtPrice = totalExtPrice.add(extPrice);
            }
            totalSurCharge = totalSurCharge
                    .add(item.getItemQuantity().bigDecimalValue().multiply(item.getItemSurcharge()));
        }
    }
    for (int i = 0, j = 0; items.size() > i; i++) {
        OlePaymentRequestItem item = (OlePaymentRequestItem) paymentRequestDocument.getItem(i);
        if (item.getItemType().isQuantityBasedGeneralLedgerIndicator() && newUnitPriceList.size() > j
                && !ObjectUtils.isNull(item.getItemQuantity())) {
            if (item.getItemSurcharge() != null) {
                item.setItemUnitPrice(newUnitPriceList.get(j).add(item.getItemSurcharge()));
            }
            j++;
        }
    }

    LOG.debug("Leaving Calculation for with out  prorate");
}

From source file:org.kuali.kfs.module.endow.document.service.impl.CurrentTaxLotServiceImpl.java

/**
 * calculates the remainder of fiscal year estimated income for pooled funds
 * /*from www .jav a 2  s .c  o  m*/
 * @param security
 * @param holdingTaxLot
 * @return amount
 */
protected BigDecimal getRemainderOfFiscalYearEstimatedIncomeForPooledFunds(Security security,
        HoldingTaxLot holdingTaxLot) {
    BigDecimal amount = BigDecimal.ZERO;

    if (ObjectUtils.isNull(security.getIncomeNextPayDate())
            || ObjectUtils.isNull(security.getFrequencyCode())) {
        return amount;
    }

    Date nextIncomeDueDate = security.getIncomeNextPayDate();
    if (ObjectUtils.isNull(nextIncomeDueDate)) {
        return amount;
    }

    Date fiscalYearEndDate = getFiscalYearEndDate();

    // BONDS - rule 4.a
    if (nextIncomeDueDate.after(fiscalYearEndDate)) {
        return BigDecimal.ZERO;
    }

    // rule 4.b
    if (nextIncomeDueDate.before(fiscalYearEndDate)) {
        String incomePayFrequency = security.getIncomePayFrequency();
        if (ObjectUtils.isNull(incomePayFrequency)) {
            return amount;
        }

        Date lastPaymentDate = getLastPaymentDate(incomePayFrequency, fiscalYearEndDate);

        long paymentsRemaining = getTotalPaymentsRemaining(lastPaymentDate, fiscalYearEndDate,
                incomePayFrequency, nextIncomeDueDate);

        long totalNumberOfPayments = kEMService.getTotalNumberOfPaymentsForFiscalYear();

        amount = KEMCalculationRoundingHelper.multiply(holdingTaxLot.getUnits(), security.getIncomeRate(),
                EndowConstants.Scale.SECURITY_MARKET_VALUE);
        amount = amount.multiply(BigDecimal.valueOf(paymentsRemaining));
        amount = KEMCalculationRoundingHelper.divide(amount, BigDecimal.valueOf(totalNumberOfPayments),
                EndowConstants.Scale.SECURITY_MARKET_VALUE);
        amount = amount.add(holdingTaxLot.getCurrentAccrual());
    }

    return amount;
}

From source file:com.mg.merp.planning.support.MPSProcessorServiceBean.java

private void calculateProductionPlan(short lowLevelCode) {
    //?  PlanningItem, BucketOffset desc
    Collections.sort(generatedMPSLines, new Comparator<MpsLine>() {

        public int compare(MpsLine o1, MpsLine o2) {
            if (o1.getPlanningItem().getId() < o2.getPlanningItem().getId())
                return 1;
            else if (o1.getPlanningItem().getId() > o2.getPlanningItem().getId())
                return -1;
            else {
                if (o1.getBucketOffset() < o2.getBucketOffset())
                    return 1;
                else if (o1.getBucketOffset() > o2.getBucketOffset())
                    return -1;
                else
                    return 0;
            }//from   w ww .  j ava  2s. co m
        }

    });

    BigDecimal availableOnBeginBucket = BigDecimal.ZERO;
    GenericItem currentPlanningItem = null;
    for (MpsLine mpsLine : generatedMPSLines) {
        if (MathUtils.compareToZero(mpsLine.getProductionDemandQty()) <= 0
                && mpsLine.getLevelCode() == lowLevelCode) {
            if (currentPlanningItem == null
                    || currentPlanningItem.getId() != mpsLine.getPlanningItem().getId()) {
                currentPlanningItem = mpsLine.getPlanningItem();
                availableOnBeginBucket = BigDecimal.ZERO;
            }

            BigDecimal plannedQty = mpsLine.calculatePlannedQuantity(availableOnBeginBucket);

            Bom bom = bomService.findCurrentBOM(currentPlanningItem.getCatalog().getId());
            if (bom != null) {
                BigDecimal MaxQty = bom.getMaxLotQty(), MinQty = bom.getMinLotQty(),
                        Increment = bom.getLotIncrementQty(), Remainder, RemInc;
                if (!(MathUtils.compareToZeroOrNull(MaxQty) == 0 || MathUtils.compareToZeroOrNull(MinQty) == 0
                        || MathUtils.compareToZeroOrNull(Increment) == 0)) {
                    //?  ?  ?  
                    if (bom.getCatalog().getMeasure1().getId() != mpsLine.getMeasure().getId()) {
                        MaxQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                                mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(), MaxQty);
                        MinQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                                mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(), MinQty);
                        Increment = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                                mpsLine.getMeasure(), bom.getCatalog(), mpsLine.getBucketOffsetDate(),
                                Increment);
                    }

                    long NumOfMax = plannedQty.divide(MaxQty).longValue();
                    Remainder = plannedQty.subtract(MaxQty.multiply(new BigDecimal(NumOfMax)));
                    plannedQty = MaxQty.multiply(new BigDecimal(NumOfMax));
                    if (MathUtils.compareToZero(Remainder) != 0) {
                        if (Remainder.compareTo(MinQty) == -1)
                            plannedQty = plannedQty.add(MinQty);
                        else {
                            long NumOfInc = Remainder.subtract(MinQty).divide(Increment).longValue();
                            RemInc = Remainder.subtract(MinQty)
                                    .subtract(Increment.multiply(new BigDecimal(NumOfInc)));
                            if (MathUtils.compareToZero(RemInc) != 0)
                                plannedQty = plannedQty.add(MinQty)
                                        .add(Increment.multiply(new BigDecimal(NumOfInc))).add(Increment);
                            else
                                plannedQty = plannedQty.add(Remainder);
                        }
                    }
                }
            }
            availableOnBeginBucket = mpsLine.calculateAvailableQuantityOnEndBucket(plannedQty,
                    availableOnBeginBucket);

            if (MathUtils.compareToZero(plannedQty) < 0)
                plannedQty = BigDecimal.ZERO;
            mpsLine.setPlannedQty(plannedQty);
        }
    }
}

From source file:com.ylife.shoppingcart.service.impl.ShoppingCartServiceImpl.java

/**
 * ???? list?,?//  w  ww . j a  v a 2s.  c om
 *
 * @param cartList
 * @return
 * @author jiaodongzhi
 */
@Override
public List<ShoppingCart> getNobaoyouShoppingcarts(List<ShoppingCart> cartList) {
    // ???
    List<ShoppingCart> nobaoyou = new ArrayList<>();
    Marketing marketing = null;
    if (CollectionUtils.isNotEmpty(cartList)) {
        Map<String, Object> map = new HashMap<>();
        // ?,?
        List<ShoppingCart> baoyou = new ArrayList<>();
        for (int i = 0; i < cartList.size(); i++) {
            if (cartList.get(i) != null && cartList.get(i).getGoodsInfoId() != null) {
                // ?id,??,?()?;
                map.put(GOODSID, cartList.get(i).getGoodsInfoId());
                map.put("codeType", "12");
                marketing = marketingMapper.queryMarketingByGoodIdAndtype(map);
                // 
                if (null != marketing) {
                    cartList.get(i).setMarketing(marketing);
                    baoyou.add(cartList.get(i));
                } else {
                    // ?
                    nobaoyou.add(cartList.get(i));
                }

            }
        }
        // id
        Map<Long, String> groups = new HashMap<Long, String>();
        // ? boss?id0
        List<List<ShoppingCart>> shopThirdList = new ArrayList<>();
        Long thirdId = null;
        if (CollectionUtils.isNotEmpty(baoyou)) {
            for (ShoppingCart pd : baoyou) {
                thirdId = pd.getThirdId();
                groups.put(thirdId, "");
            }
            List<ShoppingCart> scart = null;
            if (groups != null && !groups.isEmpty()) {
                for (Long rawTypeId : groups.keySet()) {
                    scart = new ArrayList<>();
                    for (ShoppingCart sc : baoyou) {

                        if (rawTypeId.equals(sc.getThirdId())) {
                            // ?thirdId
                            scart.add(sc);
                        }
                    }
                    shopThirdList.add(scart);
                }
            }
            BigDecimal aftermoney = BigDecimal.valueOf(0);
            Long countgoods = 0L;
            List<ShoppingCart> shop = new ArrayList<>();
            for (int m = 0; m < shopThirdList.size(); m++) {
                // third?
                baoyou = shopThirdList.get(m);
                ShoppingCart sc = new ShoppingCart();
                for (int j = 0; j < baoyou.size(); j++) {
                    GoodsProduct goodsProduct = goodsProductMapper
                            .queryByGoodsInfoDetail(baoyou.get(j).getGoodsInfoId());
                    BigDecimal goodsMoney = goodsProduct.getGoodsInfoPreferPrice();
                    Map<String, Object> mapGoods = new HashMap<String, Object>();
                    // id??,?()?;
                    Marketing mark = marketingMapper.marketingDetail(baoyou.get(j).getMarketingId());
                    // ?
                    if (null != mark) {
                        mapGoods.put(MARKETINGID, mark.getMarketingId());
                        mapGoods.put(GOODSID, baoyou.get(j).getGoodsInfoId());
                    }

                    countgoods = baoyou.get(j).getGoodsNum();
                    // ?
                    aftermoney = aftermoney.add(goodsMoney.multiply(BigDecimal.valueOf(countgoods)));
                    sc.setMarketgoodsPrice(aftermoney);
                    sc.setThirdId(baoyou.get(j).getThirdId());
                    shop.add(sc);
                }
                // ?

                // Map<String, Object> app = new HashMap<>();
                for (int k = 0; k < baoyou.size(); k++) {
                    // ???
                    for (ShoppingCart scra : shop) {
                        if (scra.getThirdId().equals(baoyou.get(k).getThirdId()) && scra.getMarketgoodsPrice()
                                .compareTo(baoyou.get(k).getMarketing().getShippingMoney()) == -1) {

                            // ??
                            nobaoyou.add(baoyou.get(k));
                        }
                    }
                }

            }

        }
    }
    return nobaoyou;

}

From source file:org.egov.wtms.service.es.WaterChargeElasticSearchService.java

/**
 * Prepare list of WaterTaxPayerDetails for each bill collector by summing
 * up the values in each ward for the respective bil collector
 *
 * @param waterChargedashBoardRequest/*from   w  ww.  ja  v  a2  s  .co m*/
 * @param billCollectorWiseMap
 * @param billCollectorWiseWaterTaxPayerDetails
 */
private void prepareTaxersInfoForBillCollectors(final WaterChargeDashBoardRequest waterChargedashBoardRequest,
        final Map<String, List<WaterTaxPayerDetails>> billCollectorWiseMap,
        final List<WaterTaxPayerDetails> billCollectorWiseWaterTaxPayerDetails) {
    BigDecimal cytdColl;
    BigDecimal lytdColl;
    BigDecimal cytdDmd;
    BigDecimal totalDmd;
    WaterTaxPayerDetails waterTaxPayerDetails;
    for (final Entry<String, List<WaterTaxPayerDetails>> entry : billCollectorWiseMap.entrySet()) {
        waterTaxPayerDetails = new WaterTaxPayerDetails();
        cytdColl = BigDecimal.ZERO;
        lytdColl = BigDecimal.ZERO;
        cytdDmd = BigDecimal.ZERO;
        totalDmd = BigDecimal.ZERO;
        for (final WaterTaxPayerDetails taxPayer : entry.getValue()) {
            totalDmd = totalDmd.add(taxPayer.getTotalDmd() == null ? BigDecimal.ZERO : taxPayer.getTotalDmd());
            cytdColl = cytdColl.add(taxPayer.getCurrentYearTillDateColl() == null ? BigDecimal.ZERO
                    : taxPayer.getCurrentYearTillDateColl());
            cytdDmd = cytdDmd.add(taxPayer.getCurrentYearTillDateDmd() == null ? BigDecimal.ZERO
                    : taxPayer.getCurrentYearTillDateDmd());
            lytdColl = lytdColl.add(taxPayer.getLastYearTillDateColl() == null ? BigDecimal.ZERO
                    : taxPayer.getLastYearTillDateColl());
        }
        waterTaxPayerDetails.setBillCollector(entry.getKey());
        waterTaxPayerDetails.setRegionName(waterChargedashBoardRequest.getRegionName());
        waterTaxPayerDetails.setDistrictName(waterChargedashBoardRequest.getDistrictName());
        waterTaxPayerDetails.setUlbGrade(waterChargedashBoardRequest.getUlbGrade());
        waterTaxPayerDetails.setCurrentYearTillDateColl(cytdColl);
        waterTaxPayerDetails.setCurrentYearTillDateDmd(cytdDmd);
        waterTaxPayerDetails.setCurrentYearTillDateBalDmd(cytdDmd.subtract(cytdColl));
        waterTaxPayerDetails.setTotalDmd(totalDmd);
        waterTaxPayerDetails.setLastYearTillDateColl(lytdColl);
        waterTaxPayerDetails.setAchievement(cytdColl.multiply(WaterTaxConstants.BIGDECIMAL_100).divide(cytdDmd,
                1, BigDecimal.ROUND_HALF_UP));
        if (lytdColl.compareTo(BigDecimal.ZERO) > 0)
            cytdColl.subtract(lytdColl).multiply(WaterTaxConstants.BIGDECIMAL_100).divide(lytdColl, 1,
                    BigDecimal.ROUND_HALF_UP);
        billCollectorWiseWaterTaxPayerDetails.add(waterTaxPayerDetails);
    }
}

From source file:com.mg.merp.planning.support.MPSProcessorServiceBean.java

private RollUpMPSResult rollUpMPS(Mps mpsDst, MpsLine srcMpsLine, BigDecimal quan, Date countDay,
        int mpsSequence) {
    BigDecimal roundedQty = quan;
    if (srcMpsLine.getPlanningItem().getCatalog() != null) {
        Bom bom = bomService.findCurrentBOM(srcMpsLine.getPlanningItem().getCatalog().getId());
        if (bom != null) {
            BigDecimal maxQty = bom.getMaxLotQty();
            BigDecimal minQty = bom.getMinLotQty();
            BigDecimal increment = bom.getLotIncrementQty();

            if (!(MathUtils.compareToZeroOrNull(maxQty) == 0 || MathUtils.compareToZeroOrNull(minQty) == 0
                    || MathUtils.compareToZeroOrNull(increment) == 0)) {
                if (bom.getCatalog().getMeasure1().getId() != srcMpsLine.getPlanningItem().getMeasure()
                        .getId()) {//w w  w  . j  a v a 2 s .  c  om
                    maxQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                            srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(),
                            srcMpsLine.getBucketOffsetDate(), maxQty);
                    minQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                            srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(),
                            srcMpsLine.getBucketOffsetDate(), minQty);
                    increment = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(),
                            srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(),
                            srcMpsLine.getBucketOffsetDate(), increment);
                }

                long numOfMax = roundedQty.divide(maxQty).longValue();
                roundedQty = maxQty.multiply(new BigDecimal(numOfMax));
                BigDecimal remainder = roundedQty.add(roundedQty);

                if (MathUtils.compareToZero(remainder) != 0) {
                    if (remainder.compareTo(minQty) < 0) {
                        roundedQty = roundedQty.add(minQty);
                    } else {
                        long numOfInc = remainder.subtract(minQty).divide(increment).longValue();
                        BigDecimal remInc = remainder.subtract(minQty)
                                .subtract(increment.multiply(new BigDecimal(numOfInc)));
                        if (MathUtils.compareToZero(remInc) != 0)
                            roundedQty = roundedQty.add(minQty)
                                    .add(increment.multiply(new BigDecimal(numOfInc))).add(increment);
                        else
                            roundedQty = roundedQty.add(remainder);

                    }
                }
            }
        }
    }

    short bucket = MfUtils.determineBucketOffset(mpsDst.getPlanningLevel().getId(), countDay);
    MpsLine mpsLine = null;
    for (MpsLine line : generatedMPSLines) {
        if (MathUtils.compareToZero(line.getProductionDemandQty()) <= 0
                && line.getPlanningItem().getId() == srcMpsLine.getPlanningItem().getId()
                && line.getBucketOffset() == bucket) {
            mpsLine = line;
            break;
        }
    }
    if (mpsLine == null) {
        mpsLine = mpsLineService.initialize();
        mpsLine.setPlanningItem(srcMpsLine.getPlanningItem());
        mpsLine.setLevelCode(srcMpsLine.getPlanningItem().getLowLevelCode());
        mpsLine.setMps(mpsDst);
        mpsLine.setBucketOffset(bucket);
        BucketRange bucketRange = MfUtils.determineBucketRange(mpsDst.getPlanningLevel().getId(), bucket);
        mpsLine.setBucketOffsetDate(bucketRange.getBucketStart());
        mpsLine.setDemandFenceDate(srcMpsLine.getDemandFenceDate());
        mpsLine.setMpsSequence(mpsSequence);
        mpsLine.setOutputMpsSequence(null);
        mpsLine.setMeasure(srcMpsLine.getMeasure());
        mpsLine.setPlannedQty(roundedQty);

        generatedMPSLines.add(mpsLine);
        //    ? MPS
        return new RollUpMPSResult(roundedQty, mpsSequence + 1);
    } else {
        mpsLine.setPlannedQty(mpsLine.getPlannedQty().add(roundedQty));
        return new RollUpMPSResult(roundedQty, mpsSequence);
    }
}

From source file:org.impotch.calcul.impot.cantonal.ge.pp.avant2010.BaremePrestationCapital2009Test.java

private void test(int revenu, String tauxEnPourcent) {
    RecepteurMultipleImpot recepteur = recepteur("IBR", "RIBR", "CAR", "RCAR", "ADR", "COR");
    FournisseurAssiettePeriodique fournisseur = this.creerAssiettes(2009, revenu);
    producteur2009.produireImpot(situationCelibataire, fournisseur, recepteur);

    BigDecimal valeurImpot = getValeur(recepteur, "TOTAL");

    // On prend les bornes Sup et Inf
    BigDecimal borneSup = valeurImpot.add(deltaSurMontantImpotCalcule);
    BigDecimal borneInf = valeurImpot.subtract(deltaSurMontantImpotCalcule);

    BigDecimal tauxCalculeSup = borneSup.multiply(new BigDecimal(20)).divide(new BigDecimal(revenu), 5,
            BigDecimal.ROUND_HALF_UP);
    BigDecimal tauxCalculeInf = borneInf.multiply(new BigDecimal(20)).divide(new BigDecimal(revenu), 5,
            BigDecimal.ROUND_HALF_UP);
    BigDecimal tauxAttendu = new BigDecimal(tauxEnPourcent);

    assertTrue("Comparaison taux attendu : " + tauxEnPourcent + ", tauxSup " + tauxCalculeSup,
            0 >= tauxAttendu.compareTo(tauxCalculeSup));
    assertTrue("Comparaison taux attendu : " + tauxEnPourcent + ", tauxInf " + tauxCalculeInf,
            0 >= tauxCalculeInf.compareTo(tauxAttendu));
}