List of usage examples for java.math BigDecimal compareTo
@Override public int compareTo(BigDecimal val)
From source file:nl.b3p.kaartenbalie.struts.WfsPricingAction.java
public ActionForward save(ActionMapping mapping, DynaValidatorForm dynaForm, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("Getting entity manager ......"); EntityManager em = getEntityManager(); request.setAttribute("id", request.getParameter("id")); if (!isTokenValid(request)) { prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, TOKEN_ERROR_KEY); return getAlternateForward(mapping, request); }// w w w . j av a2s .com ActionErrors errors = dynaForm.validate(mapping, request); if (!errors.isEmpty()) { addMessages(request, errors); prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, VALIDATION_ERROR_KEY); return getAlternateForward(mapping, request); } Date validFrom = FormUtils.FormStringToDate(dynaForm.getString("validFrom"), null); Date validUntil = FormUtils.FormStringToDate(dynaForm.getString("validUntil"), null); if (validUntil != null && validFrom != null) { if (validUntil.before(validFrom)) { prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, START_END_ERROR_KEY); return getAlternateForward(mapping, request); } } LayerPricing lp = getLayerPricing(dynaForm, request, true); if (lp == null) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, NOTFOUND_ERROR_KEY); return getAlternateForward(mapping, request); } lp.setValidFrom(validFrom); lp.setValidUntil(validUntil); WfsLayer layer = null; String id = FormUtils.nullIfEmpty(getLayerID(dynaForm)); if (id != null) { layer = getWfsLayerByUniqueName(id); } if (layer == null || layer.getName() == null || layer.getName().trim().length() == 0) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, LAYER_PLACEHOLDER_ERROR_KEY); return getAlternateForward(mapping, request); } lp.setServerProviderPrefix(layer.getSpAbbr()); lp.setLayerName(layer.getName()); lp.setPlanType(FormUtils.StringToInt(dynaForm.getString("planType"))); String service = dynaForm.getString("service"); String operation = null; if (service != null && service.equalsIgnoreCase("WMS")) { operation = dynaForm.getString("operationWMS"); } else if (service != null && service.equalsIgnoreCase("WFS")) { operation = dynaForm.getString("operationWFS"); } else { service = null; } if (operation != null && operation.trim().length() == 0) { operation = null; } lp.setService(service); lp.setOperation(operation); BigDecimal minScale = FormUtils.bdValueNull(dynaForm.getString("minScale")); BigDecimal maxScale = FormUtils.bdValueNull(dynaForm.getString("maxScale")); String projection = dynaForm.getString("projection"); if (projection != null && projection.trim().length() == 0) { projection = null; } if (projection != null && (minScale != null || maxScale != null)) { boolean scaleOK = false; if (minScale != null && minScale.doubleValue() > 0) { if (maxScale != null && maxScale.doubleValue() > 0) { if (maxScale.compareTo(minScale) > 0) { scaleOK = true; } } } if (!scaleOK) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, SCALE_ERROR_KEY); return getAlternateForward(mapping, request); } if (minScale != null) { lp.setMinScale(minScale.setScale(2, RoundingMode.HALF_UP)); } if (maxScale != null) { lp.setMaxScale(maxScale.setScale(2, RoundingMode.HALF_UP)); } lp.setProjection(projection); } BigDecimal unitPrice = FormUtils.bdValueNull(dynaForm.getString("unitPrice")); /* * || door && vervangen. Price is namelijk verplicht en dus nooit null * en hij kwam dus altijd door de check. Ook als het bedrag 0 was. */ if (unitPrice != null && unitPrice.doubleValue() > 0.0) { lp.setUnitPrice(unitPrice.setScale(2, RoundingMode.HALF_UP)); } else { lp.setLayerIsFree(Boolean.TRUE); } em.persist(lp); return super.save(mapping, dynaForm, request, response); }
From source file:op.tools.SYSTools.java
public static void handleBigDecimalFocusLost(FocusEvent evt, BigDecimal min, BigDecimal max, BigDecimal def) { BigDecimal myBD; try {/* w ww .ja v a2 s . c o m*/ myBD = BigDecimal.valueOf( Double.parseDouble(assimilateDecimalSeparators(((JTextField) evt.getSource()).getText()))); } catch (NumberFormatException ex) { OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.wrongentry"))); myBD = def; } if (myBD.compareTo(min) < 0) { myBD = min; OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.entryTooSmall"))); } if (myBD.compareTo(max) > 0) { myBD = max; OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.entryTooBig"))); } ((JTextField) evt.getSource()).setText(myBD.setScale(2, RoundingMode.HALF_UP).toString()); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJNumberEditor.java
public BigDecimal getNumberValue() { final String S_ProcName = "getNumberValue"; BigDecimal retval;/*from www . j ava2 s . com*/ String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Short) { Short s = (Short) obj; BigDecimal v; if (precis > 0) { v = new BigDecimal(s.toString() + "." + S_Zeroes.substring(0, precis)); } else { v = new BigDecimal(s.toString()); } BigDecimal min = getMinValue(); BigDecimal max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Integer) { Integer i = (Integer) obj; BigDecimal v; if (precis > 0) { v = new BigDecimal(i.toString() + "." + S_Zeroes.substring(0, precis)); } else { v = new BigDecimal(i.toString()); } BigDecimal min = getMinValue(); BigDecimal max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Long) { Long l = (Long) obj; BigDecimal v; if (precis > 0) { v = new BigDecimal(l.toString() + "." + S_Zeroes.substring(0, precis)); } else { v = new BigDecimal(l.toString()); } BigDecimal min = getMinValue(); BigDecimal max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof BigDecimal) { BigDecimal v = (BigDecimal) obj; BigDecimal min = getMinValue(); BigDecimal max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Number) { Number n = (Number) obj; BigDecimal v = new BigDecimal(n.toString()); BigDecimal min = getMinValue(); BigDecimal max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number"); } } return (retval); }
From source file:org.fineract.module.stellar.service.BridgeService.java
public BigDecimal adjustVaultIssuedAssets(final String mifosTenantId, final String assetCode, final BigDecimal amount) throws InvalidConfigurationException { final AccountBridgePersistency bridge = accountBridgeRepositoryDecorator.getBridge(mifosTenantId); if (bridge == null) { throw new IllegalArgumentException(mifosTenantId); }//from www . jav a2 s . co m final StellarAccountId stellarVaultAccountId; final char[] stellarVaultAccountPrivateKey; if (bridge.getStellarVaultAccountId() == null) { final KeyPair vaultAccountKeyPair = createVaultAccount(bridge); if (amount.compareTo(BigDecimal.ZERO) <= 0) return BigDecimal.ZERO; stellarVaultAccountId = StellarAccountId.mainAccount(vaultAccountKeyPair.getAccountId()); stellarVaultAccountPrivateKey = vaultAccountKeyPair.getSecretSeed(); } else { stellarVaultAccountId = StellarAccountId.mainAccount(bridge.getStellarVaultAccountId()); stellarVaultAccountPrivateKey = bridge.getStellarVaultAccountPrivateKey(); } final StellarAccountId stellarAccountId = StellarAccountId.mainAccount(bridge.getStellarAccountId()); return horizonServerUtilities.adjustVaultIssuedAssets(stellarAccountId, bridge.getStellarAccountPrivateKey(), stellarVaultAccountId, stellarVaultAccountPrivateKey, assetCode, amount); }
From source file:de.betterform.xml.xforms.ui.Range.java
public void refresh() throws XFormsException { super.refresh(); String tmpValue = (String) this.getValue(); this.datatype = getDatatype(); if (this.datatype.contains(":")) { this.datatype = this.datatype.substring(this.datatype.indexOf(":") + 1, this.datatype.length()); }/*w w w .jav a 2 s . c o m*/ BigDecimal foreignValue = null; if ("int".equals(this.datatype) || "integer".equals(this.datatype) || "float".equals(this.datatype) || "decimal".equals(this.datatype) || "double".equals(this.datatype) || "string".equals(this.datatype)) { if (tmpValue == null || tmpValue.equals("")) tmpValue = "0"; foreignValue = new BigDecimal(tmpValue); } if (this.valueDecimal.compareTo(foreignValue) != 0) { if (endDecimal != null && this.startDecimal != null && (foreignValue.compareTo(this.startDecimal) < 0 || foreignValue.compareTo(endDecimal) > 0)) { this.model.getContainer().dispatch(this.target, XFormsEventNames.OUT_OF_RANGE, null); } else { this.model.getContainer().dispatch(this.target, XFormsEventNames.IN_RANGE, null); } this.valueDecimal = foreignValue; } }
From source file:net.shopxx.entity.Order.java
@Transient public BigDecimal getRefundableAmount() { if (hasExpired() || Order.Status.failed.equals(getStatus()) || Order.Status.canceled.equals(getStatus()) || Order.Status.denied.equals(getStatus())) { BigDecimal refundableAmount = getAmountPaid(); return refundableAmount.compareTo(BigDecimal.ZERO) >= 0 ? refundableAmount : BigDecimal.ZERO; }//from www . j a v a 2 s . c om if (Order.Status.completed.equals(getStatus())) { BigDecimal refundableAmount = getAmountPaid().subtract(getAmount()); return refundableAmount.compareTo(BigDecimal.ZERO) >= 0 ? refundableAmount : BigDecimal.ZERO; } return BigDecimal.ZERO; }
From source file:nl.b3p.kaartenbalie.struts.WmsPricingAction.java
public ActionForward save(ActionMapping mapping, DynaValidatorForm dynaForm, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("Getting entity manager ......"); EntityManager em = getEntityManager(); request.setAttribute("id", request.getParameter("id")); if (!isTokenValid(request)) { prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, TOKEN_ERROR_KEY); return getAlternateForward(mapping, request); }/* w w w .ja v a 2s.com*/ ActionErrors errors = dynaForm.validate(mapping, request); if (!errors.isEmpty()) { addMessages(request, errors); prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, VALIDATION_ERROR_KEY); return getAlternateForward(mapping, request); } Date validFrom = FormUtils.FormStringToDate(dynaForm.getString("validFrom"), null); Date validUntil = FormUtils.FormStringToDate(dynaForm.getString("validUntil"), null); if (validUntil != null && validFrom != null) { if (validUntil.before(validFrom)) { prepareMethod(dynaForm, request, EDIT, LIST); addAlternateMessage(mapping, request, START_END_ERROR_KEY); return getAlternateForward(mapping, request); } } LayerPricing lp = getLayerPricing(dynaForm, request, true); if (lp == null) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, NOTFOUND_ERROR_KEY); return getAlternateForward(mapping, request); } lp.setValidFrom(validFrom); lp.setValidUntil(validUntil); Layer layer = null; String id = FormUtils.nullIfEmpty(getLayerID(dynaForm)); if (id != null) { layer = getLayerByUniqueName(id); } if (layer == null || layer.getName() == null || layer.getName().trim().length() == 0) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, LAYER_PLACEHOLDER_ERROR_KEY); return getAlternateForward(mapping, request); } lp.setServerProviderPrefix(layer.getSpAbbr()); lp.setLayerName(layer.getName()); lp.setPlanType(FormUtils.StringToInt(dynaForm.getString("planType"))); String service = dynaForm.getString("service"); String operation = null; if (service != null && service.equalsIgnoreCase("WMS")) { operation = dynaForm.getString("operationWMS"); } else if (service != null && service.equalsIgnoreCase("WFS")) { operation = dynaForm.getString("operationWFS"); } else { service = null; } if (operation != null && operation.trim().length() == 0) { operation = null; } lp.setService(service); lp.setOperation(operation); BigDecimal minScale = FormUtils.bdValueNull(dynaForm.getString("minScale")); BigDecimal maxScale = FormUtils.bdValueNull(dynaForm.getString("maxScale")); String projection = dynaForm.getString("projection"); if (projection != null && projection.trim().length() == 0) { projection = null; } if (projection != null && (minScale != null || maxScale != null)) { boolean scaleOK = false; if (minScale != null && minScale.doubleValue() > 0) { if (maxScale != null && maxScale.doubleValue() > 0) { if (maxScale.compareTo(minScale) > 0) { scaleOK = true; } } } if (!scaleOK) { prepareMethod(dynaForm, request, LIST, EDIT); addAlternateMessage(mapping, request, SCALE_ERROR_KEY); return getAlternateForward(mapping, request); } if (minScale != null) { lp.setMinScale(minScale.setScale(2, RoundingMode.HALF_UP)); } if (maxScale != null) { lp.setMaxScale(maxScale.setScale(2, RoundingMode.HALF_UP)); } lp.setProjection(projection); } BigDecimal unitPrice = FormUtils.bdValueNull(dynaForm.getString("unitPrice")); /* * || door && vervangen. Price is namelijk verplicht en dus nooit null * en hij kwam dus altijd door de check. Ook als het bedrag 0 was. */ if (unitPrice != null && unitPrice.doubleValue() > 0.0) { lp.setUnitPrice(unitPrice.setScale(2, RoundingMode.HALF_UP)); } else { lp.setLayerIsFree(Boolean.TRUE); } em.persist(lp); prepareMethod(dynaForm, request, LIST, EDIT); addDefaultMessage(mapping, request, ACKNOWLEDGE_MESSAGES); return getDefaultForward(mapping, request); }
From source file:com.qcadoo.mes.deliveries.DeliveriesServiceImpl.java
private boolean changedFieldValue(final Entity entity, final BigDecimal fieldValue, final String reference) { if (entity.getId() == null) { return true; }/* w w w . jav a 2s. c o m*/ Entity entityFromDB = entity.getDataDefinition().get(entity.getId()); return entityFromDB.getDecimalField(reference) == null || !(fieldValue.compareTo(entityFromDB.getDecimalField(reference)) == 0); }
From source file:net.shopxx.entity.Order.java
@Transient public BigDecimal getAmountPayable() { if (!hasExpired() && !Order.Status.completed.equals(getStatus()) && !Order.Status.failed.equals(getStatus()) && !Order.Status.canceled.equals(getStatus()) && !Order.Status.denied.equals(getStatus())) { BigDecimal amountPayable = getAmount().subtract(getAmountPaid()); return amountPayable.compareTo(BigDecimal.ZERO) >= 0 ? amountPayable : BigDecimal.ZERO; }/* w w w. ja v a 2 s . co m*/ return BigDecimal.ZERO; }
From source file:org.openvpms.archetype.rules.finance.till.TillRulesTestCase.java
private void checkDeposit(Party account, ActBean balanceBean, BigDecimal expectedBalance) { FinancialAct deposit = DepositHelper.getUndepositedDeposit(account); // make sure a new uncleared bank deposit exists, with a relationship to the till balance assertNotNull(deposit);/* ww w. ja v a 2s.c o m*/ ActBean depBean = new ActBean(deposit); assertNotNull(depBean.getRelationship(balanceBean.getAct())); assertTrue(expectedBalance.compareTo(deposit.getTotal()) == 0); }