List of usage examples for java.math BigDecimal ZERO
BigDecimal ZERO
To view the source code for java.math BigDecimal ZERO.
Click Source Link
From source file:py.una.pol.karaku.test.test.FormatProviderTest.java
@Test public void testNumbrerFormat() { assertEquals("1.000.000.000.000", fp.asNumber(veryLarge)); assertEquals("100.000", fp.asNumber(large)); assertEquals("100", fp.asNumber(small)); assertEquals("1", fp.asNumber(verySmall)); assertEquals("0", fp.asNumber(BigDecimal.ZERO)); assertEquals("0,11", fp.asNumber(decimal)); assertEquals("0,12", fp.asNumber(decimalUP)); assertEquals("0,01", fp.asNumber(smallDecimal)); assertEquals("0,02", fp.asNumber(smallDecimalUP)); }
From source file:org.openvpms.archetype.rules.stock.ChargeStockUpdaterTestCase.java
/** * Verifies that stock is updated correctly if an item is saved twice in the one transaction, but the first * save is incomplete./*from w w w. jav a 2 s . c o m*/ */ @Test public void testPartialSaveInTxn() { final List<FinancialAct> acts = createInvoice(); final FinancialAct invoice = acts.get(0); final FinancialAct item = acts.get(1); BigDecimal initialQuantity = BigDecimal.ZERO; BigDecimal quantity = BigDecimal.valueOf(5); item.setQuantity(quantity); checkEquals(initialQuantity, getStock(stockLocation, product)); BigDecimal expected = getQuantity(initialQuantity, quantity, false); TransactionTemplate template = new TransactionTemplate(txnManager); template.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { save(item); save(item); save(invoice); } }); checkEquals(expected, getStock(stockLocation, product)); save(acts); // stock shouldn't change if resaved checkEquals(expected, getStock(stockLocation, product)); }
From source file:org.openvpms.component.business.service.archetype.ArchetypeServiceActTestCase.java
/** * Tests OVPMS-211./*from w w w. j av a 2s .c o m*/ */ @Test public void testOVPMS211() { Act estimationItem1 = (Act) create("act.customerEstimationItem"); ActBean estimationItem1Bean = new ActBean(estimationItem1); estimationItem1Bean.setValue("fixedPrice", "1.0"); estimationItem1Bean.setValue("lowQty", "2.0"); estimationItem1Bean.setValue("lowUnitPrice", "3.0"); estimationItem1Bean.setValue("highQty", "4.0"); estimationItem1Bean.setValue("highUnitPrice", "5.0"); estimationItem1Bean.save(); Act estimation = (Act) create("act.customerEstimation"); ActBean estimationBean = new ActBean(estimation); estimationBean.setValue("status", "IN_PROGRESS"); estimationBean.addRelationship("actRelationship.customerEstimationItem", estimationItem1); Act estimationItem2 = (Act) create("act.customerEstimationItem"); ActBean estimationItem2Bean = new ActBean(estimationItem2); estimationItem2Bean.setValue("fixedPrice", "2.0"); estimationItem2Bean.setValue("lowQty", "3.0"); estimationItem2Bean.setValue("lowUnitPrice", "4.0"); estimationItem2Bean.setValue("highQty", "5.0"); estimationItem2Bean.setValue("highUnitPrice", "6.0"); estimationItem2Bean.save(); estimationBean.addRelationship("actRelationship.customerEstimationItem", estimationItem2); estimationBean.save(); // reload the estimation estimation = reload(estimation); estimationBean = new ActBean(estimation); // verify low & high totals have been calculated BigDecimal lowTotal = estimationBean.getBigDecimal("lowTotal"); BigDecimal highTotal = estimationBean.getBigDecimal("highTotal"); assertTrue(lowTotal.compareTo(BigDecimal.ZERO) > 0); assertTrue(highTotal.compareTo(BigDecimal.ZERO) > 0); }
From source file:com.nkapps.billing.dao.OverpaymentDaoImpl.java
@Override public void returnStateCommit(Session session, BankStatement bs, BigDecimal returnSum, Long issuerSerialNumber, String issuerIp, LocalDateTime dateTime) throws Exception { if (!bs.getBankStatementPayments().isEmpty()) { // if bankstatement has payments String q = " SELECT p.id AS id, p.tin AS tin, p.paymentNum AS paymentNum, p.paymentDate AS paymentDate," + " p.paymentSum AS paymentSum, p.sourceCode AS sourceCode," + " p.state AS state, p.tinDebtor as tinDebtor,p.claim as claim, p.issuerSerialNumber as issuerSerialNumber," + " p.issuerIp as issuerIp,p.dateCreated AS dateCreated, p.dateUpdated as dateUpdated, " + " p.paymentSum - COALESCE((SELECT SUM(paidSum) FROM KeyPayment kp WHERE kp.payment = p),0) AS overSum " + " FROM Payment p JOIN p.bankStatementPayment bsp " + " WHERE p.state IN (1,2) AND p.claim = 0 " + " AND bsp.id.bankStatement = :bs" + " ORDER BY p.paymentDate, p.paymentNum "; Query query = session.createQuery(q); query.setParameter("bs", bs); query.setResultTransformer(Transformers.aliasToBean(Payment.class)); List<Payment> paymentList = query.list(); for (Payment payment : paymentList) { if (payment.getOverSum().compareTo(returnSum) <= 0) { payment.setPaymentSum(payment.getPaymentSum().subtract(payment.getOverSum())); payment.setState((short) 3); // payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); returnSum = returnSum.subtract(payment.getOverSum()); } else { payment.setPaymentSum(payment.getPaymentSum().subtract(returnSum)); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); returnSum = BigDecimal.ZERO; }/*from w w w.j av a2s . c o m*/ if (returnSum.compareTo(BigDecimal.ZERO) <= 0) { break; } } } }
From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsReservationsController.java
@Override public ModelAndView postEditView(@ModelAttribute("Model") ReservationRequest reservationRequest, HttpServletRequest request, BindingResult bindingResult) { ModelAndView addView = getAddView(reservationRequest); validator.validate(reservationRequest, bindingResult); if (bindingResult.hasErrors()) { return addView; }/*from www . j ava 2 s . c o m*/ try { Player player = sessionUtil.getUser(request); //calculate reservation bookings, taking into account holidays LocalDate date = reservationRequest.getStartDate(); LocalDate endDate = reservationRequest.getEndDate(); List<Booking> bookings = new ArrayList<>(); List<Booking> failedBookings = new ArrayList<>(); LocalDateTime blockingTime = new LocalDateTime(); while (date.compareTo(endDate) <= 0) { Set<CalendarWeekDay> calendarWeekDays = reservationRequest.getCalendarWeekDays(); for (CalendarWeekDay calendarWeekDay : calendarWeekDays) { if (calendarWeekDay.ordinal() + 1 == date.getDayOfWeek()) { try { List<CalendarConfig> calendarConfigs = calendarConfigDAO.findFor(date); //throws CalendarConfigException Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (!bookingUtil.isHoliday(date, calendarConfig)) { for (Offer offer : reservationRequest.getOffers()) { Booking booking = new Booking(); booking.setAmount(BigDecimal.ZERO); booking.setBlockingTime(blockingTime); booking.setBookingDate(date); booking.setBookingTime(reservationRequest.getStartTime()); booking.setBookingType(BookingType.reservation); booking.setComment(reservationRequest.getComment()); booking.setConfirmed(Boolean.TRUE); booking.setCurrency(Currency.EUR); booking.setDuration(getDuration(reservationRequest, calendarConfig)); booking.setPaymentConfirmed(reservationRequest.getPaymentConfirmed()); booking.setPaymentMethod(PaymentMethod.Reservation); booking.setPlayer(player); booking.setUUID(BookingUtil.generateUUID()); booking.setOffer(offer); booking.setPublicBooking(reservationRequest.getPublicBooking()); //we call this inside the loop to prevent overbooking List<Booking> confirmedBookings = bookingDAO .findBlockedBookingsForDate(date); OfferDurationPrice offerDurationPrice = bookingUtil.getOfferDurationPrice( calendarConfigs, confirmedBookings, booking.getBookingDate(), booking.getBookingTime(), offer); if (offerDurationPrice == null) { failedBookings.add(booking); continue; } else { BigDecimal price = offerDurationPrice.getDurationPriceMap() .get(booking.getDuration().intValue()); booking.setAmount(price); } TimeSlot timeSlot = new TimeSlot(); timeSlot.setDate(date); timeSlot.setStartTime(reservationRequest.getStartTime()); timeSlot.setEndTime(reservationRequest.getEndTime()); timeSlot.setConfig(calendarConfig); Long bookingSlotsLeft = bookingUtil.getBookingSlotsLeft(timeSlot, offer, confirmedBookings); if (bookingSlotsLeft < 1) { failedBookings.add(booking); continue; } //we save the booking directly to prevent overbookings booking = bookingDAO.saveOrUpdate(booking); bookings.add(booking); } } break; } break; } catch (CalendarConfigException e) { LOG.warn( "Caught calendar config exception during add reservation request. This may be normal (for holidays)", e); Booking failedBooking = new Booking(); failedBooking.setPlayer(player); failedBooking.setBookingDate(date); failedBooking.setBookingTime(reservationRequest.getStartTime()); failedBookings.add(failedBooking); } } } date = date.plusDays(1); } if (!failedBookings.isEmpty()) { throw new Exception(msg.get("UnableToReserveAllDesiredTimes", new Object[] { StringUtils.join(bookings, "<br/>"), StringUtils.join(failedBookings, "<br/>") })); } if (bookings.isEmpty()) { throw new Exception(msg.get("NoCourtReservationsForSelectedDateTime")); } return new ModelAndView("redirect:/admin/bookings/reservations"); } catch (Exception e) { LOG.error(e, e); bindingResult.addError(new ObjectError("comment", e.getMessage())); return addView; } }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSF424V1_2Generator.java
/** * // w w w . j a v a 2 s . c om * This method is to get estimated project funds for RRSF424 * * @return EstimatedProjectFunding estimated total cost for the project. */ private EstimatedProjectFunding getProjectFunding() { EstimatedProjectFunding funding = EstimatedProjectFunding.Factory.newInstance(); funding.setTotalEstimatedAmount(BigDecimal.ZERO); funding.setTotalNonfedrequested(BigDecimal.ZERO); funding.setTotalfedNonfedrequested(BigDecimal.ZERO); funding.setEstimatedProgramIncome(BigDecimal.ZERO); boolean hasBudgetLineItem = false; ProposalDevelopmentBudgetExtContract budget = s2SCommonBudgetService .getBudget(pdDoc.getDevelopmentProposal()); if (budget != null) { ScaleTwoDecimal totalCost = ScaleTwoDecimal.ZERO; if (budget.getModularBudgetFlag()) { ScaleTwoDecimal fundsRequested = ScaleTwoDecimal.ZERO; ScaleTwoDecimal totalDirectCost = ScaleTwoDecimal.ZERO; // get modular budget amounts instead of budget detail amounts for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) { if (budgetPeriod.getBudgetModular() == null) { getAuditErrors() .add(s2SErrorHandlerService.getError(MODULAR_BUDGET_REQUIRED, getFormName())); break; } else { totalDirectCost = totalDirectCost.add(budgetPeriod.getBudgetModular().getTotalDirectCost()); for (BudgetModularIdcContract budgetModularIdc : budgetPeriod.getBudgetModular() .getBudgetModularIdcs()) { fundsRequested = fundsRequested.add(budgetModularIdc.getFundsRequested()); } } } totalCost = totalCost.add(totalDirectCost); totalCost = totalCost.add(fundsRequested); } else { totalCost = budget.getTotalCost(); } ScaleTwoDecimal fedNonFedCost = totalCost; ScaleTwoDecimal costSharingAmount = ScaleTwoDecimal.ZERO; for (BudgetPeriodContract budgetPeriod : budget.getBudgetPeriods()) { for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) { hasBudgetLineItem = true; if (budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag()) { costSharingAmount = costSharingAmount.add(lineItem.getCostSharingAmount()); List<? extends BudgetLineItemCalculatedAmountContract> calculatedAmounts = lineItem .getBudgetLineItemCalculatedAmounts(); for (BudgetLineItemCalculatedAmountContract budgetLineItemCalculatedAmount : calculatedAmounts) { costSharingAmount = costSharingAmount .add(budgetLineItemCalculatedAmount.getCalculatedCostSharing()); } } } } if (!hasBudgetLineItem && budget.getSubmitCostSharingFlag()) { costSharingAmount = budget.getCostSharingAmount(); } fedNonFedCost = fedNonFedCost.add(costSharingAmount); funding = EstimatedProjectFunding.Factory.newInstance(); funding.setTotalEstimatedAmount(totalCost.bigDecimalValue()); funding.setTotalNonfedrequested(costSharingAmount.bigDecimalValue()); funding.setTotalfedNonfedrequested(fedNonFedCost.bigDecimalValue()); funding.setEstimatedProgramIncome(getTotalProjectIncome(budget)); } return funding; }
From source file:uk.dsxt.voting.tests.TestDataGenerator.java
private static VoteResult generateVote(String id, HashMap<String, BigDecimal> securities, Voting voting) { VoteResult vote = new VoteResult(voting.getId(), id, securities.get(SECURITY)); for (int j = 0; j < voting.getQuestions().length; j++) { String questionId = voting.getQuestions()[j].getId(); if (voting.getQuestions()[j].isCanSelectMultiple()) { BigDecimal totalSum = BigDecimal.ZERO; for (int i = 0; i < voting.getQuestions()[j].getAnswers().length; i++) { String answerId = voting.getQuestions()[j].getAnswers()[i].getId(); int amount = randomInt(0, vote.getPacketSize().subtract(totalSum).intValue()); BigDecimal voteAmount = new BigDecimal(amount); totalSum = totalSum.add(voteAmount); if (voteAmount.compareTo(BigDecimal.ZERO) > 0) vote.setAnswer(questionId, answerId, voteAmount); }/*w w w . j av a2 s . com*/ } else { String answerId = voting.getQuestions()[j].getAnswers()[randomInt(0, voting.getQuestions()[j].getAnswers().length - 1)].getId(); BigDecimal voteAmount = new BigDecimal(randomInt(0, vote.getPacketSize().intValue())); if (voteAmount.compareTo(BigDecimal.ZERO) > 0) vote.setAnswer(questionId, answerId, voteAmount); } } return vote; }
From source file:org.businessmanager.web.controller.page.invoice.InvoiceEditController.java
public BigDecimal getTotalNetPrice() { BigDecimal totalNetPrice = BigDecimal.ZERO; for (LineItemBean lineItem : bean.getLineItems()) { BigDecimal sumPrice = lineItem.getSumPriceNet(); totalNetPrice = totalNetPrice.add(sumPrice); }// www . j a v a 2s.com return totalNetPrice.setScale(2, RoundingMode.HALF_UP); }
From source file:com.eventsourcing.postgresql.PostgreSQLJournalTest.java
@Test @SneakyThrows//w w w . j a v a 2 s . co m public void serializationNull() { HybridTimestamp timestamp = new HybridTimestamp(timeProvider); timestamp.update(); Journal.Transaction tx = journal.beginTransaction(); SerializationEvent event = SerializationEvent.builder().test(TestClass.builder().build()).build(); event = (SerializationEvent) journal.journal(tx, event); tx.rollback(); TestClass test = event.getTest(); assertEquals(test.pByte, 0); assertEquals(test.oByte, Byte.valueOf((byte) 0)); assertEquals(test.pByteArr.length, 0); assertEquals(test.oByteArr.length, 0); assertEquals(test.pShort, 0); assertEquals(test.oShort, Short.valueOf((short) 0)); assertEquals(test.pInt, 0); assertEquals(test.oInt, Integer.valueOf(0)); assertEquals(test.pLong, 0); assertEquals(test.oLong, Long.valueOf(0)); assertTrue(test.pFloat == 0.0); assertEquals(test.oFloat, Float.valueOf((float) 0.0)); assertEquals(test.pDouble, 0.0); assertEquals(test.oDouble, Double.valueOf(0.0)); assertEquals(test.pBoolean, false); assertEquals(test.oBoolean, Boolean.FALSE); assertEquals(test.str, ""); assertEquals(test.uuid, new UUID(0, 0)); assertEquals(test.e, TestClass.E.A); assertNotNull(test.value); assertEquals(test.value.value, ""); assertNotNull(test.value1); assertTrue(test.value1.value().isEmpty()); assertNotNull(test.list); assertEquals(test.list.size(), 0); assertNotNull(test.map); assertEquals(test.map.size(), 0); assertNotNull(test.optional); assertFalse(test.optional.isPresent()); assertNotNull(test.bigDecimal); assertEquals(test.bigDecimal, BigDecimal.ZERO); assertNotNull(test.bigInteger); assertEquals(test.bigInteger, BigInteger.ZERO); assertNotNull(test.date); assertEquals(test.date, new Date(0)); }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRBudget10V1_4Generator.java
private BudgetSummary getBudgetSummary(BudgetSummaryDto budgetSummaryData) { BudgetSummary budgetSummary = BudgetSummary.Factory.newInstance(); OtherDirectCostInfoDto otherDirectCosts = null; if (budgetSummaryData != null) { if (budgetSummaryData.getOtherDirectCosts() != null && budgetSummaryData.getOtherDirectCosts().size() > 0) { otherDirectCosts = budgetSummaryData.getOtherDirectCosts().get(0); }//from w w w. j ava 2 s .co m if (otherDirectCosts != null) { budgetSummary.setCumulativeTotalFundsRequestedSeniorKeyPerson(BigDecimal.ZERO); budgetSummary.setCumulativeTotalFundsRequestedPersonnel(BigDecimal.ZERO); if (budgetSummaryData.getCumTotalFundsForSrPersonnel() != null) { budgetSummary.setCumulativeTotalFundsRequestedSeniorKeyPerson( budgetSummaryData.getCumTotalFundsForSrPersonnel().bigDecimalValue()); } if (budgetSummaryData.getCumTotalFundsForOtherPersonnel() != null) { budgetSummary.setCumulativeTotalFundsRequestedOtherPersonnel( budgetSummaryData.getCumTotalFundsForOtherPersonnel().bigDecimalValue()); } if (budgetSummaryData.getCumNumOtherPersonnel() != null) { budgetSummary.setCumulativeTotalNoOtherPersonnel( budgetSummaryData.getCumNumOtherPersonnel().intValue()); } if (budgetSummaryData.getCumTotalFundsForPersonnel() != null) { budgetSummary.setCumulativeTotalFundsRequestedPersonnel( budgetSummaryData.getCumTotalFundsForPersonnel().bigDecimalValue()); } budgetSummary.setCumulativeTotalFundsRequestedEquipment( budgetSummaryData.getCumEquipmentFunds().bigDecimalValue()); budgetSummary .setCumulativeTotalFundsRequestedTravel(budgetSummaryData.getCumTravel().bigDecimalValue()); budgetSummary.setCumulativeDomesticTravelCosts( budgetSummaryData.getCumDomesticTravel().bigDecimalValue()); budgetSummary .setCumulativeForeignTravelCosts(budgetSummaryData.getCumForeignTravel().bigDecimalValue()); budgetSummary.setCumulativeTotalFundsRequestedTraineeCosts(budgetSummaryData.getpartOtherCost() .add(budgetSummaryData.getpartStipendCost().add(budgetSummaryData.getpartTravelCost().add( budgetSummaryData.getPartTuition().add(budgetSummaryData.getPartSubsistence())))) .bigDecimalValue()); budgetSummary.setCumulativeTraineeStipends(otherDirectCosts.getPartStipends().bigDecimalValue()); budgetSummary .setCumulativeTraineeSubsistence(otherDirectCosts.getPartSubsistence().bigDecimalValue()); budgetSummary.setCumulativeTraineeTravel(otherDirectCosts.getPartTravel().bigDecimalValue()); budgetSummary.setCumulativeTraineeTuitionFeesHealthInsurance( otherDirectCosts.getPartTuition().bigDecimalValue()); budgetSummary.setCumulativeOtherTraineeCost(budgetSummaryData.getpartOtherCost().bigDecimalValue()); budgetSummary.setCumulativeNoofTrainees(budgetSummaryData.getparticipantCount()); budgetSummary.setCumulativeTotalFundsRequestedOtherDirectCosts( otherDirectCosts.gettotalOtherDirect().bigDecimalValue()); budgetSummary.setCumulativeMaterialAndSupplies(otherDirectCosts.getmaterials().bigDecimalValue()); budgetSummary.setCumulativePublicationCosts(otherDirectCosts.getpublications().bigDecimalValue()); budgetSummary.setCumulativeConsultantServices(otherDirectCosts.getConsultants().bigDecimalValue()); budgetSummary.setCumulativeADPComputerServices(otherDirectCosts.getcomputer().bigDecimalValue()); budgetSummary.setCumulativeSubawardConsortiumContractualCosts( otherDirectCosts.getsubAwards().bigDecimalValue()); budgetSummary.setCumulativeEquipmentFacilityRentalFees( otherDirectCosts.getEquipRental().bigDecimalValue()); budgetSummary.setCumulativeAlterationsAndRenovations( otherDirectCosts.getAlterations().bigDecimalValue()); List<Map<String, String>> cvOthers = otherDirectCosts.getOtherCosts(); for (int j = 0; j < cvOthers.size(); j++) { Map<String, String> hmCosts = cvOthers.get(j); if (j == 0) { budgetSummary .setCumulativeOther1DirectCost(new BigDecimal(hmCosts.get(CostConstants.KEY_COST))); } else if (j == 1) { budgetSummary .setCumulativeOther2DirectCost(new BigDecimal(hmCosts.get(CostConstants.KEY_COST))); } else { budgetSummary .setCumulativeOther3DirectCost(new BigDecimal(hmCosts.get(CostConstants.KEY_COST))); } } budgetSummary.setCumulativeTotalFundsRequestedDirectCosts( budgetSummaryData.getCumTotalDirectCosts().bigDecimalValue()); budgetSummary.setCumulativeTotalFundsRequestedIndirectCost( budgetSummaryData.getCumTotalIndirectCosts().bigDecimalValue()); budgetSummary.setCumulativeTotalFundsRequestedDirectIndirectCosts( budgetSummaryData.getCumTotalCosts().bigDecimalValue()); if (budgetSummaryData.getCumFee() != null) { budgetSummary.setCumulativeFee(budgetSummaryData.getCumFee().bigDecimalValue()); } budgetSummary.setCumulativeTotalCostsFee(budgetSummary.getCumulativeFee() != null ? budgetSummary.getCumulativeFee() .add(budgetSummary.getCumulativeTotalFundsRequestedDirectIndirectCosts()) : budgetSummary.getCumulativeTotalFundsRequestedDirectIndirectCosts()); } } return budgetSummary; }