Example usage for java.math BigDecimal ZERO

List of usage examples for java.math BigDecimal ZERO

Introduction

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

Prototype

BigDecimal ZERO

To view the source code for java.math BigDecimal ZERO.

Click Source Link

Document

The value 0, with a scale of 0.

Usage

From source file:com.qcadoo.mes.masterOrders.hooks.OrderDetailsHooksMO.java

private void fillMasterOrderFields(final ViewDefinitionState view, final Entity masterOrder,
        final Entity product) {
    FieldComponent numberField = (FieldComponent) view.getComponentByReference(OrderFields.NUMBER);
    LookupComponent companyLookup = (LookupComponent) view.getComponentByReference(OrderFields.COMPANY);
    FieldComponent deadlineField = (FieldComponent) view.getComponentByReference(OrderFields.DEADLINE);
    FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_FROM);
    FieldComponent dateToField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_TO);
    LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT);
    LookupComponent technologyPrototypeLookup = (LookupComponent) view
            .getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE);
    FieldComponent plannedQuantityField = (FieldComponent) view
            .getComponentByReference(OrderFields.PLANNED_QUANTITY);

    if (masterOrder != null) {
        String masterOrderNumber = masterOrder.getStringField(MasterOrderFields.NUMBER);
        Entity masterOrderCompany = masterOrder.getBelongsToField(MasterOrderFields.COMPANY);
        Date masterOrderDeadline = masterOrder.getDateField(MasterOrderFields.DEADLINE);
        Date masterOrderStartDate = masterOrder.getDateField(MasterOrderFields.START_DATE);
        Date masterOrderFinishDate = masterOrder.getDateField(MasterOrderFields.FINISH_DATE);
        Entity masterOrderProduct = masterOrder.getBelongsToField(MasterOrderFields.PRODUCT);

        BigDecimal masterOrderQuantity = BigDecimalUtils
                .convertNullToZero(masterOrder.getDecimalField(MasterOrderFields.MASTER_ORDER_QUANTITY));

        BigDecimal cumulatedOrderQuantity = BigDecimalUtils.convertNullToZero(masterOrderOrdersDataProvider
                .sumBelongingOrdersPlannedQuantities(masterOrder, masterOrderProduct));

        BigDecimal plannedQuantity = masterOrderQuantity.subtract(cumulatedOrderQuantity,
                numberService.getMathContext());

        if (product != null) {
            masterOrderProduct = product;
        }//from  w w  w.j a v a 2  s.c  om

        Entity masterOrderTechnology = masterOrder.getBelongsToField(MasterOrderFields.TECHNOLOGY);

        String number = (String) numberField.getFieldValue();

        String generatedNumber = numberGeneratorService.generateNumberWithPrefix(
                OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, 3, masterOrderNumber + "-");

        // if (StringUtils.isEmpty(number) || generatedNumber.equals(number)) {
        numberField.setFieldValue(generatedNumber);
        // }

        if ((companyLookup.getEntity() == null) && (masterOrderCompany != null)) {
            companyLookup.setFieldValue(masterOrderCompany.getId());
        }

        if (StringUtils.isEmpty((String) deadlineField.getFieldValue()) && (masterOrderDeadline != null)) {
            deadlineField.setFieldValue(DateUtils.toDateTimeString(masterOrderDeadline));
        }

        if (StringUtils.isEmpty((String) dateFromField.getFieldValue()) && (masterOrderStartDate != null)) {
            dateFromField.setFieldValue(DateUtils.toDateTimeString(masterOrderStartDate));
        }

        if (StringUtils.isEmpty((String) dateToField.getFieldValue()) && (masterOrderFinishDate != null)) {
            dateToField.setFieldValue(DateUtils.toDateTimeString(masterOrderFinishDate));
        }

        if ((productLookup.getEntity() == null) && (masterOrderProduct != null)) {
            productLookup.setFieldValue(masterOrderProduct.getId());
        }

        if ((technologyPrototypeLookup.getEntity() == null) && (masterOrderTechnology != null)) {
            technologyPrototypeLookup.setFieldValue(masterOrderTechnology.getId());
        }

        if (StringUtils.isEmpty((String) plannedQuantityField.getFieldValue()) && (plannedQuantity != null)
                && (BigDecimal.ZERO.compareTo(plannedQuantity) < 0)) {
            plannedQuantityField.setFieldValue(numberService.format(plannedQuantity));
        }

        numberField.requestComponentUpdateState();
        companyLookup.requestComponentUpdateState();
        deadlineField.requestComponentUpdateState();
        dateFromField.requestComponentUpdateState();
        dateToField.requestComponentUpdateState();
        productLookup.requestComponentUpdateState();
        technologyPrototypeLookup.requestComponentUpdateState();
        plannedQuantityField.requestComponentUpdateState();

        productLookup.performEvent(view, "onSelectedEntityChange", "");
    }
}

From source file:com.axelor.apps.account.service.MoveLineExportService.java

public BigDecimal getSumCredit(String queryFilter, List<Move> moveList) {

    Query q = JPA.em().createQuery("select SUM(self.credit) FROM MoveLine as self WHERE " + queryFilter,
            BigDecimal.class);
    q.setParameter(1, moveList);/*from  w  w  w . j  a  va  2s  .co  m*/

    BigDecimal result = (BigDecimal) q.getSingleResult();
    log.debug("Total credit : {}", result);

    if (result != null) {
        return result;
    } else {
        return BigDecimal.ZERO;
    }

}

From source file:com.neovisionaries.security.JsonDigestUpdater.java

private boolean isZero(JsonNode value) {
    // int//from  ww  w  . j a v  a2 s  .co m
    if (value.isInt() && value.intValue() == 0) {
        return true;
    }

    // long
    if (value.isLong() && value.longValue() == 0) {
        return true;
    }

    // short
    if (value.isShort() && value.shortValue() == 0) {
        return true;
    }

    // float
    if (value.isFloat() && value.floatValue() == 0.0F) {
        return true;
    }

    // double
    if (value.isDouble() && value.doubleValue() == 0.0) {
        return true;
    }

    // BigInteger
    if (value.isBigInteger() && value.bigIntegerValue().equals(BigInteger.ZERO)) {
        return true;
    }

    // BigDecimal
    if (value.isBigDecimal() && value.decimalValue().equals(BigDecimal.ZERO)) {
        return true;
    }

    return false;
}

From source file:com.epam.cme.facades.converters.populator.DeviceBundleTabsPopulator.java

/**
 * Hook to call additional populators for different purposes. For Devices we are populating the
 * standard price of the according plan. Afterwards we are finding possible price rules for the
 * device product as well as for the plan product and storing the cheapest ones in the plan DTO
 * as <code>otherBundleProductPrice</code> for the cheapest device price and as
 * <code>thisBundleProductPrice</code> for the cheapest plan price.
 * /*  w w w.  j ava 2s  .  c  om*/
 * @param sourceComponent
 *            in this case e.g. the "Smartphone-Handset" component
 * @param targetComponent
 *            in this case e.g. the "Smartphone-Plan" component
 * @param productModel
 *            in this case the Model of the device product
 * @param productData
 *            in this case the DTO of the device product
 * @param subscriptionProductModel
 *            in this case the Model of the plan product
 * @param subscriptionProductData
 *            in this case the DTO of the plan product
 */
@Override
protected void callPopulators(final SOURCETEMPLATE sourceComponent, final SOURCETEMPLATE targetComponent,
        final SOURCEPRODUCT productModel, final TARGETPRODUCT productData,
        final SubscriptionProductModel subscriptionProductModel, final ProductData subscriptionProductData) {
    getProductPricePopulator().populate(subscriptionProductModel, subscriptionProductData);
    getSubscriptionProductPricePopulator().populate(subscriptionProductModel, subscriptionProductData);
    getProductDescriptionPopulator().populate(subscriptionProductModel, subscriptionProductData);
    getProductClassificationPopulator().populate(subscriptionProductModel, subscriptionProductData);

    final CurrencyModel currency = getCommonI18NService().getCurrentCurrency();

    final ChangeProductPriceBundleRuleModel devicePriceRule = getBundleRuleService()
            .getChangePriceBundleRule(sourceComponent, productModel, subscriptionProductModel, currency);
    subscriptionProductData.setOtherBundleProductPrice(devicePriceRule == null ? productData.getPrice()
            : getPriceDataFactory().create(PriceDataType.BUY, devicePriceRule.getPrice(),
                    currency.getIsocode()));

    final ChangeProductPriceBundleRuleModel planPriceRule = getBundleRuleService()
            .getChangePriceBundleRule(targetComponent, subscriptionProductModel, productModel, currency);
    final BigDecimal planPriceRulePrice = planPriceRule == null ? null : planPriceRule.getPrice();

    final SubscriptionPricePlanData pricePlan = (SubscriptionPricePlanData) subscriptionProductData.getPrice();
    BigDecimal pricePlanLowestPrice = BigDecimal.ZERO;
    BigDecimal discountPrice = BigDecimal.ZERO;

    if (pricePlan != null && CollectionUtils.isNotEmpty(pricePlan.getRecurringChargeEntries())) {
        final RecurringChargeEntryData lowestPriceChargeEntry = pricePlan.getRecurringChargeEntries().iterator()
                .next();
        pricePlanLowestPrice = lowestPriceChargeEntry.getPrice().getValue();
    }

    if (planPriceRulePrice == null || pricePlanLowestPrice.doubleValue() < planPriceRulePrice.doubleValue()) {
        discountPrice = pricePlanLowestPrice;
    } else {
        discountPrice = BigDecimal.valueOf(planPriceRulePrice.doubleValue());
    }

    subscriptionProductData.setThisBundleProductPrice(
            getPriceDataFactory().create(PriceDataType.BUY, discountPrice, currency.getIsocode()));
}

From source file:com.rockagen.gnext.service.spring.AccountServImpl.java

/**
 * Balance enough?//from   www .  j av  a2  s  .c  om
 *
 * @param account Account
 * @param amount  amount
 * @return true if enough
 */
private boolean checkBalance(Account account, BigDecimal amount) {
    BigDecimal tmp = account.getAvailableBalance().subtract(amount.abs());
    if ((tmp.compareTo(BigDecimal.ZERO)) < 0) {
        return false;
    }
    return true;

}

From source file:org.yes.cart.payment.impl.PayPalExpressCheckoutPaymentGatewayImpl.java

/**
 * Get the express checkout details via GetExpressCheckoutDetails method of
 * pay pal payment gateway//  ww  w.ja v  a 2 s. co m
 *
 * @param token   the token obtained via   SetExpressCheckout method
 * @param payerId the token obtained via   GetExpressCheckoutDetails method
 * @param amount  the amount
 * @return map of parsed key - values with detail information
 * @throws java.io.IOException in case of errors
 */
public Map<String, String> doDoExpressCheckoutPayment(final String token, final String payerId,
        final BigDecimal amount, final String currencyCode) throws IOException {

    Assert.notNull(token, "The pay pal tonek must  be not null");
    Assert.notNull(payerId, "Payer must be provided");
    Assert.notNull(amount, "Amount must be provided");
    Assert.isTrue(amount.compareTo(BigDecimal.ZERO) > 0, "Amount must be positive");
    Assert.notNull(currencyCode, "Currency code must be provided");

    final StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append(PP_EC_TOKEN);
    stringBuilder.append(EQ);
    stringBuilder.append(URLEncoder.encode(token));
    stringBuilder.append(AND);

    stringBuilder.append(PP_EC_PAYERID);
    stringBuilder.append(EQ);
    stringBuilder.append(URLEncoder.encode(payerId));
    stringBuilder.append(AND);

    stringBuilder.append(PP_EC_PAYMENTREQUEST_0_AMT);
    stringBuilder.append(EQ);
    stringBuilder.append(URLEncoder.encode("" + amount));
    stringBuilder.append(AND);

    stringBuilder.append(PP_EC_PAYMENTREQUEST_0_CURRENCYCODE);
    stringBuilder.append(EQ);
    stringBuilder.append(currencyCode);
    stringBuilder.append(AND);

    stringBuilder.append(PP_EC_PAYMENTREQUEST_0_PAYMENTACTION);
    stringBuilder.append(EQ);
    stringBuilder.append(URLEncoder.encode("Sale"));

    return performHttpCall("DoExpressCheckoutPayment", stringBuilder.toString());

}

From source file:com.axelor.apps.account.service.MoveLineExportService.java

public BigDecimal getSumCredit(List<MoveLine> moveLineList) {

    BigDecimal sumCredit = BigDecimal.ZERO;
    for (MoveLine moveLine : moveLineList) {
        sumCredit = sumCredit.add(moveLine.getCredit());
    }//from   ww  w.j  ava  2  s.  c o  m

    return sumCredit;
}

From source file:pe.gob.mef.gescon.web.ui.AlertaMB.java

public void cleanAttributes() {
    this.setId(BigDecimal.ZERO);
    this.setDescripcion(StringUtils.EMPTY);
    this.setNombre(StringUtils.EMPTY);
    this.setActivo(BigDecimal.ONE);
    this.setSelectedParametro(BigDecimal.ZERO);
    this.setCondicion1(BigDecimal.ONE);
    this.setCondicion2(BigDecimal.ONE);

    Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages();
    if (iter.hasNext() == true) {
        iter.remove();/*from   ww w. j a  v a2 s .c o m*/
        FacesContext.getCurrentInstance().renderResponse();
    }
}

From source file:org.openvpms.archetype.rules.finance.account.CustomerAccountRules.java

/**
 * Calculates a new balance for a customer from the current outstanding
 * balance and a running total./*from   w  ww  .  j av  a2 s .c o  m*/
 * If the new balance is:
 * <ul>
 * <li>&lt; 0 returns 0.00 for payments, or -balance for refunds</li>
 * <li>&gt; 0 returns 0.00 for refunds</li>
 * </ul>
 *
 * @param customer the customer
 * @param total    the running total
 * @param payment  if {@code true} indicates the total is for a payment,
 *                 if {@code false} indicates it is for a refund
 * @return the new balance
 * @throws ArchetypeServiceException for any archetype service error
 */
public BigDecimal getBalance(Party customer, BigDecimal total, boolean payment) {
    BigDecimal balance = getBalance(customer);
    BigDecimal result;
    if (payment) {
        result = balance.subtract(total);
    } else {
        result = balance.add(total);
    }
    if (result.signum() == -1) {
        result = (payment) ? BigDecimal.ZERO : result.negate();
    } else if (result.signum() == 1 && !payment) {
        result = BigDecimal.ZERO;
    }
    return result;
}

From source file:com.gst.portfolio.search.data.AdHocQueryDataValidator.java

public void validateAdHocQueryParameters(final String json) {

    if (StringUtils.isBlank(json)) {
        throw new InvalidJsonException();
    }//from   w w  w  .j  a  v  a 2  s.c o  m

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,
            AdHocQuerySearchConstants.AD_HOC_SEARCH_QUERY_REQUEST_DATA_PARAMETERS);

    final JsonElement element = this.fromApiJsonHelper.parse(json);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(AdHocQuerySearchConstants.AD_HOC_SEARCH_QUERY_RESOURCE_NAME);

    final String[] entities = this.fromApiJsonHelper
            .extractArrayNamed(AdHocQuerySearchConstants.entitiesParamName, element);
    baseDataValidator.reset().parameter(AdHocQuerySearchConstants.entitiesParamName).value(entities)
            .arrayNotEmpty();

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.loanStatusParamName, element)) {
        final String[] loanStatus = this.fromApiJsonHelper
                .extractArrayNamed(AdHocQuerySearchConstants.loanStatusParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.loanStatusParamName).value(loanStatus)
                .arrayNotEmpty();
        if (loanStatus != null && loanStatus.length > 0) {
            for (String status : loanStatus) {
                baseDataValidator.reset().parameter(AdHocQuerySearchConstants.loanStatusParamName).value(status)
                        .isOneOfTheseValues(AdHocQuerySearchConstants.loanStatusOptions);
            }
        }
    }

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.loanProductsParamName, element)) {
        final String[] loanProducts = this.fromApiJsonHelper
                .extractArrayNamed(AdHocQuerySearchConstants.loanProductsParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.loanProductsParamName).value(loanProducts)
                .arrayNotEmpty();
    }

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.officesParamName, element)) {
        final String[] offices = this.fromApiJsonHelper
                .extractArrayNamed(AdHocQuerySearchConstants.officesParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.officesParamName).value(offices)
                .arrayNotEmpty();
    }

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.loanDateOptionParamName, element)) {
        final String loanDateOption = this.fromApiJsonHelper
                .extractStringNamed(AdHocQuerySearchConstants.loanDateOptionParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.loanDateOptionParamName)
                .value(loanDateOption).isOneOfTheseValues(AdHocQuerySearchConstants.loanDateOptions);
    }

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.loanFromDateParamName, element)) {
        final LocalDate loanFromDate = this.fromApiJsonHelper
                .extractLocalDateNamed(AdHocQuerySearchConstants.loanFromDateParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.loanFromDateParamName).value(loanFromDate)
                .notNull();
    }

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.loanToDateParamName, element)) {
        final LocalDate loanToDate = this.fromApiJsonHelper
                .extractLocalDateNamed(AdHocQuerySearchConstants.loanToDateParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.loanToDateParamName).value(loanToDate)
                .notNull();
    }

    if (this.fromApiJsonHelper
            .parameterExists(AdHocQuerySearchConstants.includeOutStandingAmountPercentageParamName, element)) {
        final boolean includeOutStandingAmountPercentage = this.fromApiJsonHelper.extractBooleanNamed(
                AdHocQuerySearchConstants.includeOutStandingAmountPercentageParamName, element);
        baseDataValidator.reset()
                .parameter(AdHocQuerySearchConstants.includeOutStandingAmountPercentageParamName)
                .value(includeOutStandingAmountPercentage).notNull();
    }

    if (this.fromApiJsonHelper.parameterExists(
            AdHocQuerySearchConstants.outStandingAmountPercentageConditionParamName, element)) {
        final String outStandingAmountPercentageCondition = this.fromApiJsonHelper.extractStringNamed(
                AdHocQuerySearchConstants.outStandingAmountPercentageConditionParamName, element);
        baseDataValidator.reset()
                .parameter(AdHocQuerySearchConstants.outStandingAmountPercentageConditionParamName)
                .value(outStandingAmountPercentageCondition)
                .isNotOneOfTheseValues(AdHocQuerySearchConstants.AD_HOC_SEARCH_QUERY_CONDITIONS);
        if (outStandingAmountPercentageCondition.equals("between")) {
            final BigDecimal minOutStandingAmountPercentage = this.fromApiJsonHelper
                    .extractBigDecimalWithLocaleNamed(
                            AdHocQuerySearchConstants.minOutStandingAmountPercentageParamName, element);
            baseDataValidator.reset()
                    .parameter(AdHocQuerySearchConstants.minOutStandingAmountPercentageParamName)
                    .value(minOutStandingAmountPercentage).notNull().notLessThanMin(BigDecimal.ZERO);
            final BigDecimal maxOutStandingAmountPercentage = this.fromApiJsonHelper
                    .extractBigDecimalWithLocaleNamed(
                            AdHocQuerySearchConstants.maxOutStandingAmountPercentageParamName, element);
            baseDataValidator.reset()
                    .parameter(AdHocQuerySearchConstants.maxOutStandingAmountPercentageParamName)
                    .value(maxOutStandingAmountPercentage).notNull().notLessThanMin(BigDecimal.ZERO);
            baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(minOutStandingAmountPercentage,
                    maxOutStandingAmountPercentage);
        } else {
            if (this.fromApiJsonHelper
                    .parameterExists(AdHocQuerySearchConstants.outStandingAmountPercentageParamName, element)) {
                final BigDecimal outStandingAmountPercentage = this.fromApiJsonHelper
                        .extractBigDecimalWithLocaleNamed(
                                AdHocQuerySearchConstants.outStandingAmountPercentageParamName, element);
                baseDataValidator.reset()
                        .parameter(AdHocQuerySearchConstants.outStandingAmountPercentageParamName)
                        .value(outStandingAmountPercentage).notNull().notLessThanMin(BigDecimal.ZERO);
            }
        }
    }

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.includeOutstandingAmountParamName,
            element)) {
        final Boolean includeOutstandingAmountParamName = this.fromApiJsonHelper
                .extractBooleanNamed(AdHocQuerySearchConstants.includeOutstandingAmountParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.includeOutstandingAmountParamName)
                .value(includeOutstandingAmountParamName).notNull();
    }

    if (this.fromApiJsonHelper.parameterExists(AdHocQuerySearchConstants.outstandingAmountConditionParamName,
            element)) {
        final String outstandingAmountCondition = this.fromApiJsonHelper
                .extractStringNamed(AdHocQuerySearchConstants.outstandingAmountConditionParamName, element);
        baseDataValidator.reset().parameter(AdHocQuerySearchConstants.outstandingAmountConditionParamName)
                .value(outstandingAmountCondition)
                .isNotOneOfTheseValues(AdHocQuerySearchConstants.AD_HOC_SEARCH_QUERY_CONDITIONS);
        if (outstandingAmountCondition.equals("between")) {
            final BigDecimal minOutstandingAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
                    AdHocQuerySearchConstants.minOutstandingAmountParamName, element);
            baseDataValidator.reset().parameter(AdHocQuerySearchConstants.minOutstandingAmountParamName)
                    .value(minOutstandingAmount).notNull().notLessThanMin(BigDecimal.ZERO);
            final BigDecimal maxOutstandingAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
                    AdHocQuerySearchConstants.maxOutstandingAmountParamName, element);
            baseDataValidator.reset().parameter(AdHocQuerySearchConstants.maxOutstandingAmountParamName)
                    .value(maxOutstandingAmount).notNull().notLessThanMin(BigDecimal.ZERO);
            baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(minOutstandingAmount,
                    maxOutstandingAmount);
        } else {
            final BigDecimal outstandingAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
                    AdHocQuerySearchConstants.outstandingAmountParamName, element);
            baseDataValidator.reset().parameter(AdHocQuerySearchConstants.outstandingAmountParamName)
                    .value(outstandingAmount).notNull().notLessThanMin(BigDecimal.ZERO);
        }
    }

    throwExceptionIfValidationWarningsExist(dataValidationErrors);

}