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:org.kuali.coeus.s2sgen.impl.generate.support.PHS398ChecklistV1_1Generator.java

private void setProjectIncome(PHS398Checklist phsChecklist, BudgetContract budget) {
    Map<Integer, IncomeBudgetPeriod> incomeBudgetPeriodMap = new TreeMap<>();
    BigDecimal anticipatedAmount;
    for (BudgetProjectIncomeContract projectIncome : budget.getBudgetProjectIncomes()) {
        Integer budgetPeriodNumber = projectIncome.getBudgetPeriodNumber();
        IncomeBudgetPeriod incomeBudgPeriod = incomeBudgetPeriodMap.get(budgetPeriodNumber);
        if (incomeBudgPeriod == null) {
            incomeBudgPeriod = IncomeBudgetPeriod.Factory.newInstance();
            incomeBudgPeriod.setBudgetPeriod(budgetPeriodNumber);
            anticipatedAmount = BigDecimal.ZERO;
        } else {//from ww  w.  j  a  v a  2 s. c o  m
            anticipatedAmount = incomeBudgPeriod.getAnticipatedAmount();
        }
        anticipatedAmount = anticipatedAmount.add(projectIncome.getProjectIncome().bigDecimalValue());
        incomeBudgPeriod.setAnticipatedAmount(anticipatedAmount);
        String description = getProjectIncomeDescription(projectIncome);
        if (description != null) {
            if (incomeBudgPeriod.getSource() != null) {
                incomeBudgPeriod.setSource(incomeBudgPeriod.getSource() + ";" + description);
            } else {
                incomeBudgPeriod.setSource(description);
            }
        }
        incomeBudgetPeriodMap.put(budgetPeriodNumber, incomeBudgPeriod);
    }
    Collection<IncomeBudgetPeriod> incomeBudgetPeriodCollection = incomeBudgetPeriodMap.values();
    phsChecklist.setIncomeBudgetPeriodArray(incomeBudgetPeriodCollection.toArray(new IncomeBudgetPeriod[0]));
}

From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java

/**
 * Returns the UP rounded value of the given value for the given steps.
 *
 * @param value The original value to be rounded.
 * @param steps The steps.// w w  w.j a  v a 2 s  .c  om
 * @return The UP rounded value of the given value for the given steps.
 */
public static BigDecimal roundUpTo(double value, double steps) {
    final BigDecimal bValue = BigDecimal.valueOf(value);
    final BigDecimal bSteps = BigDecimal.valueOf(steps);

    if (Objects.equals(bSteps, BigDecimal.ZERO)) {
        return bValue;
    } else {
        return bValue.divide(bSteps, 0, RoundingMode.CEILING).multiply(bSteps);
    }
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractTenantController.java

/**
 * This method returns the Tenant View/*from  ww w  .j a v  a 2 s.  co  m*/
 * 
 * @param tenantParam
 * @param map
 * @return String (tenant.view)
 */

@RequestMapping(value = "/viewtenant", method = RequestMethod.GET)
public String show(@RequestParam(value = "tenant", required = true) String tenantParam, ModelMap map) {
    logger.debug("###Entering in show(tenantId,map) method @GET");
    Tenant tenant = tenantService.get(tenantParam);
    map.addAttribute("tenant", tenant);
    BigDecimal creditBalance = BigDecimal.ZERO;
    if (!tenant.equals(tenantService.getSystemTenant())) {
        creditBalance = billingAdminService.getOrCreateProvisionalAccountStatement(tenant).getFinalCharges()
                .negate(); // toConfirm
    }
    map.addAttribute("creditBalance", creditBalance);
    User user = getCurrentUser();
    Map<Task, String> actions = taskService.getPendingTasksMap(tenant, user, 0, 0);
    map.addAttribute("pendingActions", actions);

    List<ServiceInstance> enabledCSInstances = tenantService.getEnabledCSInstances(tenant);
    Set<Service> services = tenantService.getEnabledServices(tenant);
    map.addAttribute("instances", enabledCSInstances);
    map.addAttribute("services", services);

    Long userLimit = tenant.getMaxUsers();
    map.addAttribute("userLimit", userLimit); // TODO show userlimit in UI

    logger.debug("###Exiting show(map) method @GET");
    return "tenant.view";
}

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

@Override
@Transactional(rollbackFor = { NoEstaAbiertaException.class, NoSePuedeCerrarException.class,
        NoSePuedeCerrarEnCeroException.class })
public FacturaAlmacen cierra(FacturaAlmacen factura, Usuario usuario)
        throws NoSePuedeCerrarException, NoSePuedeCerrarEnCeroException, NoEstaAbiertaException {
    if (factura != null) {
        if (factura.getEstatus().getNombre().equals(Constantes.ABIERTA)) {
            if (usuario != null) {
                factura.setAlmacen(usuario.getAlmacen());
            }/*from w w w  .  j a va  2  s.  c  o  m*/

            Date fecha = new Date();
            factura.setIva(BigDecimal.ZERO);
            factura.setTotal(BigDecimal.ZERO);
            Query query = currentSession().createQuery("select e from Estatus e where e.nombre = :nombre");
            query.setString("nombre", Constantes.FACTURADA);
            Estatus facturada = (Estatus) query.uniqueResult();
            for (Salida salida : factura.getSalidas()) {
                salida.setEstatus(facturada);
                salida.setFechaModificacion(fecha);
                currentSession().update(salida);
                audita(salida, usuario, Constantes.FACTURADA, fecha);
                factura.setIva(factura.getIva().add(salida.getIva()));
                factura.setTotal(factura.getTotal().add(salida.getTotal()));
            }

            for (Entrada entrada : factura.getEntradas()) {
                entrada.setEstatus(facturada);
                entrada.setFechaModificacion(fecha);
                currentSession().update(entrada);
                audita(entrada, usuario, Constantes.FACTURADA, fecha);
                factura.setIva(factura.getIva().subtract(entrada.getIva()));
                factura.setTotal(factura.getTotal().subtract(entrada.getTotal()));
            }

            query.setString("nombre", Constantes.CERRADA);
            Estatus estatus = (Estatus) query.uniqueResult();
            factura.setEstatus(estatus);
            factura.setFolio(getFolio(factura.getAlmacen()));
            factura.setFechaModificacion(fecha);

            currentSession().update(factura);

            audita(factura, usuario, Constantes.ACTUALIZAR, fecha);

            currentSession().flush();
            return factura;
        } else {
            throw new NoEstaAbiertaException("No se puede actualizar una factura que no este abierta");
        }
    } else {
        throw new NoSePuedeCerrarException("No se puede cerrar la factura pues no existe");
    }
}

From source file:com.devnexus.ting.web.controller.admin.RegistrationController.java

@RequestMapping(value = "/s/admin/{eventKey}/uploadRegistration", method = RequestMethod.POST)
public ModelAndView uploadGroupRegistration(ModelAndView model, HttpServletRequest request,
        @PathVariable(value = "eventKey") String eventKey,
        @Valid @ModelAttribute("registerForm") UploadGroupRegistrationForm uploadForm,
        BindingResult bindingResult) throws FileNotFoundException, IOException, InvalidFormatException {

    EventSignup signUp = eventSignupRepository.getByEventKey(eventKey);
    model.getModelMap().addAttribute("event", signUp.getEvent());

    if (bindingResult.hasErrors()) {

        model.getModelMap().addAttribute("registerForm", uploadForm);
        model.setViewName("/admin/upload-registration");
    } else {/*from w  w w .  j  a v  a2 s.  c o  m*/

        boolean hasErrors = false;

        try {

            Workbook wb = WorkbookFactory.create(uploadForm.getRegistrationFile().getInputStream());
            Sheet sheet = wb.getSheetAt(0);
            Cell contactNameCell = sheet.getRow(0).getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
            Cell contactEmailCell = sheet.getRow(1).getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
            Cell contactPhoneCell = sheet.getRow(2).getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
            Cell registrationReferenceCell = sheet.getRow(3).getCell(1,
                    Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);

            if (contactNameCell.getStringCellValue().isEmpty()) {
                hasErrors = true;
                bindingResult.addError(new ObjectError("registrationFile", "Contact Name Empty"));
            }

            if (contactEmailCell.getStringCellValue().isEmpty()) {
                hasErrors = true;
                bindingResult.addError(new ObjectError("registrationFile", "Contact Email Empty"));
            }

            if (contactPhoneCell.getStringCellValue().isEmpty()) {
                hasErrors = true;
                bindingResult.addError(new ObjectError("registrationFile", "Contact Phone Empty"));
            }

            if (registrationReferenceCell.getStringCellValue().isEmpty()) {
                hasErrors = true;
                bindingResult.addError(new ObjectError("registrationFile", "Registration Reference Empty"));
            }

            if (!hasErrors) {
                RegistrationDetails details = new RegistrationDetails();
                details.setContactEmailAddress(contactEmailCell.getStringCellValue());
                details.setContactName(contactNameCell.getStringCellValue());
                details.setContactPhoneNumber(contactPhoneCell.getStringCellValue());
                details.setRegistrationFormKey(registrationReferenceCell.getStringCellValue());
                details.setEvent(signUp.getEvent());
                details.setFinalCost(BigDecimal.ZERO);
                details.setInvoice("Invoiced");
                details.setPaymentState(RegistrationDetails.PaymentState.PAID);
                int attendeeRowIndex = 7;

                Row attendeeRow = sheet.getRow(attendeeRowIndex);
                while (attendeeRow != null) {
                    attendeeRow = sheet.getRow(attendeeRowIndex);
                    if (attendeeRow != null) {
                        Cell firstName = attendeeRow.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell lastName = attendeeRow.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell emailAddress = attendeeRow.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell city = attendeeRow.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell state = attendeeRow.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell country = attendeeRow.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell ticketType = attendeeRow.getCell(6, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell company = attendeeRow.getCell(7, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell jobTitle = attendeeRow.getCell(8, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell tshirtSize = attendeeRow.getCell(9, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell vegetarian = attendeeRow.getCell(10, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        Cell sponsorMessages = attendeeRow.getCell(11,
                                Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);

                        if (firstName.getStringCellValue().isEmpty()) {
                            break;
                        }

                        if (lastName.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information : lastName"));
                            hasErrors = true;
                            break;
                        }
                        if (emailAddress.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information : emailAddress"));
                            hasErrors = true;
                            break;
                        }
                        if (city.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information : city"));
                            hasErrors = true;
                            break;
                        }
                        if (state.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information : state "));
                            hasErrors = true;
                            break;
                        }
                        if (country.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information : country"));
                            hasErrors = true;
                            break;
                        }
                        if (company.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information : company"));
                            hasErrors = true;
                            break;
                        }
                        if (jobTitle.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information : jobTitle"));
                            hasErrors = true;
                            break;
                        }

                        if (ticketType.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information: ticket type"));
                            hasErrors = true;
                            break;
                        }

                        if (tshirtSize.getStringCellValue().isEmpty()) {
                            bindingResult.addError(new ObjectError("registrationFile",
                                    " row " + (attendeeRowIndex + 1) + " missing information: t shirt "));
                            hasErrors = true;
                            break;
                        }
                        if (vegetarian.getStringCellValue().isEmpty()
                                || !(vegetarian.getStringCellValue().equalsIgnoreCase("no")
                                        || vegetarian.getStringCellValue().equalsIgnoreCase("yes"))) {
                            bindingResult.addError(
                                    new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1)
                                            + " missing information. Vegetarian option should be yes or no "));
                            hasErrors = true;
                            break;
                        }
                        if (sponsorMessages.getStringCellValue().isEmpty()
                                || !(sponsorMessages.getStringCellValue().equalsIgnoreCase("no")
                                        || sponsorMessages.getStringCellValue().equalsIgnoreCase("yes"))) {
                            bindingResult.addError(
                                    new ObjectError("registrationFile", " row " + (attendeeRowIndex + 1)
                                            + " missing information. Sponsor message should be yes or no "));
                            hasErrors = true;
                            break;
                        }

                        TicketOrderDetail detail = new TicketOrderDetail();

                        detail.setCity(city.getStringCellValue());
                        detail.setCompany(company.getStringCellValue());
                        detail.setCouponCode("");
                        detail.setCountry(country.getStringCellValue());
                        detail.setEmailAddress(emailAddress.getStringCellValue());
                        detail.setFirstName(firstName.getStringCellValue());
                        detail.setJobTitle(jobTitle.getStringCellValue());
                        detail.setLastName(lastName.getStringCellValue());
                        detail.setSponsorMayContact(
                                sponsorMessages.getStringCellValue().equalsIgnoreCase("no") ? "false" : "true");
                        detail.setState(state.getStringCellValue());
                        detail.setTicketGroup(
                                Long.parseLong(ticketType.getStringCellValue().split("-\\|-")[1].trim()));

                        detail.setLabel(businessService.getTicketGroup(detail.getTicketGroup()).getLabel());

                        detail.settShirtSize(tshirtSize.getStringCellValue());
                        detail.setVegetarian(
                                vegetarian.getStringCellValue().equalsIgnoreCase("no") ? "false" : "true");
                        detail.setRegistration(details);
                        details.getOrderDetails().add(detail);

                        attendeeRowIndex++;

                    }
                }

                if (uploadForm.getOverrideRegistration()) {
                    try {
                        RegistrationDetails tempRegistration = businessService
                                .getRegistrationForm(registrationReferenceCell.getStringCellValue());
                        tempRegistration.getOrderDetails().forEach((oldDetail) -> {
                            oldDetail.setRegistration(null);
                        });
                        tempRegistration.getOrderDetails().clear();
                        tempRegistration.getOrderDetails().addAll(details.getOrderDetails());

                        tempRegistration.getOrderDetails().forEach((detail) -> {
                            detail.setRegistration(tempRegistration);
                        });
                        details = tempRegistration;

                        businessService.updateRegistration(details, uploadForm.getSendEmail());
                    } catch (EmptyResultDataAccessException ignore) {
                        businessService.updateRegistration(details, uploadForm.getSendEmail());
                    }
                } else {
                    try {
                        RegistrationDetails tempRegistration = businessService
                                .getRegistrationForm(registrationReferenceCell.getStringCellValue());
                        hasErrors = true;
                        bindingResult.addError(new ObjectError("registrationFile",
                                "Registration with this key exists, please check \"Replace Registrations\"."));
                    } catch (EmptyResultDataAccessException ignore) {
                        businessService.updateRegistration(details, uploadForm.getSendEmail());
                    }
                }

            }

        } catch (Exception ex) {
            hasErrors = true;
            Logger.getAnonymousLogger().log(Level.SEVERE, ex.getMessage(), ex);

            bindingResult.addError(new ObjectError("registrationFile", ex.getMessage()));
        }
        if (hasErrors) {
            model.setViewName("/admin/upload-registration");
        } else {
            model.setViewName("/admin/index");
        }
    }

    return model;
}

From source file:br.com.postalis.folhapgto.service.SvcFolhaPgtoImpl.java

public boolean criarRelatorioResumoDeDifEnviadasEIncorporadas(Date dtRef) throws JRException {
    List<RelatorioDTO> lista = new ArrayList<RelatorioDTO>();
    LinkedHashMap<String, PosGpxConsignacaoPopulisIncorporada> listaIncorp = new LinkedHashMap<String, PosGpxConsignacaoPopulisIncorporada>();

    for (PosGpxConsignacaoPopulisIncorporada incorp : incorporadosRepository
            .findByDtReferenciaGroupByVerbaAndVlLancamentoAndQtLancamento(dtRef)) {
        listaIncorp.put(incorp.getCdVerba(), incorp);
    }/*from   w  w w  .  j a  v a2  s .  co m*/

    for (ConsignacaoPopulis env : consignadoRepository
            .findByDtReferenciaEnviadosGroupByCdVerbaAndDsVerba(dtRef)) {
        PosGpxConsignacaoPopulisIncorporada inc = listaIncorp.get(env.getCdVerba());
        RelatorioDTO rel;
        if (inc != null) {
            BigDecimal difValor = env.getVlVerba().subtract(inc.getVlLancamento());
            BigDecimal difQtd = env.getQtVerba().subtract(inc.getQtLancamento());
            rel = new RelatorioDTO(env.getCdVerba(), env.getDsVerba(), env.getVlVerba(), env.getQtVerba(),
                    inc.getVlLancamento(), inc.getQtLancamento(), difValor, difQtd);
        } else {
            rel = new RelatorioDTO(env.getCdVerba(), env.getDsVerba(), env.getVlVerba(), env.getQtVerba(),
                    BigDecimal.ZERO, BigDecimal.ZERO, env.getVlVerba(), env.getQtVerba());
        }

        lista.add(rel);
    }

    if (lista == null || lista.isEmpty()) {
        return false;
    }
    gerarRelatorio("Relatrio de diferenas das rbricas enviadas e incorporadas - Sinttico",
            "RelResumoDifRubEnviadasXIncorporadas", lista, dtRef);
    return true;
}

From source file:alfio.manager.system.DataMigrator.java

static BigDecimal parseVersion(String version) {
    Matcher matcher = VERSION_PATTERN.matcher(version);
    if (!matcher.find()) {
        return BigDecimal.ZERO;
    }//from w  w w. j av  a  2 s. c  o m
    return new BigDecimal(matcher.group(1) + matcher.group(2).replaceAll("\\.", ""));
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398ChecklistV1_0Generator.java

private void setProjectIncome(PHS398Checklist phsChecklist, BudgetContract budget) {
    phsChecklist.setProgramIncome(YesNoDataType.YES);

    //TreeMap Used to maintain the order of the Budget periods.
    Map<Integer, IncomeBudgetPeriod> incomeBudgetPeriodMap = new TreeMap<>();
    BigDecimal anticipatedAmount;
    for (BudgetProjectIncomeContract projectIncome : budget.getBudgetProjectIncomes()) {
        Integer budgetPeriodNumber = projectIncome.getBudgetPeriodNumber();
        IncomeBudgetPeriod incomeBudgPeriod = incomeBudgetPeriodMap.get(budgetPeriodNumber);
        if (incomeBudgPeriod == null) {
            incomeBudgPeriod = IncomeBudgetPeriod.Factory.newInstance();
            incomeBudgPeriod.setBudgetPeriod(budgetPeriodNumber);
            anticipatedAmount = BigDecimal.ZERO;
        } else {//from  w w w. ja  v  a 2s .  com
            anticipatedAmount = incomeBudgPeriod.getAnticipatedAmount();
        }
        anticipatedAmount = anticipatedAmount.add(projectIncome.getProjectIncome().bigDecimalValue());
        incomeBudgPeriod.setAnticipatedAmount(anticipatedAmount);
        String description = getProjectIncomeDescription(projectIncome);
        if (description != null) {
            if (incomeBudgPeriod.getSource() != null) {
                incomeBudgPeriod.setSource(incomeBudgPeriod.getSource() + ";" + description);
            } else {
                incomeBudgPeriod.setSource(description);
            }
        }
        incomeBudgetPeriodMap.put(budgetPeriodNumber, incomeBudgPeriod);
    }
    Collection<IncomeBudgetPeriod> incomeBudgetPeriodCollection = incomeBudgetPeriodMap.values();
    phsChecklist.setIncomeBudgetPeriodArray(incomeBudgetPeriodCollection.toArray(new IncomeBudgetPeriod[0]));
}

From source file:module.siadap.domain.SiadapEvaluationUniverse.java

private BigDecimal getEvaluationScoring(List<? extends SiadapEvaluationItem> evaluations) {

    if (!isEvaluationScoringComplete(evaluations)) {
        return BigDecimal.ZERO;
    }//from  ww w  . ja  va 2 s .  com

    BigDecimal result = new BigDecimal(0);
    for (SiadapEvaluationItem evaluation : evaluations) {
        IScoring itemEvaluation = evaluation.getItemEvaluation();
        if (itemEvaluation == null) {
            throw new SiadapException("error.siadapEvaluation.mustFillAllItems");
        }
        result = result.add(itemEvaluation.getPoints());
    }

    if (evaluations.size() == 0) {
        return BigDecimal.ZERO;
    }
    return result.divide(new BigDecimal(evaluations.size()), PRECISION, ROUND_MODE);
}

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

/**
 * @return 0 if val is null//  w w w .jav  a  2 s .c o m
 */
public static BigDecimal getBD(BigDecimal val) {
    return val == null ? BigDecimal.ZERO : val;
}