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.omricat.yacc.data.model.Currency.java

/**
 * Converts a conversionRate in the source currency to a conversionRate in
 * the target currency/*  w w  w  .j a v a2s. co m*/
 *
 * @param source the source currency. Must be non-null.
 * @param target the target currency. Must be non-null.
 * @param value  the conversionRate to be converted. This is a
 *               conversionRate in the source currency. It should be
 *               non-negative.
 * @return the conversionRate converted into the target currency
 */
@NotNull
public static BigDecimal convert(@NotNull final Currency source, @NotNull final Currency target,
        @NotNull final BigDecimal value) {
    checkArgument(checkNotNull(value).compareTo(BigDecimal.ZERO) >= 0, "Value parameter must be non-negative");

    return value.multiply(conversionRatio(checkNotNull(source), checkNotNull(target)));
}

From source file:com.premiumminds.billy.core.services.builders.impl.GenericInvoiceEntryBuilderImpl.java

@Override
@NotOnUpdate//w  w  w  .j  ava 2  s .c  om
public TBuilder setShippingCostsAmount(BigDecimal amount) {
    BillyValidator.notNull(amount,
            GenericInvoiceEntryBuilderImpl.LOCALIZER.getString("field.shipping_costs_amount"));
    Validate.isTrue(amount.compareTo(BigDecimal.ZERO) >= 0);
    this.getTypeInstance().setShippingCostsAmount(amount);
    return this.getBuilder();
}

From source file:cimav.client.data.domain.EmpleadoNomina.java

public BigDecimal getTotalDeducciones() {
    List<Movimiento> deducciones = this.getMovimientos(ETipoConcepto.DEDUCCION);
    BigDecimal result = BigDecimal.ZERO;
    for (Movimiento deduccion : deducciones) {
        if (deduccion.getConcepto().getSuma()) {
            result = result.add(deduccion.getCantidad());
        }/*from  www  .  java2 s.  c  o m*/
    }
    return result;
}

From source file:com.tasktop.c2c.server.internal.tasks.domain.conversion.TaskDomain.java

public Task createManaged(com.tasktop.c2c.server.tasks.domain.Task source) {
    if (source == null) {
        return null;
    }//from   w  w w.j  a  v a2  s  .  com
    Task target = createInternalTask(source);

    target.setId(source.getId());
    target.setCreationTs(source.getCreationDate());
    target.setTaskType(source.getTaskType());
    target.setShortDesc(source.getShortDescription());

    target.setComments(copyCommentsAndWorkLogs(target, source));

    target.setDeadline(source.getDeadline());

    target.setExternalTaskRelations(generateExternalTaskRelationsString(source.getExternalTaskRelations()));
    target.setCommits(generateCommitsString(source.getCommits()));
    target.setEstimatedTime(source.getEstimatedTime());

    // Non-nullable
    target.setKeywords(generateKeywordString(source.getKeywords()));
    target.setStatusWhiteboard("");
    target.setOpSys("");
    target.setVersion(source.getFoundInRelease() == null ? "" : source.getFoundInRelease());
    target.setReporter(createManaged(source.getReporter()));
    target.setAssignee(createManaged(source.getAssignee()));
    target.setProduct(createManaged(source.getProduct()));
    target.setComponent(createManaged(source.getComponent()));
    target.setRepPlatform("");
    target.setResolution(source.getResolution() == null ? "" : source.getResolution().getValue());
    target.setEverconfirmed(false);
    target.setReporterAccessible(true);
    target.setCclistAccessible(true);
    target.setRemainingTime(source.getRemainingTime() == null ? BigDecimal.ZERO : source.getRemainingTime());

    target.setSeverity(source.getSeverity() == null ? "" : source.getSeverity().getValue());
    target.setStatus(source.getStatus() == null ? "" : source.getStatus().getValue());
    target.setPriority(source.getPriority() == null ? "" : source.getPriority().getValue());
    target.setTargetMilestone(source.getMilestone() == null ? "" : source.getMilestone().getValue());

    // Do this last, as some of the previous calls may trigger updates on this object - as a result, we want to make
    // certain that the timestamp of this object is the same that was intended.
    target.setDeltaTs(source.getModificationDate());

    return target;
}

From source file:org.fineract.module.stellar.TestPaymentInIncompleteNetwork.java

@Test
public void roundRobinPayments() throws Exception {
    logger.info("roundRobinPayments test begin");

    final AccountListener accountListener = new AccountListener(serverAddress, firstTenantId, secondTenantId,
            thirdTenantId);//from www.  java2s .  c o  m

    final BigDecimal transferAmount = BigDecimal.TEN;
    makePayment(firstTenantId, firstTenantApiKey, secondTenantId, ASSET_CODE, transferAmount);
    makePayment(secondTenantId, secondTenantApiKey, thirdTenantId, ASSET_CODE, transferAmount);

    accountListener.waitForCredits(MAX_PAY_WAIT,
            creditMatcher(secondTenantId, transferAmount, ASSET_CODE, firstTenantId),
            creditMatcher(thirdTenantId, transferAmount, ASSET_CODE, secondTenantId));

    checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId),
            transferAmount);
    checkBalance(thirdTenantId, thirdTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(secondTenantId),
            transferAmount);

    makePayment(thirdTenantId, thirdTenantApiKey, firstTenantId, ASSET_CODE, transferAmount);

    accountListener.waitForCredits(MAX_PAY_WAIT * 5,
            creditMatcher(firstTenantId, transferAmount, ASSET_CODE, secondTenantId),
            creditMatcher(firstTenantId, transferAmount, ASSET_CODE, firstTenantId),
            creditMatcher(secondTenantId, transferAmount, ASSET_CODE, secondTenantId));

    checkBalance(firstTenantId, firstTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(secondTenantId),
            BigDecimal.ZERO);
    checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId),
            BigDecimal.ZERO);
    checkBalance(thirdTenantId, thirdTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId),
            BigDecimal.ZERO);
    checkBalance(thirdTenantId, thirdTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(secondTenantId),
            BigDecimal.ZERO);
}

From source file:org.openmrs.module.billing.web.controller.main.BillableServiceBillEditForBDController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, Object command, BindingResult bindingResult, HttpServletRequest request,
        @RequestParam("cons") Integer[] cons, @RequestParam("patientId") Integer patientId,
        @RequestParam("billId") Integer billId, @RequestParam("action") String action,
        @RequestParam(value = "description", required = false) String description) {

    validate(cons, bindingResult, request);
    if (bindingResult.hasErrors()) {
        model.addAttribute("errors", bindingResult.getAllErrors());
        return "module/billing/main/patientServiceBillEdit";
    }/*from   ww w .  j  a  v a2 s.c  o  m*/
    BillingService billingService = Context.getService(BillingService.class);

    PatientServiceBill bill = billingService.getPatientServiceBillById(billId);

    // Get the BillCalculator to calculate the rate of bill item the patient
    // has to pay
    Patient patient = Context.getPatientService().getPatient(patientId);
    Map<String, String> attributes = PatientUtils.getAttributes(patient);

    BillCalculatorForBDService calculator = new BillCalculatorForBDService();

    if (!"".equals(description))
        bill.setDescription(description);

    if ("void".equalsIgnoreCase(action)) {
        bill.setVoided(true);
        bill.setVoidedDate(new Date());
        for (PatientServiceBillItem item : bill.getBillItems()) {
            item.setVoided(true);
            item.setVoidedDate(new Date());
            /*ghanshyam 7-sept-2012 these 5 lines of code written only due to voided item is being updated in "billing_patient_service_bill_item" table
              but not being updated in "orders" table */
            Order ord = item.getOrder();
            if (ord != null) {
                ord.setVoided(true);
                ord.setDateVoided(new Date());
            }
            item.setOrder(ord);
        }
        billingService.savePatientServiceBill(bill);
        //ghanshyam 7-sept-2012 Support #343 [Billing][3.2.7-SNAPSHOT]No Queue to be generated from Old bill
        return "redirect:/module/billing/patientServiceBillEditForBD.list?patientId=" + patientId;
    }

    // void old items and reset amount
    Map<Integer, PatientServiceBillItem> mapOldItems = new HashMap<Integer, PatientServiceBillItem>();
    for (PatientServiceBillItem item : bill.getBillItems()) {
        item.setVoided(true);
        item.setVoidedDate(new Date());
        //ghanshyam-kesav 16-08-2012 Bug #323 [BILLING] When a bill with a lab\radiology order is edited the order is re-sent
        Order ord = item.getOrder();
        /*ghanshyam 18-08-2012 [Billing - Bug #337] [3.2.7 snap shot][billing(DDU,DDU SDMX,Tanda,mohali)]error in edit bill.
          the problem was while we are editing the bill of other than lab and radiology.
        */
        if (ord != null) {
            ord.setVoided(true);
            ord.setDateVoided(new Date());
        }
        item.setOrder(ord);
        mapOldItems.put(item.getPatientServiceBillItemId(), item);
    }
    bill.setAmount(BigDecimal.ZERO);
    bill.setPrinted(false);

    PatientServiceBillItem item;
    int quantity = 0;
    Money itemAmount;
    Money mUnitPrice;
    Money totalAmount = new Money(BigDecimal.ZERO);
    BigDecimal totalActualAmount = new BigDecimal(0);
    BigDecimal unitPrice;
    String name;
    BillableService service;

    for (int conceptId : cons) {

        unitPrice = NumberUtils.createBigDecimal(request.getParameter(conceptId + "_unitPrice"));
        quantity = NumberUtils.createInteger(request.getParameter(conceptId + "_qty"));
        name = request.getParameter(conceptId + "_name");
        service = billingService.getServiceByConceptId(conceptId);

        mUnitPrice = new Money(unitPrice);
        itemAmount = mUnitPrice.times(quantity);
        totalAmount = totalAmount.plus(itemAmount);

        String sItemId = request.getParameter(conceptId + "_itemId");

        if (sItemId == null) {
            item = new PatientServiceBillItem();

            // Get the ratio for each bill item
            Map<String, Object> parameters = HospitalCoreUtils.buildParameters("patient", patient, "attributes",
                    attributes, "billItem", item);
            BigDecimal rate;
            //ghanshyam 25-02-2013 New Requirement #966[Billing]Add Paid Bill/Add Free Bill for Bangladesh module
            //ghanshyam 3-june-2013 New Requirement #1632 Orders from dashboard must be appear in billing queue.User must be able to generate bills from this queue
            if (bill.getFreeBill().equals(1)) {
                String billType = "free";
                rate = calculator.getRate(parameters, billType);
            } else if (bill.getFreeBill().equals(2)) {
                String billType = "mixed";
                PatientServiceBillItem patientServiceBillItem = billingService.getPatientServiceBillItem(billId,
                        name);
                String psbi = patientServiceBillItem.getActualAmount().toString();
                if (psbi.equals("0.00")) {
                    rate = new BigDecimal(0);
                } else {
                    rate = new BigDecimal(1);
                }
                item.setActualAmount(item.getAmount().multiply(rate));
            } else {
                String billType = "paid";
                rate = calculator.getRate(parameters, billType);
            }

            item.setAmount(itemAmount.getAmount());
            item.setActualAmount(item.getAmount().multiply(rate));
            totalActualAmount = totalActualAmount.add(item.getActualAmount());
            item.setCreatedDate(new Date());
            item.setName(name);
            item.setPatientServiceBill(bill);
            item.setQuantity(quantity);
            item.setService(service);
            item.setUnitPrice(unitPrice);
            bill.addBillItem(item);
        } else {

            item = mapOldItems.get(Integer.parseInt(sItemId));

            // Get the ratio for each bill item
            Map<String, Object> parameters = HospitalCoreUtils.buildParameters("patient", patient, "attributes",
                    attributes, "billItem", item);
            BigDecimal rate;
            //ghanshyam 25-02-2013 New Requirement #966[Billing]Add Paid Bill/Add Free Bill for Bangladesh module
            //ghanshyam 3-june-2013 New Requirement #1632 Orders from dashboard must be appear in billing queue.User must be able to generate bills from this queue
            if (bill.getFreeBill().equals(1)) {
                String billType = "free";
                rate = calculator.getRate(parameters, billType);
            } else if (bill.getFreeBill().equals(2)) {
                String billType = "mixed";
                PatientServiceBillItem patientServiceBillItem = billingService.getPatientServiceBillItem(billId,
                        name);
                String psbi = patientServiceBillItem.getActualAmount().toString();
                if (psbi.equals("0.00")) {
                    rate = new BigDecimal(0);
                } else {
                    rate = new BigDecimal(1);
                }
                item.setActualAmount(item.getAmount().multiply(rate));
            } else {
                String billType = "paid";
                rate = calculator.getRate(parameters, billType);
            }

            //ghanshyam 5-oct-2012 [Billing - Support #344] [Billing] Edited Quantity and Amount information is lost in database
            if (quantity != item.getQuantity()) {
                item.setVoided(true);
                item.setVoidedDate(new Date());
            } else {
                item.setVoided(false);
                item.setVoidedDate(null);
            }
            // ghanshyam-kesav 16-08-2012 Bug #323 [BILLING] When a bill with a lab\radiology order is edited the order is re-sent
            Order ord = item.getOrder();
            if (ord != null) {
                ord.setVoided(false);
                ord.setDateVoided(null);
            }
            item.setOrder(ord);
            //ghanshyam 5-oct-2012 [Billing - Support #344] [Billing] Edited Quantity and Amount information is lost in database
            if (quantity != item.getQuantity()) {
                item = new PatientServiceBillItem();
                item.setService(service);
                item.setUnitPrice(unitPrice);
                item.setQuantity(quantity);
                item.setName(name);
                item.setCreatedDate(new Date());
                item.setOrder(ord);
                bill.addBillItem(item);
            }
            item.setAmount(itemAmount.getAmount());
            item.setActualAmount(item.getAmount().multiply(rate));

            totalActualAmount = totalActualAmount.add(item.getActualAmount());
        }
    }
    bill.setAmount(totalAmount.getAmount());
    bill.setActualAmount(totalActualAmount);

    // Determine whether the bill is free or not

    //ghanshyam 25-02-2013 New Requirement #966[Billing]Add Paid Bill/Add Free Bill for Bangladesh module
    //ghanshyam 3-june-2013 New Requirement #1632 Orders from dashboard must be appear in billing queue.User must be able to generate bills from this queue
    if (bill.getFreeBill().equals(1)) {
        String billType = "free";
        bill.setFreeBill(calculator.isFreeBill(billType));
    } else if (bill.getFreeBill().equals(2)) {
        String billType = "mixed";
        bill.setFreeBill(2);
    } else {
        String billType = "paid";
        bill.setFreeBill(calculator.isFreeBill(billType));
    }

    logger.info("Is free bill: " + bill.getFreeBill());

    bill = billingService.savePatientServiceBill(bill);
    //ghanshyam 7-sept-2012 Support #343 [Billing][3.2.7-SNAPSHOT]No Queue to be generated from Old bill
    return "redirect:/module/billing/patientServiceBillEditForBD.list?patientId=" + patientId + "&billId="
            + billId;
}

From source file:edu.usu.sdl.openstorefront.common.util.StringProcessor.java

/**
 * Converts a 1.1.1 to a BigDecimal for comparison
 *
 * @param code/*w  w  w.  j a  v a 2  s . co  m*/
 * @return BigDecimal (returns zero on null)
 */
public static BigDecimal archtecureCodeToDecimal(String code) {
    BigDecimal result = BigDecimal.ZERO;
    if (StringUtils.isNotBlank(code)) {
        code = code.replace(".", "");
        if (code.length() > 1) {
            StringBuilder sb = new StringBuilder(code);
            sb.insert(1, ".");
            code = sb.toString();
        }
        result = Convert.toBigDecimal(code, result);
    }
    return result;
}

From source file:com.benfante.minimark.blo.ResultCalculationBo.java

private void evaluateClosedQuestion(ClosedQuestionFilling closedQuestionFilling, String evaluationType,
        BigDecimal minimumEvaluation) {
    BigDecimal result = new BigDecimal("0.00");
    if (evaluationType == null
            || Assessment.EVALUATION_CLOSED_SUM_CORRECT_MINUS_WRONG_ANSWERS.equals(evaluationType)) {
        final BigDecimal weightCorrect = closedQuestionFilling.weightCorrectAnswers();
        final BigDecimal weightSelectedCorrect = closedQuestionFilling.weightSelectedCorrectAnswers();
        final BigDecimal weightWrong = closedQuestionFilling.weightWrongAnswers();
        final BigDecimal weightSelectedWrong = closedQuestionFilling.weightSelectedWrongAnswers();
        BigDecimal normalizedCorrect = new BigDecimal("1.00");
        if (!BigDecimal.ZERO.equals(weightCorrect)) {
            // nc = #selectedCorrect/#correct
            normalizedCorrect = weightSelectedCorrect.divide(weightCorrect, 2, RoundingMode.HALF_EVEN);
        }/*  ww  w.  ja  v  a  2s . c o m*/
        BigDecimal normalizedWrong = new BigDecimal("1.00");
        if (!BigDecimal.ZERO.equals(weightWrong)) {
            // nw = #selectedWrong/#wrong
            normalizedWrong = weightSelectedWrong.divide(weightWrong, 2, RoundingMode.HALF_EVEN);
        }
        // r = nc-nw
        result = normalizedCorrect.subtract(normalizedWrong);
    } else if (Assessment.EVALUATION_CLOSED_SUM_CORRECT_ANSWERS.equals(evaluationType)) {
        final BigDecimal weightCorrect = closedQuestionFilling.weightCorrectAnswers();
        final BigDecimal weightSelectedCorrect = closedQuestionFilling.weightSelectedCorrectAnswers();
        result = new BigDecimal("1.00");
        if (!BigDecimal.ZERO.equals(weightCorrect)) {
            // r = #selectedCorrect/#correct
            result = weightSelectedCorrect.divide(weightCorrect, 2, RoundingMode.HALF_EVEN);
        }
    }
    // r = max(r, minimumEvaluation)
    if (minimumEvaluation != null) {
        result = result.max(minimumEvaluation);
    }
    closedQuestionFilling.setMark(result);
}

From source file:mx.edu.um.mateo.inventario.dao.impl.ProductoDaoHibernate.java

@SuppressWarnings("unchecked")
@Override//from  w  ww .  j a va2s . c  o  m
@Transactional(readOnly = true)
public List<Producto> listaParaSalida(String filtro, Long almacenId) {
    Criteria criteria = currentSession().createCriteria(Producto.class);
    criteria.createCriteria("almacen").add(Restrictions.idEq(almacenId));
    filtro = "%" + filtro + "%";
    Disjunction propiedades = Restrictions.disjunction();
    propiedades.add(Restrictions.ilike("sku", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("nombre", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("descripcion", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("marca", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("modelo", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("ubicacion", filtro, MatchMode.ANYWHERE));
    criteria.add(propiedades);

    propiedades = Restrictions.disjunction();
    propiedades.add(Restrictions.eq("inactivo", Boolean.FALSE));
    propiedades.add(Restrictions.isNull("inactivo"));
    criteria.add(propiedades);

    criteria.add(Restrictions.gt("existencia", BigDecimal.ZERO));
    criteria.setMaxResults(10);
    return criteria.list();
}

From source file:it.govpay.core.utils.RtUtils.java

private static void validaSemantica(CtDatiVersamentoRPT rpt, CtDatiVersamentoRT rt, EsitoValidazione esito) {

    valida(rpt.getCodiceContestoPagamento(), rt.getCodiceContestoPagamento(), esito,
            "CodiceContestoPagamento non corrisponde", true);
    valida(rpt.getIdentificativoUnivocoVersamento(), rt.getIdentificativoUnivocoVersamento(), esito,
            "IdentificativoUnivocoVersamento non corrisponde", true);

    Rpt.EsitoPagamento esitoPagamento = validaSemanticaCodiceEsitoPagamento(rt.getCodiceEsitoPagamento(),
            esito);/*from  w  w w.  ja  va 2 s.  co  m*/

    // Se siamo in pagamento eseguito, parzialmente eseguito o parzialmente decorso, devono esserci tanti versamenti quanti pagamenti.
    if (esitoPagamento != null) {
        switch (esitoPagamento) {
        case DECORRENZA_TERMINI_PARZIALE:
        case PAGAMENTO_ESEGUITO:
        case PAGAMENTO_PARZIALMENTE_ESEGUITO:
            if (rt.getDatiSingoloPagamento().size() != rpt.getDatiSingoloVersamento().size()) {
                esito.addErrore("Numero di pagamenti diverso dal numero di versamenti per una ricevuta di tipo "
                        + esitoPagamento.name(), true);
                return;
            }
        case DECORRENZA_TERMINI:
        case PAGAMENTO_NON_ESEGUITO:
            if (rt.getDatiSingoloPagamento().size() != 0
                    && rt.getDatiSingoloPagamento().size() != rpt.getDatiSingoloVersamento().size()) {
                esito.addErrore("Numero di pagamenti diverso dal numero di versamenti per una ricevuta di tipo "
                        + esitoPagamento.name(), true);
                return;
            }
        }
    }

    BigDecimal importoTotaleCalcolato = BigDecimal.ZERO;

    for (int i = 0; i < rpt.getDatiSingoloVersamento().size(); i++) {

        CtDatiSingoloVersamentoRPT singoloVersamento = rpt.getDatiSingoloVersamento().get(i);
        CtDatiSingoloPagamentoRT singoloPagamento = null;
        if (rt.getDatiSingoloPagamento().size() != 0) {
            singoloPagamento = rt.getDatiSingoloPagamento().get(i);
            validaSemanticaSingoloVersamento(singoloVersamento, singoloPagamento, esito);
            importoTotaleCalcolato = importoTotaleCalcolato.add(singoloPagamento.getSingoloImportoPagato());
        }
    }

    if (importoTotaleCalcolato.compareTo(rt.getImportoTotalePagato()) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] non corrisponde alla somma dei SingoliImportiPagati ["
                + importoTotaleCalcolato.doubleValue() + "]", true);
    if (esitoPagamento == Rpt.EsitoPagamento.PAGAMENTO_NON_ESEGUITO
            && rt.getImportoTotalePagato().compareTo(BigDecimal.ZERO) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da 0 per un pagamento con esito 'Non Eseguito'.", true);
    if (esitoPagamento == Rpt.EsitoPagamento.DECORRENZA_TERMINI
            && rt.getImportoTotalePagato().compareTo(BigDecimal.ZERO) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da 0 per un pagamento con esito 'Decorrenza temini'.", true);
    if (esitoPagamento == Rpt.EsitoPagamento.PAGAMENTO_ESEGUITO
            && rt.getImportoTotalePagato().compareTo(rpt.getImportoTotaleDaVersare()) != 0)
        esito.addErrore("Importo totale del pagamento [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da quanto richiesto [" + rpt.getImportoTotaleDaVersare().doubleValue() + "]",
                false);
}