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:org.openvpms.archetype.rules.stock.ChargeStockUpdaterTestCase.java
/** * Verifies that stock is updated when for a charge. * * @param acts the charge act and item/*from ww w .java 2s . c o m*/ */ private void checkStockUpdate(List<FinancialAct> acts) { FinancialAct item = acts.get(1); BigDecimal initialQuantity = BigDecimal.ZERO; BigDecimal quantity = BigDecimal.valueOf(5); Product product2 = TestHelper.createProduct(); boolean credit = TypeHelper.isA(item, CustomerAccountArchetypes.CREDIT_ITEM); BigDecimal expected = getQuantity(initialQuantity, quantity, credit); item.setQuantity(quantity); checkEquals(initialQuantity, getStock(stockLocation, product)); save(acts); checkEquals(expected, getStock(stockLocation, product)); save(acts); // stock shouldn't change if resaved checkEquals(expected, getStock(stockLocation, product)); item = get(item); BigDecimal updatedQty = new BigDecimal(10); item.setQuantity(updatedQty); expected = getQuantity(initialQuantity, updatedQty, credit); save(item); checkEquals(expected, getStock(stockLocation, product)); item = get(item); save(item); checkEquals(expected, getStock(stockLocation, product)); ActBean itemBean = new ActBean(item); itemBean.setParticipant(ProductArchetypes.PRODUCT_PARTICIPATION, product2); save(item); checkEquals(BigDecimal.ZERO, getStock(stockLocation, product)); checkEquals(expected, getStock(stockLocation, product2)); }
From source file:com.qcadoo.mes.productionScheduling.listeners.OrderTimePredictionListeners.java
@Transactional public void changeRealizationTime(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent technologyLookup = (FieldComponent) view.getComponentByReference(OrderFields.TECHNOLOGY); FieldComponent plannedQuantityField = (FieldComponent) view .getComponentByReference(OrderFields.PLANNED_QUANTITY); FieldComponent dateFromField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_FROM); FieldComponent dateToField = (FieldComponent) view.getComponentByReference(OrderFields.DATE_TO); FieldComponent productionLineLookup = (FieldComponent) view .getComponentByReference(OrderFields.PRODUCTION_LINE); boolean isGenerated = false; if (technologyLookup.getFieldValue() == null) { technologyLookup.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE); return;// w w w. ja v a 2s . com } if (!StringUtils.hasText((String) dateFromField.getFieldValue())) { dateFromField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE); return; } if (!StringUtils.hasText((String) plannedQuantityField.getFieldValue())) { plannedQuantityField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE); return; } if (productionLineLookup.getFieldValue() == null) { productionLineLookup.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE); return; } BigDecimal quantity = null; Object value = plannedQuantityField.getFieldValue(); if (value instanceof BigDecimal) { quantity = (BigDecimal) value; } else { try { ParsePosition parsePosition = new ParsePosition(0); String trimedValue = value.toString().replaceAll(" ", ""); DecimalFormat formatter = (DecimalFormat) NumberFormat.getNumberInstance(view.getLocale()); formatter.setParseBigDecimal(true); quantity = new BigDecimal(String.valueOf(formatter.parseObject(trimedValue, parsePosition))); } catch (NumberFormatException e) { plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidNumericFormat", MessageType.FAILURE); return; } } int scale = quantity.scale(); if (MAX != null && scale > MAX) { plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidScale.max", MessageType.FAILURE, MAX.toString()); return; } int presicion = quantity.precision() - scale; if (MAX != null && presicion > MAX) { plannedQuantityField.addMessage("qcadooView.validate.field.error.invalidPrecision.max", MessageType.FAILURE, MAX.toString()); return; } if (BigDecimal.ZERO.compareTo(quantity) >= 0) { plannedQuantityField.addMessage("qcadooView.validate.field.error.outOfRange.toSmall", MessageType.FAILURE); return; } int maxPathTime = 0; Entity technology = dataDefinitionService .get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY) .get((Long) technologyLookup.getFieldValue()); Validate.notNull(technology, "technology is null"); if (technology.getStringField(TechnologyFields.STATE).equals(TechnologyState.DRAFT.getStringValue()) || technology.getStringField(TechnologyFields.STATE) .equals(TechnologyState.OUTDATED.getStringValue())) { technologyLookup.addMessage("productionScheduling.technology.incorrectState", MessageType.FAILURE); return; } FieldComponent laborWorkTimeField = (FieldComponent) view .getComponentByReference(OrderFieldsPS.LABOR_WORK_TIME); FieldComponent machineWorkTimeField = (FieldComponent) view .getComponentByReference(OrderFieldsPS.MACHINE_WORK_TIME); FieldComponent includeTpzField = (FieldComponent) view.getComponentByReference(OrderFieldsPS.INCLUDE_TPZ); FieldComponent includeAdditionalTimeField = (FieldComponent) view .getComponentByReference(OrderFieldsPS.INCLUDE_ADDITIONAL_TIME); Boolean includeTpz = "1".equals(includeTpzField.getFieldValue()); Boolean includeAdditionalTime = "1".equals(includeAdditionalTimeField.getFieldValue()); Entity productionLine = dataDefinitionService .get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE) .get((Long) productionLineLookup.getFieldValue()); final Map<Long, BigDecimal> operationRuns = Maps.newHashMap(); productQuantitiesService.getProductComponentQuantities(technology, quantity, operationRuns); OperationWorkTime workTime = operationWorkTimeService.estimateTotalWorkTimeForTechnology(technology, operationRuns, includeTpz, includeAdditionalTime, productionLine, true); laborWorkTimeField.setFieldValue(workTime.getLaborWorkTime()); machineWorkTimeField.setFieldValue(workTime.getMachineWorkTime()); maxPathTime = orderRealizationTimeService.estimateOperationTimeConsumption( technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(), quantity, includeTpz, includeAdditionalTime, productionLine); if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) { state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", MessageType.FAILURE); dateToField.setFieldValue(null); } else { Date startTime = DateUtils.parseDate(dateFromField.getFieldValue()); if (startTime == null) { dateFromField.addMessage("orders.validate.global.error.dateFromIsNull", MessageType.FAILURE); } else { Date stopTime = shiftsService.findDateToForOrder(startTime, maxPathTime); if (stopTime == null) { orderForm.addMessage("productionScheduling.timenorms.isZero", MessageType.FAILURE, false); dateToField.setFieldValue(null); } else { dateToField.setFieldValue(orderRealizationTimeService.setDateToField(stopTime)); startTime = shiftsService.findDateFromForOrder(stopTime, maxPathTime); scheduleOperationComponents(technology.getId(), startTime); isGenerated = true; } if (startTime != null) { orderForm.addMessage("orders.dateFrom.info.dateFromSetToFirstPossible", MessageType.INFO, false); } } } laborWorkTimeField.requestComponentUpdateState(); machineWorkTimeField.requestComponentUpdateState(); dateFromField.requestComponentUpdateState(); dateToField.requestComponentUpdateState(); orderForm.setEntity(orderForm.getEntity()); state.performEvent(view, "refresh", new String[0]); if (isGenerated) { orderForm.addMessage("productionScheduling.info.calculationGenerated", MessageType.SUCCESS); } }
From source file:com.opensky.osis.BraintreeConnector.java
/** * Refund the given transaction//from w w w . j a v a 2 s. c om * * {@sample.xml ../../../doc/braintree-connector.xml.sample braintree:refund} * * @param txId Transaction id * @param amount The amount * @return The result */ @Processor public Result refund(String txId, @Optional BigDecimal amount) { log.info("Refunding tx {} by {}", txId, amount); Result<Transaction> result; if (null == amount) { result = getGateway().transaction().refund(txId); } else { Validate.isTrue(amount.compareTo(BigDecimal.ZERO) >= 0, "amount must be >= 0"); result = getGateway().transaction().refund(txId, amount); } log.debug("Refund {}", result); return result; }
From source file:it.govpay.core.utils.RtUtils.java
private static void validaSemanticaSingoloVersamento(CtDatiSingoloVersamentoRPT singoloVersamento, CtDatiSingoloPagamentoRT singoloPagamento, EsitoValidazione esito) { valida(singoloPagamento.getCausaleVersamento(), singoloVersamento.getCausaleVersamento(), esito, "CausaleVersamento non corrisponde", true); valida(singoloPagamento.getDatiSpecificiRiscossione(), singoloVersamento.getDatiSpecificiRiscossione(), esito, "DatiSpecificiRiscossione non corrisponde", false); if (singoloPagamento.getSingoloImportoPagato().compareTo(BigDecimal.ZERO) == 0) { if (singoloPagamento.getEsitoSingoloPagamento() == null || singoloPagamento.getEsitoSingoloPagamento().isEmpty()) { esito.addErrore("EsitoSingoloPagamento obbligatorio per pagamenti non eseguiti", false); }/*from ww w . j av a2 s .c o m*/ if (!singoloPagamento.getIdentificativoUnivocoRiscossione().equals("n/a")) { esito.addErrore("IdentificativoUnivocoRiscossione deve essere n/a per pagamenti non eseguiti.", false); } } else if (singoloPagamento.getSingoloImportoPagato() .compareTo(singoloVersamento.getImportoSingoloVersamento()) != 0) { esito.addErrore("Importo di un pagamento [" + singoloPagamento.getSingoloImportoPagato().doubleValue() + "] diverso da quanto richiesto [" + singoloVersamento.getImportoSingoloVersamento().doubleValue() + "]", false); } }
From source file:com.gst.portfolio.shareaccounts.domain.ShareAccountCharge.java
private BigDecimal percentageOf(final BigDecimal value, final BigDecimal percentage) { BigDecimal percentageOf = BigDecimal.ZERO; if (isGreaterThanZero(value)) { final MathContext mc = new MathContext(8, MoneyHelper.getRoundingMode()); final BigDecimal multiplicand = percentage.divide(BigDecimal.valueOf(100l), mc); percentageOf = value.multiply(multiplicand, mc); }//ww w . ja va 2 s .c om return percentageOf; }
From source file:net.sourceforge.fenixedu.domain.Shift.java
public BigDecimal getTotalHours() { Collection<Lesson> lessons = getAssociatedLessonsSet(); BigDecimal lessonTotalHours = BigDecimal.ZERO; for (Lesson lesson : lessons) { lessonTotalHours = lessonTotalHours.add(lesson.getTotalHours()); }/*from ww w. ja v a 2 s. co m*/ return lessonTotalHours; }
From source file:com.feilong.core.lang.NumberUtil.java
/** * ?.//w ww .ja va 2 s. c o m * * <h3>:</h3> * * <blockquote> * * <pre class="code"> * NumberUtil.getAddValue(2, 4, 5) = 11 * NumberUtil.getAddValue(new BigDecimal(6), 5) = 11 * </pre> * * </blockquote> * * @param numbers * the numbers * @return <code>numbers</code> null, {@link NullPointerException}<br> * null, {@link IllegalArgumentException}<br> * ????{@link BigDecimal},? * @since 1.5.5 */ public static BigDecimal getAddValue(Number... numbers) { Validate.noNullElements(numbers, "numbers can't be null!"); BigDecimal sum = BigDecimal.ZERO; for (Number number : numbers) { sum = sum.add(toBigDecimal(number)); } return sum; }
From source file:edu.byu.softwareDistribution.web.controller.shopper.ShoppingCartController.java
@RequestMapping(value = "/shop/shoppingCart/updateTotalPrice") public @ResponseBody BigDecimal updateTotalPrice() { if (cart == null) return BigDecimal.ZERO; return cart.getTotalPrice(); }
From source file:net.sourceforge.fenixedu.domain.residence.StudentsPerformanceReport.java
private BigDecimal getB(final Student student) { return getNumberOfApprovedCourses(student) == 0 ? BigDecimal.ZERO : new BigDecimal(getApprovedGradeValuesSum(student)) .divide(new BigDecimal(getNumberOfApprovedCourses(student)), 2, RoundingMode.HALF_EVEN); }