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.excilys.ebi.bank.dao.impl.OperationDaoImpl.java

private Predicate buildOperationSignPredicate(OperationSign sign) {
    return sign == OperationSign.CREDIT ? operation.amount.gt(BigDecimal.ZERO)
            : operation.amount.lt(BigDecimal.ZERO);
}

From source file:net.sf.reportengine.util.TestCalculatorIntermResultMatrix.java

@Test
public void testInitFirstXRows() {
    classUnderTest = new CalculatorIntermResultsMatrix(3, TEST_DATA_COLUMNS);
    classUnderTest.initAll();/*from   w w  w  .  j  a v a2 s.  co  m*/

    classUnderTest.addValuesToEachRow(new NewRowEvent(TEST_VALUES));

    //reinit the first two columns
    classUnderTest.initFirstXRows(2);

    //check the interm results matrix
    Assert.assertNotNull(classUnderTest);
    Assert.assertNotNull(classUnderTest.getIntermResultsMatrix());
    Assert.assertEquals(classUnderTest.getIntermResultsMatrix().length, 3);

    //the first row should be re-initialized
    CalcIntermResult[] row1 = classUnderTest.getIntermResultsMatrix()[0];
    Assert.assertNotNull(row1);
    Assert.assertEquals(row1.length, 2);
    Assert.assertEquals(row1[0].getResult(), NumberUtils.INTEGER_ZERO);
    Assert.assertEquals(row1[1].getResult(), BigDecimal.ZERO);

    //the second row should be also re-initialized
    CalcIntermResult[] row2 = classUnderTest.getIntermResultsMatrix()[1];
    Assert.assertNotNull(row2);
    Assert.assertEquals(row2.length, 2);
    Assert.assertEquals(row2[0].getResult(), NumberUtils.INTEGER_ZERO);
    Assert.assertEquals(row2[1].getResult(), BigDecimal.ZERO);

    //the third row should not be re-initialized
    CalcIntermResult[] row3 = classUnderTest.getIntermResultsMatrix()[2];
    Assert.assertNotNull(row3);
    Assert.assertEquals(row3.length, 2);
    Assert.assertNotSame(row3[0].getResult(), NumberUtils.INTEGER_ZERO);
    Assert.assertNotSame(row3[1].getResult(), BigDecimal.ZERO);
}

From source file:com.redhat.lightblue.metadata.types.BigDecimalTypeTest.java

@Test
public void testCompareNotEqual() {
    assertEquals(bigDecimalType.compare((Object) BigDecimal.ZERO, (Object) BigDecimal.ONE), -1);
}

From source file:com.siapa.managedbean.RegistroAlimentacionManagedBean.java

public Boolean UpdateStock() {
    Boolean isOk;/*  w  w  w .  ja  v a 2s  .co  m*/
    BigDecimal existencia = BigDecimal.ZERO;
    BigDecimal existenciaActual = alimento.getExistenciaAlimento();
    Integer id = alimento.getIdAlimento();
    BigDecimal existenciaNueva;
    BigDecimal reduccion = registroAlimentacion.getCantidadRegistroAlimentacion();

    if (existenciaActual.compareTo(reduccion) == -1) {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("El inventario no es suficiente"));
        isOk = false;
    } else {
        existenciaNueva = existenciaActual.subtract(reduccion);
        Alimento newAlimento = getAlimento();
        Alimento idAlimento = registroAlimentacion.getIdAlimento();
        Alimento cactual = alimentoService.findById(idAlimento.getIdAlimento());
        existencia = cactual.getExistenciaAlimento().subtract(reduccion);
        newAlimento.setExistenciaAlimento(existencia);
        alimentoService.merge(newAlimento);
        isOk = true;

    }
    /* System.out.println("el id es "+id);
     System.out.println("la existencia es "+existenciaActual);
     System.out.println("la reduccion es "+reduccion);*/
    // System.out.println("la nueva existencia es "+existenciaNueva);
    return isOk;

}

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

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, @RequestParam("ambulanceBillId") Integer ambulanceBillId,
        @RequestParam("driverId") Integer driverId, @RequestParam("ambulanceIds") Integer[] ambulanceIds,
        @RequestParam("action") String action, HttpServletRequest request, Object command,
        BindingResult binding) {//from   w  w w . j  av a  2 s  . c  om

    validate(ambulanceIds, binding, request);
    if (binding.hasErrors()) {
        model.addAttribute("errors", binding.getAllErrors());
        return "module/billing/main/ambulanceBillAdd";
    }

    BillingService billingService = (BillingService) Context.getService(BillingService.class);

    AmbulanceBill ambulanceBill = billingService.getAmbulanceBillById(ambulanceBillId);

    if ("void".equalsIgnoreCase(action)) {
        ambulanceBill.setVoided(true);
        ambulanceBill.setVoidedDate(new Date());
        for (AmbulanceBillItem item : ambulanceBill.getBillItems()) {
            item.setVoided(true);
            item.setVoidedDate(new Date());
        }
        billingService.saveAmbulanceBill(ambulanceBill);
        return "redirect:/module/billing/ambulanceBill.list?driverId=" + driverId;
    }

    ambulanceBill.setPrinted(false);

    // void old items and reset amount
    Map<Integer, AmbulanceBillItem> mapOldItems = new HashMap<Integer, AmbulanceBillItem>();
    for (AmbulanceBillItem item : ambulanceBill.getBillItems()) {
        item.setVoided(true);
        item.setVoidedDate(new Date());
        mapOldItems.put(item.getAmbulanceBillItemId(), item);
    }
    ambulanceBill.setAmount(BigDecimal.ZERO);

    Ambulance ambulance = null;
    Money itemAmount;
    Money totalAmount = new Money(BigDecimal.ZERO);
    AmbulanceBillItem item;
    for (Integer id : ambulanceIds) {

        ambulance = billingService.getAmbulanceById(id);
        BigDecimal amount = new BigDecimal(request.getParameter(id + "_amount"));
        itemAmount = new Money(amount);
        totalAmount = totalAmount.plus(itemAmount);

        Integer numberOfTrip = Integer.parseInt(request.getParameter(id + "_numOfTrip"));

        //ghanshyam 9-august-2012 New Requirement #333 [Billing]Edit ambulance bill with all details
        String patientName = (request.getParameter(id + "_patientName"));
        String receiptNumber = (request.getParameter(id + "_receiptNumber"));
        String origin = (request.getParameter(id + "_origin"));
        String destination = (request.getParameter(id + "_destination"));

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

        if (sItemId != null) {
            item = mapOldItems.get(Integer.parseInt(sItemId));
            item.setVoided(false);
            item.setVoidedDate(null);
            item.setAmount(itemAmount.getAmount());
            item.setNumberOfTrip(numberOfTrip);
            //ghanshyam 9-august-2012 New Requirement #333 [Billing]Edit ambulance bill with all details
            item.setPatientName(patientName);
            item.setReceiptNumber(receiptNumber);
            item.setOrigin(origin);
            item.setDestination(destination);
        } else {
            item = new AmbulanceBillItem();
            item.setName(ambulance.getName());
            item.setCreatedDate(new Date());
            item.setAmbulance(ambulance);
            item.setAmbulanceBill(ambulanceBill);
            item.setAmount(itemAmount.getAmount());
            item.setNumberOfTrip(numberOfTrip);
            //ghanshyam 9-august-2012 New Requirement #333 [Billing]Edit ambulance bill with all details
            item.setPatientName(patientName);
            item.setReceiptNumber(receiptNumber);
            item.setOrigin(origin);
            item.setDestination(destination);
            ambulanceBill.addBillItem(item);
        }
    }
    ambulanceBill.setAmount(totalAmount.getAmount());
    ambulanceBill = billingService.saveAmbulanceBill(ambulanceBill);

    return "redirect:/module/billing/ambulanceBill.list?driverId=" + driverId + "&ambulanceBillId="
            + ambulanceBill.getAmbulanceBillId();
}

From source file:alfio.manager.EventStatisticsManager.java

public EventWithAdditionalInfo getEventWithAdditionalInfo(String eventName, String username) {
    Event event = getEventAndCheckOwnership(eventName, username);
    Map<String, String> description = eventDescriptionRepository.findByEventIdAsMap(event.getId());
    boolean owner = userManager.isOwner(userManager.findUserByUsername(username));
    EventStatisticView statistics = owner ? eventRepository.findStatisticsFor(event.getId())
            : EventStatisticView.empty(event.getId());
    EventStatistic eventStatistic = new EventStatistic(event, statistics, displayStatisticsForEvent(event));
    BigDecimal grossIncome = owner ? MonetaryUtil.centsToUnit(eventRepository.getGrossIncome(event.getId()))
            : BigDecimal.ZERO;

    List<TicketCategory> ticketCategories = loadTicketCategories(event);
    List<Integer> ticketCategoriesIds = ticketCategories.stream().map(TicketCategory::getId)
            .collect(Collectors.toList());

    Map<Integer, Map<String, String>> descriptions = ticketCategoryDescriptionRepository
            .descriptionsByTicketCategory(ticketCategoriesIds);
    Map<Integer, TicketCategoryStatisticView> ticketCategoriesStatistics = owner
            ? ticketCategoryRepository.findStatisticsForEventIdByCategoryId(event.getId())
            : ticketCategoriesIds.stream().collect(
                    toMap(Function.identity(), id -> TicketCategoryStatisticView.empty(id, event.getId())));
    Map<Integer, List<SpecialPrice>> specialPrices = ticketCategoriesIds.isEmpty() ? Collections.emptyMap()
            : specialPriceRepository.findAllByCategoriesIdsMapped(ticketCategoriesIds);

    List<TicketCategoryWithAdditionalInfo> tWithInfo = ticketCategories.stream()
            .map(t -> new TicketCategoryWithAdditionalInfo(event, t, ticketCategoriesStatistics.get(t.getId()),
                    descriptions.get(t.getId()), specialPrices.get(t.getId())))
            .collect(Collectors.toList());

    return new EventWithAdditionalInfo(event, tWithInfo, eventStatistic, description, grossIncome);
}

From source file:cz.muni.fi.dndtroops.test.TroopDaoImplTest.java

@Test
public void testFindTroopByName() {
    Troop troopE = new Troop();
    troopE.setName("E");
    troopE.setMoney(BigDecimal.ZERO);
    troopE.setMission("mise E");
    troopDao.createTroop(troopE);// w  ww . j av a 2s. co m
    Troop t1 = troopDao.findTroopById(troopE.getId());

    Assert.assertEquals(t1.getName(), "E");
    Assert.assertEquals(t1.getMission(), "mise E");

}

From source file:de.hybris.platform.b2bacceleratorservices.jalo.promotions.ProductPriceDiscountPromotionByPaymentType.java

@Override
public List<PromotionResult> evaluate(final SessionContext ctx, final PromotionEvaluationContext promoContext) {
    final List<PromotionResult> promotionResults = new ArrayList<PromotionResult>();
    // Find all valid products in the cart
    final PromotionsManager.RestrictionSetResult restrictionResult = this.findEligibleProductsInBasket(ctx,
            promoContext);//www .j a  va2  s  .c  o  m

    if (restrictionResult.isAllowedToContinue() && !restrictionResult.getAllowedProducts().isEmpty()) {
        final PromotionOrderView view = promoContext.createView(ctx, this,
                restrictionResult.getAllowedProducts());
        final AbstractOrder order = promoContext.getOrder();

        for (final PromotionOrderEntry entry : view.getAllEntries(ctx)) {
            // Get the next order entry
            final long quantityToDiscount = entry.getQuantity(ctx);
            if (quantityToDiscount > 0) {
                final long quantityOfOrderEntry = entry.getBaseOrderEntry().getQuantity(ctx).longValue();

                // The adjustment to the order entry
                final double originalUnitPrice = entry.getBasePrice(ctx).doubleValue();
                final double originalEntryPrice = quantityToDiscount * originalUnitPrice;

                final Currency currency = promoContext.getOrder().getCurrency(ctx);
                Double discountPriceValue;

                final EnumerationValue paymentType = B2BAcceleratorServicesManager.getInstance()
                        .getPaymentType(ctx, order);

                if (paymentType != null
                        && StringUtils.equalsIgnoreCase(paymentType.getCode(), getPaymentType().getCode())) {
                    promoContext.startLoggingConsumed(this);
                    discountPriceValue = this.getPriceForOrder(ctx, this.getProductDiscountPrice(ctx),
                            promoContext.getOrder(),
                            ProductPriceDiscountPromotionByPaymentType.PRODUCTDISCOUNTPRICE);

                    final BigDecimal adjustedEntryPrice = Helper.roundCurrencyValue(ctx, currency,
                            originalEntryPrice - (quantityToDiscount * discountPriceValue.doubleValue()));
                    // Calculate the unit price and round it
                    final BigDecimal adjustedUnitPrice = Helper.roundCurrencyValue(ctx, currency,
                            adjustedEntryPrice.equals(BigDecimal.ZERO) ? BigDecimal.ZERO
                                    : adjustedEntryPrice.divide(BigDecimal.valueOf(quantityToDiscount),
                                            RoundingMode.HALF_EVEN));

                    for (final PromotionOrderEntryConsumed poec : view.consume(ctx, quantityToDiscount)) {
                        poec.setAdjustedUnitPrice(ctx, adjustedUnitPrice.doubleValue());
                    }

                    final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx,
                            this, promoContext.getOrder(), 1.0F);
                    result.setConsumedEntries(ctx, promoContext.finishLoggingAndGetConsumed(this, true));
                    final BigDecimal adjustment = Helper.roundCurrencyValue(ctx, currency,
                            adjustedEntryPrice.subtract(BigDecimal.valueOf(originalEntryPrice)));
                    final PromotionOrderEntryAdjustAction poeac = PromotionsManager.getInstance()
                            .createPromotionOrderEntryAdjustAction(ctx, entry.getBaseOrderEntry(),
                                    quantityOfOrderEntry, adjustment.doubleValue());
                    result.addAction(ctx, poeac);
                    promotionResults.add(result);
                }
            }
        }
        final long remainingCount = view.getTotalQuantity(ctx);
        if (remainingCount > 0) {
            promoContext.startLoggingConsumed(this);
            view.consume(ctx, remainingCount);
            final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx, this,
                    promoContext.getOrder(), 0.5F);
            result.setConsumedEntries(ctx, promoContext.finishLoggingAndGetConsumed(this, false));
            promotionResults.add(result);
        }
    }
    return promotionResults;
}

From source file:com.sasav.blackjack.service.GameCore.java

public Game createNewGame(LoginDetails loginDetails) {
    Game game = getUserGame(loginDetails);
    boolean noError = false;
    if (game == null) {
        game = new Game(loginDetails, null, null, (ArrayList<Card>) DEFAULT_CARD_DECK.clone(), BigDecimal.ZERO,
                GameStatus.NEW);/*from   w  w  w  .j  a v a2  s .  c  om*/
        noError = commonDao.saveOrUpdate(game);

    }
    return noError ? game : null;
}