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.ar.dev.tierra.api.controller.FacturaController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity<?> add(OAuth2Authentication authentication, @RequestBody Factura factura) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    factura.setUsuarioCreacion(user.getIdUsuario());
    factura.setFechaCreacion(new Date());
    factura.setEstado("INICIADO");
    factura.setIdSucursal(user.getUsuarioSucursal().getIdSucursal());
    factura.setTotal(BigDecimal.ZERO);
    int idFactura = facadeService.getFacturaDAO().add(factura);
    JsonResponse msg = new JsonResponse("Success", String.valueOf(idFactura));
    return new ResponseEntity<>(msg, HttpStatus.OK);
}

From source file:org.ng200.openolympus.services.SolutionService.java

public BigDecimal getSolutionMaximumScore(final Solution solution) {
    return this.getVerdicts(solution).stream().map((verdict) -> verdict.getMaximumScore())
            .reduce((x, y) -> x.add(y)).orElse(BigDecimal.ZERO);
}

From source file:alfio.util.Validator.java

public static ValidationResult validateEventPrices(Optional<Event> event, EventModification ev, Errors errors) {

    if (!isInternal(event, ev)) {
        return ValidationResult.success();
    }/*from w w w .  j av a 2 s  .  com*/

    if (!ev.isFreeOfCharge()) {
        if (isCollectionEmpty(ev.getAllowedPaymentProxies())) {
            errors.rejectValue("allowedPaymentProxies", "error.allowedpaymentproxies");
        }
        if (ev.getRegularPrice() == null || BigDecimal.ZERO.compareTo(ev.getRegularPrice()) >= 0) {
            errors.rejectValue("regularPrice", "error.regularprice");
        }
        if (ev.getVatPercentage() == null || BigDecimal.ZERO.compareTo(ev.getVatPercentage()) > 0) {
            errors.rejectValue("vat", "error.vat");
        }
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "currency", "error.currency");
    }
    if (ev.getAvailableSeats() < 1) {
        errors.rejectValue("availableSeats", "error.availableseats");
    }
    return evaluateValidationResult(errors);
}

From source file:com.haulmont.timesheets.service.StatisticServiceBean.java

public Map<Task, BigDecimal> getStatisticsByTasks(Date start, Date end, @Nullable Project project) {
    LoadContext.Query query = LoadContext
            .createQuery("select t from ts$TimeEntry t where t.date >= :start and t.date <= :end")
            .setParameter("start", start).setParameter("end", end);
    if (project != null) {
        query.setQueryString(query.getQueryString() + " and t.task.project.id = :project");
        query.setParameter("project", project);
    }//from  w  w w . ja va 2 s  .  co  m
    LoadContext<TimeEntry> loadContext = LoadContext.create(TimeEntry.class).setQuery(query)
            .setView(new View(TimeEntry.class)
                    .addProperty("task",
                            new View(Task.class).addProperty("name").addProperty("project",
                                    viewRepository.getView(Project.class, View.MINIMAL)))
                    .addProperty("timeInMinutes"));
    List<TimeEntry> timeEntries = dataManager.loadList(loadContext);
    Map<Task, BigDecimal> result = new HashMap<>();
    for (TimeEntry timeEntry : timeEntries) {
        BigDecimal sum = result.get(timeEntry.getTask());
        if (sum == null) {
            sum = BigDecimal.ZERO;
        }

        sum = sum.add(HoursAndMinutes.fromTimeEntry(timeEntry).toBigDecimal());
        result.put(timeEntry.getTask(), sum);
    }

    return result;
}

From source file:pe.gob.mef.gescon.hibernate.impl.UserDaoImpl.java

@Override
public List<Mtuser> getMtusersExternal() throws Exception {
    DetachedCriteria criteria = DetachedCriteria.forClass(Mtuser.class);
    criteria.add(Restrictions.eq("nuserinterno", BigDecimal.ZERO));
    return (List<Mtuser>) getHibernateTemplate().findByCriteria(criteria);
}

From source file:org.businessmanager.web.controller.page.admin.VatController.java

@Override
public void showAddDialog() {
    vatPercentage = BigDecimal.ZERO;
    model.setSelectedEntity(null);
    super.showAddDialog();
}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.internal.TradeWriter.java

@Override
public void open(ExecutionContext executionContext) {
    if (executionContext.containsKey(TOTAL_AMOUNT_KEY)) {
        this.totalPrice = (BigDecimal) executionContext.get(TOTAL_AMOUNT_KEY);
    } else {/*  w  w w.  jav  a 2 s  .c  om*/
        //
        // Fresh run. Disregard old state.
        //
        this.totalPrice = BigDecimal.ZERO;
    }
}

From source file:org.openmrs.module.openhmis.cashier.web.controller.CashierOptionsController.java

@RequestMapping(method = RequestMethod.GET)
@ResponseBody/*from  w  ww.ja v  a  2  s .  c  om*/
public CashierOptions options() {
    CashierOptions options = cashierOptionsService.getOptions();

    String roundingModeProperty = adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY);
    String roundingItemId = adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID);
    if (StringUtils.isNotEmpty(roundingModeProperty)) {
        if (StringUtils.isEmpty(options.getRoundingItemUuid()) && StringUtils.isNotEmpty(roundingItemId)) {
            throw new APIException(
                    "Rounding item ID set in options but item not found. Make sure your user has the "
                            + "required rights and the item has the set ID in the database");
        }

        // Check to see if rounding has been enabled and throw exception if it has as a rounding item must be set
        if (StringUtils.isEmpty(roundingItemId) && options.getRoundToNearest() != null
                && !options.getRoundToNearest().equals(BigDecimal.ZERO)) {
            throw new APIException("Rounding enabled (nearest " + options.getRoundToNearest().toString()
                    + ") but no rounding item ID specified in options.");
        }
    }

    return options;
}

From source file:org.openvpms.archetype.tools.account.AccountBalanceToolTestCase.java

/**
 * Tests generation given a customer name.
 */// w ww. j a  va 2s .c  o  m
@Test
public void testGenerateForCustomerName() {
    Party customer = getCustomer();
    String name = customer.getName();
    Money amount = new Money(100);
    FinancialAct debit = createInitialBalance(amount);
    save(debit);

    checkEquals(BigDecimal.ZERO, rules.getBalance(customer));
    assertFalse(tool.check(name));

    tool.generate(name);
    checkEquals(amount, rules.getBalance(customer));
    FinancialAct credit = createBadDebt(amount);
    save(credit);
    tool.generate(name);
    checkEquals(BigDecimal.ZERO, rules.getBalance(customer));
    assertTrue(tool.check(name));
}

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

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

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

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

    longAdder.increment();

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

    metrics.incrementCount();

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

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