Example usage for java.math BigDecimal compareTo

List of usage examples for java.math BigDecimal compareTo

Introduction

In this page you can find the example usage for java.math BigDecimal compareTo.

Prototype

@Override
public int compareTo(BigDecimal val) 

Source Link

Document

Compares this BigDecimal with the specified BigDecimal .

Usage

From source file:org.apache.calcite.runtime.SqlFunctions.java

/** SQL <code>&ge;</code> operator applied to BigDecimal values. */
public static boolean ge(BigDecimal b0, BigDecimal b1) {
    return b0.compareTo(b1) >= 0;
}

From source file:net.groupbuy.service.impl.OrderServiceImpl.java

@Transactional(readOnly = true)
public Order build(Cart cart, Receiver receiver, PaymentMethod paymentMethod, ShippingMethod shippingMethod,
        CouponCode couponCode, boolean isInvoice, String invoiceTitle, boolean useBalance, String memo) {
    Assert.notNull(cart);/*from   w  ww  .jav a2s .  com*/
    Assert.notNull(cart.getMember());
    Assert.notEmpty(cart.getCartItems());

    Order order = new Order();
    order.setShippingStatus(ShippingStatus.unshipped);
    order.setFee(new BigDecimal(0));
    order.setPromotionDiscount(cart.getDiscount());
    order.setCouponDiscount(new BigDecimal(0));
    order.setOffsetAmount(new BigDecimal(0));
    order.setPoint(cart.getEffectivePoint());
    order.setMemo(memo);
    order.setMember(cart.getMember());

    if (receiver != null) {
        order.setConsignee(receiver.getConsignee());
        order.setAreaName(receiver.getAreaName());
        order.setAddress(receiver.getAddress());
        order.setZipCode(receiver.getZipCode());
        order.setPhone(receiver.getPhone());
        order.setArea(receiver.getArea());
    }

    if (!cart.getPromotions().isEmpty()) {
        StringBuffer promotionName = new StringBuffer();
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion != null && promotion.getName() != null) {
                promotionName.append(" " + promotion.getName());
            }
        }
        if (promotionName.length() > 0) {
            promotionName.deleteCharAt(0);
        }
        order.setPromotion(promotionName.toString());
    }

    order.setPaymentMethod(paymentMethod);

    if (shippingMethod != null && paymentMethod != null
            && paymentMethod.getShippingMethods().contains(shippingMethod)) {
        BigDecimal freight = shippingMethod.calculateFreight(cart.getWeight());
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion.getIsFreeShipping()) {
                freight = new BigDecimal(0);
                break;
            }
        }
        order.setFreight(freight);
        order.setShippingMethod(shippingMethod);
    } else {
        order.setFreight(new BigDecimal(0));
    }

    if (couponCode != null && cart.isCouponAllowed()) {
        couponCodeDao.lock(couponCode, LockModeType.PESSIMISTIC_WRITE);
        if (!couponCode.getIsUsed() && couponCode.getCoupon() != null && cart.isValid(couponCode.getCoupon())) {
            BigDecimal couponDiscount = cart.getEffectivePrice().subtract(
                    couponCode.getCoupon().calculatePrice(cart.getQuantity(), cart.getEffectivePrice()));
            couponDiscount = couponDiscount.compareTo(new BigDecimal(0)) > 0 ? couponDiscount
                    : new BigDecimal(0);
            order.setCouponDiscount(couponDiscount);
            order.setCouponCode(couponCode);
        }
    }

    List<OrderItem> orderItems = order.getOrderItems();
    for (CartItem cartItem : cart.getCartItems()) {
        if (cartItem != null && cartItem.getProduct() != null) {
            Product product = cartItem.getProduct();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(product.getSn());
            orderItem.setName(product.getName());
            orderItem.setFullName(product.getFullName());
            orderItem.setPrice(cartItem.getPrice());
            orderItem.setWeight(product.getWeight());
            orderItem.setThumbnail(product.getThumbnail());
            orderItem.setIsGift(false);
            orderItem.setQuantity(cartItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(product);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    for (GiftItem giftItem : cart.getGiftItems()) {
        if (giftItem != null && giftItem.getGift() != null) {
            Product gift = giftItem.getGift();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(gift.getSn());
            orderItem.setName(gift.getName());
            orderItem.setFullName(gift.getFullName());
            orderItem.setPrice(new BigDecimal(0));
            orderItem.setWeight(gift.getWeight());
            orderItem.setThumbnail(gift.getThumbnail());
            orderItem.setIsGift(true);
            orderItem.setQuantity(giftItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(gift);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    Setting setting = SettingUtils.get();
    if (setting.getIsInvoiceEnabled() && isInvoice && StringUtils.isNotEmpty(invoiceTitle)) {
        order.setIsInvoice(true);
        order.setInvoiceTitle(invoiceTitle);
        order.setTax(order.calculateTax());
    } else {
        order.setIsInvoice(false);
        order.setTax(new BigDecimal(0));
    }

    if (useBalance) {
        Member member = cart.getMember();
        if (member.getBalance().compareTo(order.getAmount()) >= 0) {
            order.setAmountPaid(order.getAmount());
        } else {
            order.setAmountPaid(member.getBalance());
        }
    } else {
        order.setAmountPaid(new BigDecimal(0));
    }

    if (order.getAmountPayable().compareTo(new BigDecimal(0)) == 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.paid);
    } else if (order.getAmountPayable().compareTo(new BigDecimal(0)) > 0
            && order.getAmountPaid().compareTo(new BigDecimal(0)) > 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.partialPayment);
    } else {
        order.setOrderStatus(OrderStatus.unconfirmed);
        order.setPaymentStatus(PaymentStatus.unpaid);
    }

    if (paymentMethod != null && paymentMethod.getTimeout() != null
            && order.getPaymentStatus() == PaymentStatus.unpaid) {
        order.setExpire(DateUtils.addMinutes(new Date(), paymentMethod.getTimeout()));
    }

    return order;
}

From source file:op.tools.SYSTools.java

public static BigDecimal checkBigDecimal(javax.swing.event.CaretEvent evt, boolean nees2BePositive) {
    BigDecimal bd = null;
    JTextComponent txt = (JTextComponent) evt.getSource();
    Action toolTipAction = txt.getActionMap().get("hideTip");
    if (toolTipAction != null) {
        ActionEvent hideTip = new ActionEvent(txt, ActionEvent.ACTION_PERFORMED, "");
        toolTipAction.actionPerformed(hideTip);
    }/*from   w  ww  .j a  va 2s  . c  om*/
    try {
        OPDE.debug(txt.getText());
        OPDE.debug(assimilateDecimalSeparators(txt.getText()));

        bd = parseDecimal(txt.getText());

        //            bd = BigDecimal.valueOf(Double.parseDouble(assimilateDecimalSeparators(txt.getText())));
        OPDE.debug(bd);
        if (nees2BePositive && bd.compareTo(BigDecimal.ZERO) <= 0) {
            txt.setToolTipText("<html><font color=\"red\"><b>" + SYSTools.xx("misc.msg.invalidnumber")
                    + "</b></font></html>");
            toolTipAction = txt.getActionMap().get("postTip");
            bd = BigDecimal.ONE;
        } else {
            txt.setToolTipText("");
        }

    } catch (NumberFormatException ex) {
        if (nees2BePositive) {
            bd = BigDecimal.ONE;
        } else {
            bd = BigDecimal.ZERO;
        }
        txt.setToolTipText(
                "<html><font color=\"red\"><b>" + SYSTools.xx("misc.msg.invalidnumber") + "</b></font></html>");
        toolTipAction = txt.getActionMap().get("postTip");
        if (toolTipAction != null) {
            ActionEvent postTip = new ActionEvent(txt, ActionEvent.ACTION_PERFORMED, "");
            toolTipAction.actionPerformed(postTip);
        }
    }
    return bd;
}

From source file:hydrograph.ui.propertywindow.widgets.listeners.grid.MouseHoverOnSchemaGridListener.java

private String setToolTipForDoubleFloatIntegerLongShortSchemaRange(
        GenerateRecordSchemaGridRow generateRecordSchemaGridRow) {
    BigDecimal rangeFrom = null, rangeTo = null;

    if (StringUtils.isNotBlank(generateRecordSchemaGridRow.getRangeFrom())
            && generateRecordSchemaGridRow.getRangeFrom().matches(REGULAR_EXPRESSION_FOR_NUMBER)) {
        rangeFrom = new BigDecimal(generateRecordSchemaGridRow.getRangeFrom());
    }//from   ww  w  .j  a v a 2 s.c o  m

    if (StringUtils.isNotBlank(generateRecordSchemaGridRow.getRangeTo())
            && generateRecordSchemaGridRow.getRangeTo().matches(REGULAR_EXPRESSION_FOR_NUMBER)) {
        rangeTo = new BigDecimal(generateRecordSchemaGridRow.getRangeTo());
    }

    if (rangeFrom != null && rangeTo != null) {
        if (rangeFrom.compareTo(rangeTo) > 0) {
            return Messages.RANGE_FROM_GREATER_THAN_RANGE_TO;
        }
    }

    if (!generateRecordSchemaGridRow.getLength().isEmpty()) {
        int fieldLength = Integer.parseInt(generateRecordSchemaGridRow.getLength());

        if (fieldLength < 0) {
            return Messages.FIELD_LENGTH_LESS_THAN_ZERO;
        } else {

            String minPermissibleRangeValue = "", maxPermissibleRangeValue = "";

            for (int i = 1; i <= fieldLength; i++) {
                maxPermissibleRangeValue = maxPermissibleRangeValue.concat("9");

                if (minPermissibleRangeValue.trim().length() == 0) {
                    minPermissibleRangeValue = minPermissibleRangeValue.concat("-");
                } else {
                    minPermissibleRangeValue = minPermissibleRangeValue.concat("9");
                }
            }

            if (minPermissibleRangeValue.equals("-")) {
                minPermissibleRangeValue = "0";
            }

            if (fieldLength == 0) {
                minPermissibleRangeValue = "0";
                maxPermissibleRangeValue = "0";
            }

            BigDecimal minRangeValue = new BigDecimal(minPermissibleRangeValue);
            BigDecimal maxRangeValue = new BigDecimal(maxPermissibleRangeValue);

            return setToolTipIfSchemaRangeAndLengthIsInvalid(rangeFrom, fieldLength, rangeTo, minRangeValue,
                    maxRangeValue);
        }
    }
    return "";
}

From source file:org.apache.cloudstack.api.response.QuotaResponseBuilderImpl.java

@Override
public QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Double amount, Long updatedBy,
        Boolean enforce) {// ww w .  jav a  2 s .c  o m
    Date despositedOn = _quotaService.computeAdjustedTime(new Date());
    QuotaBalanceVO qb = _quotaBalanceDao.findLaterBalanceEntry(accountId, domainId, despositedOn);

    if (qb != null) {
        throw new InvalidParameterValueException(
                "Incorrect deposit date: " + despositedOn + " there are balance entries after this date");
    }

    QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, new BigDecimal(amount), updatedBy);
    credits.setUpdatedOn(despositedOn);
    QuotaCreditsVO result = _quotaCreditsDao.saveCredits(credits);

    final AccountVO account = _accountDao.findById(accountId);
    if (account == null) {
        throw new InvalidParameterValueException("Account does not exist with account id " + accountId);
    }
    final boolean lockAccountEnforcement = "true".equalsIgnoreCase(QuotaConfig.QuotaEnableEnforcement.value());
    final BigDecimal currentAccountBalance = _quotaBalanceDao.lastQuotaBalance(accountId, domainId,
            startOfNextDay(new Date(despositedOn.getTime())));
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("AddQuotaCredits: Depositing " + amount + " on adjusted date " + despositedOn
                + ", current balance " + currentAccountBalance);
    }
    // update quota account with the balance
    _quotaService.saveQuotaAccount(account, currentAccountBalance, despositedOn);
    if (lockAccountEnforcement) {
        if (currentAccountBalance.compareTo(new BigDecimal(0)) >= 0) {
            if (account.getState() == Account.State.locked) {
                s_logger.info("UnLocking account " + account.getAccountName() + " , due to positive balance "
                        + currentAccountBalance);
                _accountMgr.enableAccount(account.getAccountName(), domainId, accountId);
            }
        } else { // currentAccountBalance < 0 then lock the account
            if (_quotaManager.isLockable(account) && account.getState() == Account.State.enabled && enforce) {
                s_logger.info("Locking account " + account.getAccountName() + " , due to negative balance "
                        + currentAccountBalance);
                _accountMgr.lockAccount(account.getAccountName(), domainId, accountId);
            }
        }
    }

    String creditor = String.valueOf(Account.ACCOUNT_ID_SYSTEM);
    User creditorUser = _userDao.getUser(updatedBy);
    if (creditorUser != null) {
        creditor = creditorUser.getUsername();
    }
    QuotaCreditsResponse response = new QuotaCreditsResponse(result, creditor);
    response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
    return response;
}

From source file:org.apache.fineract.portfolio.loanaccount.domain.LoanCharge.java

/**
 * @param percentageOf/*from   w ww .ja v a 2 s .co  m*/
 * @returns a minimum cap or maximum cap set on charges if the criteria fits
 *          else it returns the percentageOf if the amount is within min and
 *          max cap
 */
private BigDecimal minimumAndMaximumCap(final BigDecimal percentageOf) {
    BigDecimal minMaxCap = BigDecimal.ZERO;
    if (this.minCap != null) {
        final int minimumCap = percentageOf.compareTo(this.minCap);
        if (minimumCap == -1) {
            minMaxCap = this.minCap;
            return minMaxCap;
        }
    }
    if (this.maxCap != null) {
        final int maximumCap = percentageOf.compareTo(this.maxCap);
        if (maximumCap == 1) {
            minMaxCap = this.maxCap;
            return minMaxCap;
        }
    }
    minMaxCap = percentageOf;
    // this will round the amount value
    if (this.loan != null && minMaxCap != null) {
        minMaxCap = Money.of(this.loan.getCurrency(), minMaxCap).getAmount();
    }
    return minMaxCap;
}

From source file:mx.edu.um.mateo.inventario.web.EntradaController.java

@RequestMapping("/ver/{id}")
public String ver(@PathVariable Long id, Model modelo) {
    log.debug("Mostrando entrada {}", id);
    Entrada entrada = entradaDao.obtiene(id);
    switch (entrada.getEstatus().getNombre()) {
    case Constantes.ABIERTA:
        modelo.addAttribute("puedeEditar", true);
        modelo.addAttribute("puedeEliminar", true);
        modelo.addAttribute("puedeCerrar", true);
        modelo.addAttribute("puedePendiente", true);
        break;/*  w w w  . j a  va  2 s .c  o  m*/
    case Constantes.PENDIENTE:
        modelo.addAttribute("puedeEditarPendiente", true);
        break;
    case Constantes.CERRADA:
        modelo.addAttribute("puedeCancelar", true);
        break;
    }

    modelo.addAttribute("entrada", entrada);

    BigDecimal subtotal = new BigDecimal("0").setScale(2, RoundingMode.HALF_UP);
    BigDecimal iva = new BigDecimal("0").setScale(2, RoundingMode.HALF_UP);
    for (LoteEntrada lote : entrada.getLotes()) {
        subtotal = subtotal.add(lote.getPrecioUnitario().multiply(lote.getCantidad()));
        iva = iva.add(lote.getIva());
    }
    BigDecimal total = subtotal.add(iva);
    modelo.addAttribute("subtotal", subtotal.setScale(2, RoundingMode.HALF_UP));
    modelo.addAttribute("iva", iva);
    modelo.addAttribute("total", total.setScale(2, RoundingMode.HALF_UP));
    if (iva.compareTo(entrada.getIva()) == 0 && total.compareTo(entrada.getTotal()) == 0) {
        modelo.addAttribute("estiloTotales", "label label-success");
    } else {
        BigDecimal variacion = new BigDecimal("0.05");
        BigDecimal topeIva = entrada.getIva().multiply(variacion);
        BigDecimal topeTotal = entrada.getTotal().multiply(variacion);
        log.debug("Estilos {} {} {} {} {} {}",
                new Object[] { iva, entrada.getIva(), topeIva, total, entrada.getTotal(), topeTotal });
        if (iva.compareTo(entrada.getIva()) < 0 || total.compareTo(entrada.getTotal()) < 0) {
            log.debug("La diferencia es menor");
            if (iva.compareTo(entrada.getIva().subtract(topeIva)) >= 0
                    && total.compareTo(entrada.getTotal().subtract(topeTotal)) >= 0) {
                modelo.addAttribute("estiloTotales", "label label-warning");
            } else {
                modelo.addAttribute("estiloTotales", "label label-important");
            }
        } else {
            log.debug("La diferencia es mayor {} {}",
                    new Object[] { iva.compareTo(entrada.getIva().add(topeIva)),
                            total.compareTo(entrada.getTotal().add(topeTotal)) });
            if (iva.compareTo(entrada.getIva().add(topeIva)) <= 0
                    && total.compareTo(entrada.getTotal().add(topeTotal)) <= 0) {
                log.debug("estilo warning");
                modelo.addAttribute("estiloTotales", "label label-warning");
            } else {
                log.debug("estilo error");
                modelo.addAttribute("estiloTotales", "label label-important");
            }
        }
    }

    return "inventario/entrada/ver";
}

From source file:com.gst.infrastructure.core.data.DataValidatorBuilder.java

public DataValidatorBuilder comapareMinAndMaxOfTwoBigDecmimalNos(final BigDecimal min, final BigDecimal max) {
    if (min != null && max != null) {
        if (max.compareTo(min) == -1) {
            final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource)
                    .append(".").append(this.parameter).append(".is.not.within.expected.range");
            final StringBuilder defaultEnglishMessage = new StringBuilder("The ").append(" min number ")
                    .append(min).append(" should less than max number ").append(max).append(".");
            final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(),
                    defaultEnglishMessage.toString(), this.parameter, min, max);
            this.dataValidationErrors.add(error);
            return this;
        }/*from  www .jav a 2s. co  m*/
    }
    return this;
}

From source file:gov.guilin.service.impl.OrderServiceImpl.java

@Transactional(readOnly = true)
public Order build(Cart cart, Receiver receiver, PaymentMethod paymentMethod, ShippingMethod shippingMethod,
        CouponCode couponCode, boolean isInvoice, String invoiceTitle, boolean useBalance, String memo) {
    Assert.notNull(cart);//from   ww  w .jav a 2  s .  c  om
    Assert.notNull(cart.getMember());
    Assert.notEmpty(cart.getCartItems());

    Order order = new Order();
    order.setShippingStatus(ShippingStatus.unshipped);
    order.setFee(new BigDecimal(0));
    order.setPromotionDiscount(cart.getDiscount());
    order.setCouponDiscount(new BigDecimal(0));
    order.setOffsetAmount(new BigDecimal(0));
    order.setPoint(cart.getEffectivePoint());
    order.setMemo(memo);
    order.setMember(cart.getMember());
    Supplier supplier = cart.getCartItems().iterator().next().getProduct().getSupplier();
    Assert.notNull(supplier);
    order.setSupplier(supplier);

    if (receiver != null) {
        order.setConsignee(receiver.getConsignee());
        order.setAreaName(receiver.getAreaName());
        order.setAddress(receiver.getAddress());
        order.setZipCode(receiver.getZipCode());
        order.setPhone(receiver.getPhone());
        order.setArea(receiver.getArea());
    }

    if (!cart.getPromotions().isEmpty()) {
        StringBuffer promotionName = new StringBuffer();
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion != null && promotion.getName() != null) {
                promotionName.append(" " + promotion.getName());
            }
        }
        if (promotionName.length() > 0) {
            promotionName.deleteCharAt(0);
        }
        order.setPromotion(promotionName.toString());
    }

    order.setPaymentMethod(paymentMethod);

    if (shippingMethod != null && paymentMethod != null
            && paymentMethod.getShippingMethods().contains(shippingMethod)) {
        BigDecimal freight = shippingMethod.calculateFreight(cart.getWeight());
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion.getIsFreeShipping()) {
                freight = new BigDecimal(0);
                break;
            }
        }
        order.setFreight(freight);
        order.setShippingMethod(shippingMethod);
    } else {
        order.setFreight(new BigDecimal(0));
    }

    if (couponCode != null && cart.isCouponAllowed()) {
        couponCodeDao.lock(couponCode, LockModeType.PESSIMISTIC_WRITE);
        if (!couponCode.getIsUsed() && couponCode.getCoupon() != null && cart.isValid(couponCode.getCoupon())) {
            BigDecimal couponDiscount = cart.getEffectivePrice().subtract(
                    couponCode.getCoupon().calculatePrice(cart.getQuantity(), cart.getEffectivePrice()));
            couponDiscount = couponDiscount.compareTo(new BigDecimal(0)) > 0 ? couponDiscount
                    : new BigDecimal(0);
            order.setCouponDiscount(couponDiscount);
            order.setCouponCode(couponCode);
        }
    }

    List<OrderItem> orderItems = order.getOrderItems();
    for (CartItem cartItem : cart.getCartItems()) {
        if (cartItem != null && cartItem.getProduct() != null) {
            Product product = cartItem.getProduct();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(product.getSn());
            orderItem.setName(product.getName());
            orderItem.setFullName(product.getFullName());
            orderItem.setPrice(cartItem.getPrice());
            orderItem.setWeight(product.getWeight());
            orderItem.setThumbnail(product.getThumbnail());
            orderItem.setIsGift(false);
            orderItem.setQuantity(cartItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(product);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    for (GiftItem giftItem : cart.getGiftItems()) {
        if (giftItem != null && giftItem.getGift() != null) {
            Product gift = giftItem.getGift();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(gift.getSn());
            orderItem.setName(gift.getName());
            orderItem.setFullName(gift.getFullName());
            orderItem.setPrice(new BigDecimal(0));
            orderItem.setWeight(gift.getWeight());
            orderItem.setThumbnail(gift.getThumbnail());
            orderItem.setIsGift(true);
            orderItem.setQuantity(giftItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(gift);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    Setting setting = SettingUtils.get();
    if (setting.getIsInvoiceEnabled() && isInvoice && StringUtils.isNotEmpty(invoiceTitle)) {
        order.setIsInvoice(true);
        order.setInvoiceTitle(invoiceTitle);
        order.setTax(order.calculateTax());
    } else {
        order.setIsInvoice(false);
        order.setTax(new BigDecimal(0));
    }

    if (useBalance) {
        Member member = cart.getMember();
        if (member.getBalance().compareTo(order.getAmount()) >= 0) {
            order.setAmountPaid(order.getAmount());
        } else {
            order.setAmountPaid(member.getBalance());
        }
    } else {
        order.setAmountPaid(new BigDecimal(0));
    }

    if (order.getAmountPayable().compareTo(new BigDecimal(0)) == 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.paid);
    } else if (order.getAmountPayable().compareTo(new BigDecimal(0)) > 0
            && order.getAmountPaid().compareTo(new BigDecimal(0)) > 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.partialPayment);
    } else {
        order.setOrderStatus(OrderStatus.unconfirmed);
        order.setPaymentStatus(PaymentStatus.unpaid);
    }

    if (paymentMethod != null && paymentMethod.getTimeout() != null
            && order.getPaymentStatus() == PaymentStatus.unpaid) {
        order.setExpire(DateUtils.addMinutes(new Date(), paymentMethod.getTimeout()));
    }

    return order;
}

From source file:com.gst.infrastructure.core.data.DataValidatorBuilder.java

public DataValidatorBuilder notLessThanMin(final BigDecimal min) {
    if (min != null && this.value != null) {
        final BigDecimal amount = BigDecimal.valueOf(Double.valueOf(this.value.toString()));
        if (amount.compareTo(min) == -1) {
            final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource)
                    .append(".").append(this.parameter).append(".is.less.than.min");
            final StringBuilder defaultEnglishMessage = new StringBuilder("The ").append(this.parameter)
                    .append(" value ").append(amount).append(" must not be less than minimum value ")
                    .append(min);/* ww w .  j a v a2 s  . c  o m*/
            final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(),
                    defaultEnglishMessage.toString(), this.parameter, amount, min);
            this.dataValidationErrors.add(error);
            return this;
        }
    }
    return this;
}