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:com.qcadoo.mes.orders.hooks.OrderHooks.java

private void setProductQuantity(final Entity order) {
    Long orderId = order.getId();

    if (orderId == null) {
        return;//  w w  w.j  a  v  a2 s . c o  m
    }

    Entity orderFromDB = orderService.getOrder(orderId);

    BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
    BigDecimal commissionedPlannedQuantity = order.getDecimalField(OrderFields.COMMISSIONED_PLANNED_QUANTITY);
    BigDecimal commissionedCorrectedQuantity = order
            .getDecimalField(OrderFields.COMMISSIONED_CORRECTED_QUANTITY);
    BigDecimal plannedQuantityFromDB = orderFromDB.getDecimalField(OrderFields.PLANNED_QUANTITY);

    if (plannedQuantityFromDB.compareTo(plannedQuantity) != 0) {
        String state = order.getStringField(OrderFields.STATE);

        if (OrderState.PENDING.getStringValue().equals(state)) {
            order.setField(OrderFields.COMMISSIONED_PLANNED_QUANTITY, numberService.setScale(plannedQuantity));
        }
        if (OrderState.ACCEPTED.getStringValue().equals(state)
                || OrderState.IN_PROGRESS.getStringValue().equals(state)
                || OrderState.INTERRUPTED.getStringValue().equals(state)) {
            order.setField(OrderFields.COMMISSIONED_CORRECTED_QUANTITY,
                    numberService.setScale(plannedQuantity));
        }
    } else {
        if (BigDecimal.ZERO.compareTo(BigDecimalUtils.convertNullToZero(commissionedCorrectedQuantity)) != 0) {
            order.setField(OrderFields.PLANNED_QUANTITY, numberService.setScale(commissionedCorrectedQuantity));
        } else if (BigDecimal.ZERO
                .compareTo(BigDecimalUtils.convertNullToZero(commissionedPlannedQuantity)) != 0) {
            order.setField(OrderFields.PLANNED_QUANTITY, numberService.setScale(commissionedPlannedQuantity));
        }
    }

    BigDecimal doneQuantityFromDB = orderFromDB.getDecimalField(OrderFields.DONE_QUANTITY);
    BigDecimal doneQuantity = order.getDecimalField(OrderFields.DONE_QUANTITY);
    BigDecimal amountOfProductProducedFromDB = orderFromDB
            .getDecimalField(OrderFields.AMOUNT_OF_PRODUCT_PRODUCED);
    BigDecimal amountOfProductProduced = order.getDecimalField(OrderFields.AMOUNT_OF_PRODUCT_PRODUCED);

    String typeOfProductionRecording = order.getStringField(L_TYPE_OF_PRODUCTION_RECORDING);

    if (StringUtils.isEmpty(typeOfProductionRecording)) {
        if (BigDecimalUtils.convertNullToZero(doneQuantity)
                .compareTo(BigDecimalUtils.convertNullToZero(doneQuantityFromDB)) != 0) {
            order.setField(OrderFields.AMOUNT_OF_PRODUCT_PRODUCED, numberService.setScale(doneQuantity));
        } else if (BigDecimalUtils.convertNullToZero(amountOfProductProduced)
                .compareTo(BigDecimalUtils.convertNullToZero(amountOfProductProducedFromDB)) != 0) {
            order.setField(OrderFields.DONE_QUANTITY, numberService.setScale(amountOfProductProduced));
        }
    } else {
        order.setField(OrderFields.AMOUNT_OF_PRODUCT_PRODUCED, numberService.setScale(doneQuantity));
    }
}

From source file:au.org.ala.delta.editor.slotfile.directive.DirOutDefault.java

private void writeIntItemCharSetArgs(int argType, DirectiveArguments directiveArgs, StringBuilder textBuffer) {
    if (directiveArgs.size() > 0) {

        State curState = State.IN_MODIFIERS;
        List<Integer> dataList = new ArrayList<Integer>();
        for (DirectiveArgument<?> vectIter : directiveArgs.getDirectiveArguments()) {
            BigDecimal curVal = vectIter.getValue();
            if (curState == State.IN_MODIFIERS && !BigDecimal.ZERO.equals(curVal)) {
                if (curVal.compareTo(BigDecimal.ZERO) > 0)
                    break; // No taxa present, so nothing else matters
                curState = State.IN_TAXA;
                dataList.clear();//  w  ww . j  a v a  2  s .com
                textBuffer.append(" (");
            }
            if (curState == State.IN_TAXA && curVal.compareTo(BigDecimal.ZERO) > 0) {
                if (vectIter.getData().size() >= 0)
                    appendRange(dataList, ' ', true, textBuffer);
                textBuffer.append(')');
                curState = State.IN_CHARS;
                dataList.clear();
            }
            if (curState == State.IN_CHARS && curVal.compareTo(BigDecimal.ZERO) >= 0)
                break; // Should never happen, unless arguments were somehow reordered
            if ((Integer) vectIter.getId() > 0)
                dataList.add((Integer) vectIter.getId());
            else
                appendKeyword(textBuffer, vectIter.getText(), false,
                        !(curState == State.IN_TAXA && textBuffer.charAt(textBuffer.length() - 1) == '('));
        }
        if (dataList.size() > 0) {
            textBuffer.append(' ');
            appendRange(dataList, ' ', true, textBuffer);
        }
    }
}

From source file:net.sourceforge.fenixedu.domain.Shift.java

public BigDecimal getMaxLessonDuration() {
    BigDecimal maxHours = BigDecimal.ZERO;
    for (Lesson lesson : getAssociatedLessonsSet()) {
        BigDecimal lessonHours = lesson.getUnitHours();
        if (maxHours.compareTo(lessonHours) == -1) {
            maxHours = lessonHours;/*from  w  w  w .j  ava  2  s . c om*/
        }
    }
    return maxHours;
}

From source file:com.opensky.osis.BraintreeConnector.java

/**
 * Custom processor/*  www . ja v  a2 s  . co m*/
 *
 * {@sample.xml ../../../doc/braintree-connector.xml.sample braintree:sale}
 *
 * @param token The payment method token
 * @param amount The transaction amount
 * @param orderId The order id
 * @param customerId The customer id
 * @param settle Flag to settle immediately or just auth
 * @return The Result
 */
@Processor
public Result sale(String token, BigDecimal amount, String orderId, String customerId,
        @Optional @Default(value = "false") Boolean settle) {
    log.info("Calling sale with token: {} amount: {} orderId: {} customerId: {} settle: {}",
            new Object[] { token, amount, orderId, customerId, settle });

    Validate.notNull(token, "token should not be null");
    Validate.notNull(amount, "amount should not be null");
    Validate.isTrue(amount.compareTo(BigDecimal.ZERO) >= 0, "amount must be >= 0");
    Validate.notNull(orderId, "orderId should not be null");
    Validate.notNull(customerId, "customerId should not be null");

    try {
        TransactionRequest request = getRequestFactory().transactionRequest().amount(amount).type(Type.SALE)
                .orderId(orderId).customerId(customerId).paymentMethodToken(token).options()
                .submitForSettlement(settle).done();

        Result<Transaction> res = getGateway().transaction().sale(request);
        return res;
    } catch (BraintreeException e) {
        return new ExceptionResult(e.getClass().getCanonicalName());
    }
}

From source file:es.upm.fiware.rss.expenditureLimit.server.service.ExpenditureLimitDataChecker.java

/**
 * /*  ww  w  . ja va2s  .co  m*/
 * @param urlEndUserId
 * @param appPorviderId
 * @param currency
 * @throws RSSException
 */
public void checkChargeRequiredParameters(String urlEndUserId, String service, String aggregator,
        String appPorviderId, String currency, String chargeType, BigDecimal amount) throws RSSException {

    if (null == urlEndUserId || urlEndUserId.trim().isEmpty() || null == service || service.trim().isEmpty()
            || null == aggregator || aggregator.trim().isEmpty() || null == appPorviderId
            || appPorviderId.trim().isEmpty() || null == currency || currency.trim().isEmpty()
            || null == chargeType || chargeType.trim().isEmpty() || null == amount
            || amount.compareTo(new BigDecimal(0)) < 1) {
        String[] args = {
                "Required parameters not found:enUserId, service, aggregator, appProvider, currency, chargeType, amount." };
        throw new RSSException(UNICAExceptionType.NON_EXISTENT_RESOURCE_ID, args);
    }

}

From source file:com.gst.infrastructure.core.api.JsonCommand.java

private boolean differenceExists(final BigDecimal baseValue, final BigDecimal workingCopyValue) {
    boolean differenceExists = false;

    if (baseValue != null) {
        if (workingCopyValue != null) {
            differenceExists = baseValue.compareTo(workingCopyValue) != 0;
        } else {//from  w ww.j a  v  a2s .  c  o m
            differenceExists = true;
        }
    } else {
        differenceExists = workingCopyValue != null;
    }

    return differenceExists;
}

From source file:com.feilong.core.bean.ConvertUtilTest.java

/**
 * Test./*from ww  w . ja v a2  s  .  c o m*/
 */
@Test
public void test() {
    BigDecimal a = toBigDecimal("1.000000");
    BigDecimal b = new BigDecimal(1);
    LOGGER.debug(a.compareTo(b) + "");
    LOGGER.debug(a.equals(b) + "");
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJNumberEditor.java

public boolean isEditValid() {
    final String S_ProcName = "isEditValid";
    if (!hasValue()) {
        setValue(null);/*from w  ww . j a va2 s.  c o m*/
        return (true);
    }

    boolean retval = super.isEditValid();
    if (retval) {
        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 = false;
        } 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)) {
                retval = false;
            }
        } 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)) {
                retval = false;
            }
        } 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)) {
                retval = false;
            }
        } else if (obj instanceof BigDecimal) {
            BigDecimal v = (BigDecimal) obj;
            BigDecimal min = getMinValue();
            BigDecimal max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } 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)) {
                retval = false;
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number");
        }
    }
    return (retval);
}

From source file:net.jmhertlein.alphonseirc.AlphonseBot.java

private void handleBillyCommand(String target) {
    sendMessage(target, "Measuring Billium levels...");
    int total = previousSenders.size(), billy = 0;
    for (String previousSender : previousSenders) {
        if (previousSender.equals("brodes")) {
            billy++;/*w  w w  .j  a  v  a2s .  c  om*/
        }
    }
    if (total > 0) {
        BigDecimal conc = new BigDecimal(((float) billy) / total * 100);
        sendMessage(target, "Current Billium concentration: " + conc.toPlainString() + "%");
        String status;
        if (conc.compareTo(new BigDecimal(80)) > 0) {
            status = "!!DANGER!! OVERDOSE IMMENENT";
        } else if (conc.compareTo(new BigDecimal(50)) > 0) {
            status = "WARNING - DANGEROUS LEVELS";
        } else if (conc.compareTo(new BigDecimal(30)) > 0) {
            status = "Caution - Levels rising, but stable";
        } else {
            status = "Billium levels negligible.";
        }
        sendMessage(target, "Current status: " + status);
    } else {
        sendMessage(target, "Billium levels negligible.");
    }
}