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:net.shopxx.entity.Order.java

@Transient
public BigDecimal getAmountReceivable() {
    if (!hasExpired() && PaymentMethod.Type.cashOnDelivery.equals(getPaymentMethodType())
            && !Order.Status.completed.equals(getStatus()) && !Order.Status.failed.equals(getStatus())
            && !Order.Status.canceled.equals(getStatus()) && !Order.Status.denied.equals(getStatus())) {
        BigDecimal amountReceivable = getAmount().subtract(getAmountPaid());
        return amountReceivable.compareTo(BigDecimal.ZERO) >= 0 ? amountReceivable : BigDecimal.ZERO;
    }/*from  w w  w. ja  v  a 2s .  co  m*/
    return BigDecimal.ZERO;
}

From source file:net.shopxx.service.impl.ShippingMethodServiceImpl.java

@Transactional(readOnly = true)
public BigDecimal calculateFreight(ShippingMethod shippingMethod, Area area, Integer weight) {
    Assert.notNull(shippingMethod);/*from www.j  ava2 s .  c  o  m*/

    Setting setting = SystemUtils.getSetting();
    BigDecimal firstPrice = shippingMethod.getDefaultFirstPrice();
    BigDecimal continuePrice = shippingMethod.getDefaultContinuePrice();
    if (area != null && CollectionUtils.isNotEmpty(shippingMethod.getFreightConfigs())) {
        List<Area> areas = new ArrayList<Area>();
        areas.addAll(area.getParents());
        areas.add(area);
        for (int i = areas.size() - 1; i >= 0; i--) {
            FreightConfig freightConfig = shippingMethod.getFreightConfig(areas.get(i));
            if (freightConfig != null) {
                firstPrice = freightConfig.getFirstPrice();
                continuePrice = freightConfig.getContinuePrice();
                break;
            }
        }
    }
    if (weight == null || weight <= shippingMethod.getFirstWeight()
            || continuePrice.compareTo(BigDecimal.ZERO) == 0) {
        return setting.setScale(firstPrice);
    } else {
        double contiuneWeightCount = Math
                .ceil((weight - shippingMethod.getFirstWeight()) / (double) shippingMethod.getContinueWeight());
        return setting.setScale(
                firstPrice.add(continuePrice.multiply(new BigDecimal(String.valueOf(contiuneWeightCount)))));
    }
}

From source file:edu.usu.sdl.openstorefront.core.sort.AttributeCodeArchViewComparator.java

@Override
public int compare(T o1, T o2) {
    //Codes should be numbers (Note the description includes the code so they should be sort as well)
    BigDecimal codeKey1;
    BigDecimal codeKey2;/*from   www  . j  a va 2s  . c o  m*/

    if (o1.getSortOrder() != null && o2.getSortOrder() != null) {
        return o1.getSortOrder().compareTo(o2.getSortOrder());
    } else {
        if (StringUtils.isNotBlank(o1.getArchitectureCode())) {
            codeKey1 = StringProcessor.archtecureCodeToDecimal(o1.getArchitectureCode());
        } else {
            codeKey1 = StringProcessor.archtecureCodeToDecimal(o1.getCode());
        }

        if (StringUtils.isNotBlank(o2.getArchitectureCode())) {
            codeKey2 = StringProcessor.archtecureCodeToDecimal(o2.getArchitectureCode());
        } else {
            codeKey2 = StringProcessor.archtecureCodeToDecimal(o2.getCode());
        }

        int results = codeKey1.compareTo(codeKey2);
        if (results != 0) {
            return results;
        } else {
            return o1.getCode().compareTo(o2.getCode());
        }
    }
}

From source file:UserInterface.FinanceRole.TransferToRegSiteJPanel.java

private void populateLowRegSiteTable() {

    //Table//from ww w  .ja va2s.co  m
    DefaultTableModel dtm = (DefaultTableModel) lowRegJTable.getModel();
    dtm.setRowCount(0);

    for (CountryEnterprise objCountryEnterprise : objWorldEnterprise.getObjCountryEnterpriseDirectory()
            .getCountryEnterpriseList()) {
        for (RegisteredSiteEnterprise objRegisteredSiteEnterprise : objCountryEnterprise
                .getObjRegisteredSiteDirectory().getRegisteredSiteList()) {

            objRegisteredSiteEnterprise.getObjTransactionDirectory().updateTransactionAccount();

            BigDecimal availableBalance = objRegisteredSiteEnterprise.getObjTransactionDirectory()
                    .getAvailableRealBalance();
            int compare = availableBalance.compareTo(new BigDecimal(1000));

            if (compare < 1) {
                Object row[] = new Object[4];
                row[0] = objRegisteredSiteEnterprise.getOrganizationID();
                row[1] = objRegisteredSiteEnterprise.getRegSiteName();
                row[2] = objCountryEnterprise;
                row[3] = "$ "
                        + objRegisteredSiteEnterprise.getObjTransactionDirectory().getAvailableRealBalance();

                dtm.addRow(row);
            }
        }
    }
}

From source file:edu.usu.sdl.openstorefront.core.sort.ArchitectureComparator.java

@Override
public int compare(T o1, T o2) {
    //Codes should be numbers
    BigDecimal codeKey1;
    BigDecimal codeKey2;/*from   w w  w. ja  v a2 s. co  m*/

    if (o1.getSortOrder() != null && o2.getSortOrder() != null) {
        return o1.getSortOrder().compareTo(o2.getSortOrder());
    } else {

        if (StringUtils.isNotBlank(o1.getArchitectureCode())) {
            codeKey1 = StringProcessor.archtecureCodeToDecimal(o1.getArchitectureCode());
        } else {
            codeKey1 = StringProcessor.archtecureCodeToDecimal(o1.getAttributeCode());
        }

        if (StringUtils.isNotBlank(o2.getArchitectureCode())) {
            codeKey2 = StringProcessor.archtecureCodeToDecimal(o2.getArchitectureCode());
        } else {
            codeKey2 = StringProcessor.archtecureCodeToDecimal(o2.getAttributeCode());
        }

        return codeKey1.compareTo(codeKey2);
    }
}

From source file:au.org.ala.delta.translation.key.KeyStateTranslator.java

/**
 * Produces a state description of a key state defined for a numeric character.
 * @param keyChar the character as defined by the KEY STATES directive.
 * @param state details of the redefined state to describe.
 * @param separator the separator to use.
 * @return a description of the supplied state of the supplied character.
 *//*from w w w  .  j  av a2  s  .co  m*/
private String translateNumericState(IdentificationKeyCharacter keyChar, NumericKeyState state) {

    BigDecimal min = state.min();
    BigDecimal max = state.max();
    List<String> states = new ArrayList<String>();

    String separator = " " + Words.word(Word.TO) + " ";
    Values values = new Values(states, separator);

    if (keyChar.getCharacter().getCharacterType().isNumeric()) {

        if (min.equals(MIN_VALUE)) {
            values.setPrefix(Words.word(Word.UP_TO));
            states.add(max.toPlainString());
        } else if (max.equals(MAX_VALUE)) {
            values.setSuffix(Words.word(Word.OR_MORE));
            states.add(min.toPlainString());
        } else {
            states.add(min.toPlainString());
            if (min.compareTo(max) != 0) {
                states.add(max.toPlainString());
            }
        }
    }

    AttributeTranslator at = _attributeTranslatorFactory.translatorFor(keyChar.getCharacter());

    StringBuffer result = new StringBuffer();
    if (StringUtils.isNotBlank((values.getPrefix()))) {
        result.append(values.getPrefix()).append(" ");
    }

    result.append(at.translateValues(values));

    if (StringUtils.isNotBlank(values.getSuffix())) {
        result.append(" ").append(values.getSuffix());
    }
    return result.toString();
}

From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java

private boolean isGreaterThanZero(final BigDecimal value) {
    return value.compareTo(BigDecimal.ZERO) == 1;
}

From source file:UserInterface.FinanceRole.TransferToRegSiteJPanel.java

private void donateJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_donateJButtonActionPerformed

    //Validation//  w  w  w  .j a  va 2s  .  c o  m
    boolean validationSuccess;
    validationSuccess = validationIndividualTansfer();

    if (validationSuccess) {

        RegisteredSiteEnterprise objRegisteredSiteEnterprise = null;

        int selectedRegSite = regSiteJTable.getSelectedRow();

        if (selectedRegSite < 0) {
            JOptionPane.showMessageDialog(null, "Please select a Site");
            return;
        }

        objRegisteredSiteEnterprise = (RegisteredSiteEnterprise) regSiteJTable.getValueAt(selectedRegSite, 1);

        if (objRegisteredSiteEnterprise != null) {

            objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

            BigDecimal worldBalance = objWorldEnterprise.getObjTransactionDirectory().getAvailableRealBalance();

            int positiveWorldBalance = worldBalance.compareTo(individualDonationAmount);

            if (positiveWorldBalance >= 1) {

                int response = JOptionPane.showConfirmDialog(null,
                        "Total transfer of $ " + individualDonationAmount + "/- Do you want to transfer?",
                        "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (response == JOptionPane.YES_OPTION) {

                    //Registered Site Transaction
                    Transaction objRealRSTransaction = (Transaction) objRegisteredSiteEnterprise
                            .getObjTransactionDirectory().addNewTransaction();
                    objRealRSTransaction.setTransactionBDAmount(individualDonationAmount);
                    objRealRSTransaction.setObjUserAccountSource(objUserAccount);
                    objRealRSTransaction.setObjUserAccountDestination(null);
                    objRealRSTransaction.setTransactionSource(
                            Transaction.TransactionSourceType.FromWorldEnterprise.getValue());
                    objRealRSTransaction.setTransactionDestination(
                            Transaction.TransactionSourceType.ToRegSiteEnterprise.getValue());
                    objRealRSTransaction.setTransactionType(Transaction.TransactionType.Credit.getValue());
                    objRealRSTransaction.setTransactionMode(Transaction.TransactionModeType.Real.getValue());
                    objRegisteredSiteEnterprise.getObjTransactionDirectory().updateTransactionAccount();

                    //WorldEnterprise Transaction
                    Transaction objRealWETransaction = (Transaction) objWorldEnterprise
                            .getObjTransactionDirectory().addNewTransaction();
                    objRealWETransaction.setTransactionBDAmount(individualDonationAmount);
                    objRealWETransaction.setObjUserAccountSource(objUserAccount);
                    objRealWETransaction.setObjUserAccountDestination(null);
                    objRealWETransaction.setTransactionSource(
                            Transaction.TransactionSourceType.FromWorldEnterprise.getValue());
                    objRealWETransaction.setTransactionDestination(
                            Transaction.TransactionSourceType.ToRegSiteEnterprise.getValue());
                    objRealWETransaction.setTransactionType(Transaction.TransactionType.Debit.getValue());
                    objRealWETransaction.setTransactionMode(Transaction.TransactionModeType.Real.getValue());
                    objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

                    populateTransactionTable(objRegisteredSiteEnterprise);

                    JOptionPane.showMessageDialog(null,
                            "$ " + individualDonationAmount + "/- transferred successfully");

                    donationAmountJTextField.setText(null);
                    populateLowRegSiteTable();

                    //RegSiteTransferRecords
                    String donationLogs = objRealWETransaction.getTransactionID() + ","
                            + objRealWETransaction.getTransactionBDAmount() + ","
                            + objRealWETransaction.getObjUserAccountSource() + ","
                            + objRealWETransaction.getTransactionSource() + "," + objRegisteredSiteEnterprise
                            + "," + objRealWETransaction.getTransactionDestination() + ","
                            + objRealWETransaction.getTransactionType() + ","
                            + objRealWETransaction.getTransactionMode();

                    GenerateReports.regSiteTransferRecords(donationLogs);
                }

            } else {
                JOptionPane.showMessageDialog(null, "World Balance is low");
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please select again");
        }
    }
}

From source file:org.devgateway.ocds.web.rest.controller.CostEffectivenessVisualsController.java

@ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and "
        + "/api/costEffectivenessAwardAmount."
        + "This endpoint aggregates the responses from the specified endpoints, per year. "
        + "Responds to the same filters.")
@RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = { RequestMethod.POST,
        RequestMethod.GET }, produces = "application/json")
public List<DBObject> costEffectivenessTenderAwardAmount(
        @ModelAttribute @Valid final GroupingFilterPagingRequest filter) {

    Future<List<DBObject>> costEffectivenessAwardAmountFuture = controllerLookupService.asyncInvoke(
            new AsyncBeanParamControllerMethodCallable<List<DBObject>, GroupingFilterPagingRequest>() {
                @Override//from  w ww  .ja  v  a  2s.  co m
                public List<DBObject> invokeControllerMethod(GroupingFilterPagingRequest filter) {
                    return costEffectivenessAwardAmount(filter);
                }
            }, filter);

    Future<List<DBObject>> costEffectivenessTenderAmountFuture = controllerLookupService.asyncInvoke(
            new AsyncBeanParamControllerMethodCallable<List<DBObject>, GroupingFilterPagingRequest>() {
                @Override
                public List<DBObject> invokeControllerMethod(GroupingFilterPagingRequest filter) {
                    return costEffectivenessTenderAmount(filter);
                }
            }, filter);

    //this is completely unnecessary since the #get methods are blocking
    //controllerLookupService.waitTillDone(costEffectivenessAwardAmountFuture, costEffectivenessTenderAmountFuture);

    LinkedHashMap<Object, DBObject> response = new LinkedHashMap<>();

    try {

        costEffectivenessAwardAmountFuture.get()
                .forEach(dbobj -> response.put(getYearMonthlyKey(filter, dbobj), dbobj));
        costEffectivenessTenderAmountFuture.get().forEach(dbobj -> {
            if (response.containsKey(getYearMonthlyKey(filter, dbobj))) {
                Map<?, ?> map = dbobj.toMap();
                map.remove(Keys.YEAR);
                if (filter.getMonthly()) {
                    map.remove(Keys.MONTH);
                }
                response.get(getYearMonthlyKey(filter, dbobj)).putAll(map);
            } else {
                response.put(getYearMonthlyKey(filter, dbobj), dbobj);
            }
        });

    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }

    Collection<DBObject> respCollection = response.values();

    respCollection.forEach(dbobj -> {

        BigDecimal totalTenderAmount = BigDecimal.valueOf(dbobj.get(Keys.TOTAL_TENDER_AMOUNT) == null ? 0d
                : ((Number) dbobj.get(Keys.TOTAL_TENDER_AMOUNT)).doubleValue());

        BigDecimal totalAwardAmount = BigDecimal.valueOf(dbobj.get(Keys.TOTAL_AWARD_AMOUNT) == null ? 0d
                : ((Number) dbobj.get(Keys.TOTAL_AWARD_AMOUNT)).doubleValue());

        dbobj.put(Keys.DIFF_TENDER_AWARD_AMOUNT, totalTenderAmount.subtract(totalAwardAmount));

        dbobj.put(Keys.PERCENTAGE_AWARD_AMOUNT,
                totalTenderAmount.compareTo(BigDecimal.ZERO) != 0
                        ? (totalAwardAmount.setScale(15).divide(totalTenderAmount, BigDecimal.ROUND_HALF_UP)
                                .multiply(ONE_HUNDRED))
                        : BigDecimal.ZERO);

        dbobj.put(Keys.PERCENTAGE_DIFF_AMOUNT,
                totalTenderAmount.compareTo(BigDecimal.ZERO) != 0
                        ? (((BigDecimal) dbobj.get(Keys.DIFF_TENDER_AWARD_AMOUNT)).setScale(15)
                                .divide(totalTenderAmount, BigDecimal.ROUND_HALF_UP).multiply(ONE_HUNDRED))
                        : BigDecimal.ZERO);

    });

    return new ArrayList<>(respCollection);
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

private void checkBigDecimal(ResultSet rs, String[] value) throws SQLException {
    for (String v : value) {
        assertTrue(rs.next());/*ww  w .j a v a  2s.  co m*/
        BigDecimal x = rs.getBigDecimal(1);
        trace("v=" + v + " x=" + x);
        if (v == null) {
            assertTrue(x == null);
        } else {
            assertTrue(x.compareTo(new BigDecimal(v)) == 0);
        }
    }
    assertTrue(!rs.next());
}