List of usage examples for java.math BigDecimal compareTo
@Override public int compareTo(BigDecimal val)
From source file:com.opensky.osis.BraintreeConnector.java
/** * Refund the given transaction/* w w w . jav 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:net.sf.jasperreports.engine.json.expression.filter.evaluation.BasicFilterExpressionEvaluator.java
protected boolean applyOperator(JsonNode valueNode) { ValueDescriptor valueDescriptor = expression.getValueDescriptor(); JsonOperatorEnum operator = expression.getOperator(); FilterExpression.VALUE_TYPE type = valueDescriptor.getType(); // do null comparison first if (FilterExpression.VALUE_TYPE.NULL.equals(type)) { switch (operator) { case EQ://from w ww . jav a2s . c om return valueNode.isNull() || valueNode.isMissingNode(); case NE: return !(valueNode.isNull() || valueNode.isMissingNode()); } } else { // compare numbers with numbers if (valueNode.isNumber() && (FilterExpression.VALUE_TYPE.INTEGER.equals(type) || FilterExpression.VALUE_TYPE.DOUBLE.equals(type))) { BigDecimal opRight = new BigDecimal(valueDescriptor.getValue()); BigDecimal opLeft; if (valueNode.isBigDecimal()) { opLeft = valueNode.decimalValue(); } else { opLeft = new BigDecimal(valueNode.asText()); } switch (operator) { case EQ: return opLeft.compareTo(opRight) == 0; case NE: return opLeft.compareTo(opRight) != 0; case GT: return opLeft.compareTo(opRight) > 0; case GE: return opLeft.compareTo(opRight) >= 0; case LT: return opLeft.compareTo(opRight) < 0; case LE: return opLeft.compareTo(opRight) <= 0; } } // compare strings with strings else if (valueNode.isTextual() && FilterExpression.VALUE_TYPE.STRING.equals(type)) { switch (operator) { case EQ: return valueNode.textValue().equals(valueDescriptor.getValue()); case NE: return !valueNode.textValue().equals(valueDescriptor.getValue()); case CONTAINS: return valueNode.textValue().contains(valueDescriptor.getValue()); } } // compare booleans with booleans else if (valueNode.isBoolean() && FilterExpression.VALUE_TYPE.BOOLEAN.equals(type)) { switch (operator) { case EQ: return valueNode.booleanValue() == Boolean.parseBoolean(valueDescriptor.getValue()); case NE: return valueNode.booleanValue() != Boolean.parseBoolean(valueDescriptor.getValue()); } } } return false; }
From source file:ccc.cli.StringToDecConverterUtil.java
/** * * Converts a number represented as text to a decimal number. * * @param textNumber text representation of a number * @return BigDecimal//from www. j a v a 2s . c o m */ public BigDecimal convert(final String textNumber) { BigDecimal decNumber = null; if (textNumber != null && textNumber.matches(DECIMAL_PATTERN)) { // BigNumber(String) constructor does not allow commas decNumber = new BigDecimal(textNumber.replaceAll(",", "")); if (decNumber.precision() > MAX_PRECISION || decNumber.scale() < 0 && Math.abs(decNumber.scale()) + decNumber.precision() > MAX_PRECISION - MAX_SCALE || decNumber.compareTo(MAX_VALUE) == 1) { LOG.warn("Value is larger than maximum precision allowed " + "and was rejected."); return null; } if (decNumber.scale() > MAX_SCALE) { LOG.trace("Scale is bigger than maximum allowed: " + decNumber.scale() + ". Resetting scale."); decNumber = decNumber.setScale(MAX_SCALE, RoundingMode.DOWN); } } return decNumber; }
From source file:com.roncoo.pay.account.service.impl.RpAccountTransactionServiceImpl.java
/** * ?:?//from w w w . j a v a 2s.com * * @param userNo * ? * @param amount * ?? * @param requestNo * ? * @param trxType * * @param remark * */ @Transactional(rollbackFor = Exception.class) public RpAccount debitToAccount(String userNo, BigDecimal amount, String requestNo, String bankTrxNo, String trxType, String remark) { RpAccount account = this.getByUserNo_IsPessimist(userNo, true); if (account == null) { throw AccountBizException.ACCOUNT_NOT_EXIT; } // ??? BigDecimal availableBalance = account.getAvailableBalance(); String isAllowSett = PublicEnum.YES.name(); String completeSett = PublicEnum.NO.name(); if (availableBalance.compareTo(amount) == -1) { throw AccountBizException.ACCOUNT_SUB_AMOUNT_OUTLIMIT; } /** ?? **/ account.setBalance(account.getBalance().subtract(amount)); Date lastModifyDate = account.getEditTime(); // ??0 if (!DateUtils.isSameDayWithToday(lastModifyDate)) { account.setTodayExpend(BigDecimal.ZERO); account.setTodayIncome(BigDecimal.ZERO); account.setTodayExpend(amount); } else { account.setTodayExpend(account.getTodayExpend().add(amount)); } account.setTotalExpend(account.getTodayExpend().add(amount)); account.setEditTime(new Date()); // ? RpAccountHistory accountHistoryEntity = new RpAccountHistory(); accountHistoryEntity.setCreateTime(new Date()); accountHistoryEntity.setEditTime(new Date()); accountHistoryEntity.setIsAllowSett(isAllowSett); accountHistoryEntity.setAmount(amount); accountHistoryEntity.setBalance(account.getBalance()); accountHistoryEntity.setRequestNo(requestNo); accountHistoryEntity.setBankTrxNo(bankTrxNo); accountHistoryEntity.setIsCompleteSett(completeSett); accountHistoryEntity.setRemark(remark); accountHistoryEntity.setFundDirection(AccountFundDirectionEnum.SUB.name()); accountHistoryEntity.setAccountNo(account.getAccountNo()); accountHistoryEntity.setTrxType(trxType); accountHistoryEntity.setId(StringUtil.get32UUID()); accountHistoryEntity.setUserNo(userNo); this.rpAccountHistoryDao.insert(accountHistoryEntity); this.rpAccountDao.update(account); return account; }
From source file:org.yes.cart.payment.impl.PayPalExpressCheckoutPaymentGatewayImpl.java
/** * Support for pp express checkout. In case if gateway not support this operation , return will be empty hashmap. * * All info about SetExpressCheckout see here: * https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout * * @param amount amount/*from w w w .j ava 2 s . c o m*/ * @param currencyCode currecny * @return map with auth token * @throws java.io.IOException in case of errors */ public Map<String, String> setExpressCheckoutMethod(final BigDecimal amount, final String currencyCode) throws IOException { Assert.notNull(amount, "Amount must be provided"); Assert.isTrue(amount.compareTo(BigDecimal.ZERO) > 0, "Amount must be positive"); Assert.notNull(currencyCode, "Currency code must be provided"); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(PP_EC_PAYMENTREQUEST_0_AMT); stringBuilder.append(EQ); stringBuilder.append(URLEncoder.encode("" + amount)); stringBuilder.append(AND); stringBuilder.append(PP_EC_PAYMENTREQUEST_0_PAYMENTACTION); stringBuilder.append(EQ); stringBuilder.append("Sale"); stringBuilder.append(AND); stringBuilder.append(PP_EC_RETURNURL); stringBuilder.append(EQ); stringBuilder.append(URLEncoder.encode(getParameterValue(PP_EC_RETURNURL))); stringBuilder.append(AND); stringBuilder.append(PP_EC_CANCELURL); stringBuilder.append(EQ); stringBuilder.append(URLEncoder.encode(getParameterValue(PP_EC_CANCELURL))); stringBuilder.append(AND); stringBuilder.append(PP_EC_NOSHIPPING); stringBuilder.append(EQ); stringBuilder.append("1"); stringBuilder.append(AND); stringBuilder.append(PP_EC_PAYMENTREQUEST_0_CURRENCYCODE); stringBuilder.append(EQ); stringBuilder.append(currencyCode); return performHttpCall("SetExpressCheckout", stringBuilder.toString()); }
From source file:org.broadleafcommerce.core.pricing.service.tax.provider.SimpleTaxProvider.java
@Override public Order calculateTaxForOrder(Order order, ModuleConfiguration config) throws TaxException { if (!order.getCustomer().isTaxExempt()) { for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) { // Set taxes on the fulfillment group items for (FulfillmentGroupItem fgItem : fulfillmentGroup.getFulfillmentGroupItems()) { if (isItemTaxable(fgItem)) { BigDecimal factor = determineItemTaxRate(fulfillmentGroup.getAddress()); if (factor != null && factor.compareTo(BigDecimal.ZERO) != 0) { TaxDetail tax;/*from w ww .j a v a 2 s . co m*/ checkDetail: { for (TaxDetail detail : fgItem.getTaxes()) { if (detail.getType().equals(TaxType.COMBINED)) { tax = detail; break checkDetail; } } tax = entityConfig.createEntityInstance(TaxDetail.class.getName(), TaxDetail.class); tax.setType(TaxType.COMBINED); fgItem.getTaxes().add(tax); } tax.setRate(factor); tax.setAmount(fgItem.getTotalItemTaxableAmount().multiply(factor)); } } } for (FulfillmentGroupFee fgFee : fulfillmentGroup.getFulfillmentGroupFees()) { if (isFeeTaxable(fgFee)) { BigDecimal factor = determineItemTaxRate(fulfillmentGroup.getAddress()); if (factor != null && factor.compareTo(BigDecimal.ZERO) != 0) { TaxDetail tax; checkDetail: { for (TaxDetail detail : fgFee.getTaxes()) { if (detail.getType().equals(TaxType.COMBINED)) { tax = detail; break checkDetail; } } tax = entityConfig.createEntityInstance(TaxDetail.class.getName(), TaxDetail.class); tax.setType(TaxType.COMBINED); fgFee.getTaxes().add(tax); } tax.setRate(factor); tax.setAmount(fgFee.getAmount().multiply(factor)); } } } BigDecimal factor = determineTaxRateForFulfillmentGroup(fulfillmentGroup); if (factor != null && factor.compareTo(BigDecimal.ZERO) != 0) { TaxDetail tax; checkDetail: { for (TaxDetail detail : fulfillmentGroup.getTaxes()) { if (detail.getType().equals(TaxType.COMBINED)) { tax = detail; break checkDetail; } } tax = entityConfig.createEntityInstance(TaxDetail.class.getName(), TaxDetail.class); tax.setType(TaxType.COMBINED); fulfillmentGroup.getTaxes().add(tax); } tax.setRate(factor); tax.setAmount(fulfillmentGroup.getFulfillmentPrice().multiply(factor)); } } } return order; }
From source file:org.fineract.module.stellar.horizonadapter.HorizonServerUtilities.java
public BigDecimal adjustVaultIssuedAssets(final StellarAccountId stellarAccountId, final char[] stellarAccountPrivateKey, final StellarAccountId stellarVaultAccountId, final char[] stellarVaultAccountPrivateKey, final String assetCode, final BigDecimal amount) throws InvalidConfigurationException, StellarPaymentFailedException, StellarTrustlineAdjustmentFailedException { final BigDecimal currentVaultIssuedAssets = currencyTrustSize(stellarAccountId, assetCode, stellarVaultAccountId);//from w w w. j a v a 2s .c o m final BigDecimal adjustmentRequired = amount.subtract(currentVaultIssuedAssets); if (adjustmentRequired.compareTo(BigDecimal.ZERO) < 0) { final BigDecimal currentVaultIssuedAssetsHeldByTenant = getBalanceByIssuer(stellarAccountId, assetCode, stellarVaultAccountId); final BigDecimal adjustmentPossible = currentVaultIssuedAssetsHeldByTenant .min(adjustmentRequired.abs()); final BigDecimal finalBalance = currentVaultIssuedAssets.subtract(adjustmentPossible); simplePay(stellarVaultAccountId, adjustmentPossible, assetCode, stellarVaultAccountId, stellarAccountPrivateKey); setTrustLineSize(stellarAccountPrivateKey, stellarVaultAccountId, assetCode, finalBalance); return finalBalance; } else if (adjustmentRequired.compareTo(BigDecimal.ZERO) > 0) { setTrustLineSize(stellarAccountPrivateKey, stellarVaultAccountId, assetCode, amount); simplePay(stellarAccountId, adjustmentRequired, assetCode, stellarVaultAccountId, stellarVaultAccountPrivateKey); return amount; } else { return currentVaultIssuedAssets; } }
From source file:hydrograph.ui.propertywindow.widgets.listeners.grid.MouseHoverOnSchemaGridListener.java
private String setToolTipIfSchemaRangeAndLengthIsInvalid(BigDecimal rangeFrom, int fieldLength, BigDecimal rangeTo, BigDecimal minRangeValue, BigDecimal maxRangeValue) { if (rangeFrom != null && fieldLength > 0 && rangeTo != null) { if (rangeFrom.compareTo(minRangeValue) < 0) { return Messages.RANGE_FROM_LESS_THAN_MIN_PERMISSIBLE_VALUE; } else if (rangeTo.compareTo(maxRangeValue) > 0) { return Messages.RANGE_TO_GREATER_THAN_MAX_PERMISSIBLE_VALUE; }/*w w w . ja va2s . c om*/ } else if (rangeFrom != null && fieldLength > 0 && rangeTo == null) { if (rangeFrom.compareTo(maxRangeValue) > 0) { return Messages.RANGE_FROM_GREATER_THAN_MAX_PERMISSIBLE_VALUE; } } else if (rangeTo != null && fieldLength > 0 && rangeFrom == null) { if (rangeTo.compareTo(minRangeValue) < 0) { return Messages.RANGE_TO_LESS_THAN_MIN_PERMISSIBLE_VALUE; } } return ""; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java
private SummaryControlCategory getResumeClassification(BigDecimal result) { if (result.compareTo(BigDecimal.valueOf(20)) < 0) { return SummaryControlCategory.BETWEEN_0_20; }//www . ja va 2 s .c om if (result.compareTo(BigDecimal.valueOf(40)) < 0) { return SummaryControlCategory.BETWEEN_20_40; } if (result.compareTo(BigDecimal.valueOf(60)) < 0) { return SummaryControlCategory.BETWEEN_40_60; } if (result.compareTo(BigDecimal.valueOf(80)) < 0) { return SummaryControlCategory.BETWEEN_60_80; } return SummaryControlCategory.BETWEEN_80_100; }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJNumberEditor.java
public void setMinValue(BigDecimal value) { final String S_ProcName = "setMinValue"; if (value == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "value"); }//w w w . j a va2 s . c o m BigDecimal absoluteMinValue = getAbsoluteMinValue(); if (value.compareTo(absoluteMinValue) < 0) { throw CFLib.getDefaultExceptionFactory().newArgumentUnderflowException(getClass(), S_ProcName, 1, "value", value, absoluteMinValue); } minValue = value; }