Example usage for java.math BigDecimal intValue

List of usage examples for java.math BigDecimal intValue

Introduction

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

Prototype

@Override
public int intValue() 

Source Link

Document

Converts this BigDecimal to an int .

Usage

From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java

/**
 * Converts a numeric value from its BigDecimal representation to its native form
 * //  w  w  w  .  j  ava  2  s  .c o  m
 * @param value
 * @param propertyId
 * @return
 */
protected Number convertNumber(BigDecimal value, String propertyId) {
    Class<?> clazz = getEditablePropertyClass(propertyId);
    if (clazz.equals(Integer.class)) {
        return value.intValue();
    } else if (clazz.equals(Long.class)) {
        return value.longValue();
    } else if (clazz.equals(BigDecimal.class)) {
        return value;
    }
    return null;
}

From source file:org.goko.tools.commandpanel.CommandPanelPart.java

protected void enableAdaptiveSpinner() throws GkException {
    if (jogStepSpinner != null) {
        BigDecimal selection = getDataModel().getJogIncrement()
                .multiply(new BigDecimal(10).pow(jogStepSpinner.getDigits()))
                .value(GokoPreference.getInstance().getLengthUnit());

        jogStepSpinner.setSelection(selection.intValue());
        jogStepSpinner.addSelectionListener(new SelectionAdapter() {
            @Override/*from   w w  w.j  a  v a  2  s . c o m*/
            public void widgetSelected(SelectionEvent event) {
                int selection = jogStepSpinner.getSelection();
                if (selection < 100) {
                    jogStepSpinner.setIncrement(10);
                } else if (selection < 1000) {
                    jogStepSpinner.setIncrement(100);
                } else if (selection < 10000) {
                    jogStepSpinner.setIncrement(1000);
                }
                BigDecimal step = new BigDecimal(selection)
                        .divide(new BigDecimal(10).pow(jogStepSpinner.getDigits()));
                try {
                    getDataModel().setJogIncrement(
                            Length.valueOf(step, GokoPreference.getInstance().getLengthUnit()));
                } catch (GkException e) {
                    LOG.error(e);
                }
            }
        });
    }

    jogSpeedSpinner.setSelection(
            (int) (getDataModel().getJogSpeed().doubleValue(GokoPreference.getInstance().getSpeedUnit())
                    * Math.pow(10, jogSpeedSpinner.getDigits())));

    jogSpeedSpinner.setIncrement(10);
    jogSpeedSpinner.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            try {
                getDataModel().setJogSpeed(Speed.valueOf(jogSpeedSpinner.getSelection(),
                        GokoPreference.getInstance().getSpeedUnit()));
            } catch (GkException e) {
                LOG.error(e);
            }
        }
    });

}

From source file:org.kuali.ole.select.document.web.struts.OlePaymentRequestAction.java

/**
 * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#insertSourceLine(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*w  w  w.j a  va2 s. co m*/
@Override
public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // It would be preferable to find a way to genericize the KualiAccountingDocument methods but this will work for now
    PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form;

    // index of item selected
    int itemIndex = getSelectedLine(request);
    PurApItem item = null;

    // if custom processing of an accounting line is not done then insert a line generically.
    if (processCustomInsertAccountingLine(purapForm, request) == false) {
        String errorPrefix = null;
        PurApAccountingLine line = null;

        boolean rulePassed = false;
        if (itemIndex >= 0) {
            item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex));
            //Calculating the dollar amount for the accounting Line.
            PurApAccountingLine lineItem = item.getNewSourceLine();
            if (lineItem.getAccountLinePercent() != null) {
                BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100));
                lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent))));
            } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent() == null) {
                KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100));
                BigDecimal dollarToPercent = dollar.bigDecimalValue()
                        .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR);
                lineItem.setAccountLinePercent(dollarToPercent);
            }
            line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem);
            //end
            //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
            errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "["
                    + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME;
            rulePassed = SpringContext.getBean(KualiRuleService.class)
                    .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
        } else if (itemIndex == -2) {
            //corrected: itemIndex == -2 is the only case for distribute account
            //This is the case when we're inserting an accounting line for distribute account.
            line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine();
            //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
            errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE;
            rulePassed = SpringContext.getBean(KualiRuleService.class)
                    .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
        }
        AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine();
        if (accountingLineBase != null) {
            String accountNumber = accountingLineBase.getAccountNumber();
            String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode();
            Map<String, String> criteria = new HashMap<String, String>();
            criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
            criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
            Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class,
                    criteria);
            rulePassed = checkForValidAccount(account);
        }

        /*  if (rulePassed) {
        // add accountingLine
        SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line);
        if (itemIndex >=0) {
            insertAccountingLine(purapForm, item, line);
            // clear the temp account
            item.resetAccount();
        }
        else if (itemIndex == -2) {
            //this is the case for distribute account
            ((PurchasingFormBase)purapForm).addAccountDistributionsourceAccountingLine(line);
        }
          }*/
        if (rulePassed) {
            // add accountingLine
            SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line);

            PurApAccountingLine newSourceLine = item.getNewSourceLine();
            List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines();

            BigDecimal initialValue = new BigDecimal(0);

            for (PurApAccountingLine accountLine : existingSourceLine) {
                initialValue = initialValue.add(accountLine.getAccountLinePercent());
            }
            if (itemIndex >= 0) {

                if ((newSourceLine.getAccountLinePercent()
                        .intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED
                        && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT
                                .subtract(initialValue).intValue())
                        && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) {
                    if (OleSelectConstant.MAX_PERCENT.subtract(initialValue)
                            .intValue() != OleSelectConstant.ZERO) {
                        insertAccountingLine(purapForm, item, line);
                    }
                } else {
                    checkAccountingLinePercent(newSourceLine);

                }
                for (PurApAccountingLine oldSourceAccountingLine : item.getSourceAccountingLines()) {
                    if (oldSourceAccountingLine instanceof PaymentRequestAccount) {
                        ((PaymentRequestAccount) oldSourceAccountingLine)
                                .setExistingAmount(oldSourceAccountingLine.getAmount());
                    }
                }
                List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines();
                BigDecimal totalPercent = new BigDecimal(100);
                BigDecimal initialPercent = new BigDecimal(0);
                for (PurApAccountingLine purApAccountingLine : existingAccountingLine) {
                    initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent());

                }
                initialPercent = totalPercent.subtract(initialPercent);
                BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT);
                if (maxPercent.intValue() == OleSelectConstant.ZERO) {
                    item.resetAccount(OleSelectConstant.ZERO_PERCENT);

                } else {
                    item.resetAccount(initialPercent);

                }
            } else if (itemIndex == -2) {
                //this is the case for distribute account
                ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line);
            }
        }
    }

    return mapping.findForward(OLEConstants.MAPPING_BASIC);
}

From source file:ch.elexis.data.TarmedOptifier.java

/**
 * Get double as int rounded half up.//from w w w .j  av a2 s  .c o m
 * 
 * @param value
 * @return
 */
private int doubleToInt(double value) {
    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(0, RoundingMode.HALF_UP);
    return bd.intValue();
}

From source file:org.openvpms.esci.adapter.map.invoice.InvoiceMapperImpl.java

/**
 * Returns the package size.//from w  w  w .j a v a  2s. co  m
 *
 * @param line the invoice line
 * @param pkg  the expected package, or <tt>null</tt> if it is not known
 * @return the package size, or <tt>0</tt> if it is not known
 * @throws ESCIAdapterException if the package size is incorrectly specified
 */
private int getPackageSize(UBLInvoiceLine line, Package pkg) {
    int result;
    BigDecimal packageSize = line.getPackSizeNumeric();
    int expectedSize = (pkg != null) ? pkg.getPackageSize() : 0;
    int invoiceSize;
    try {
        invoiceSize = packageSize.intValueExact();
    } catch (ArithmeticException exception) {
        ErrorContext context = new ErrorContext(line, "PackSizeNumeric");
        String intValue = Integer.toString(packageSize.intValue());
        throw new ESCIAdapterException(ESCIAdapterMessages.ublInvalidValue(context.getPath(), context.getType(),
                context.getID(), intValue, packageSize.toString()));
    }
    if (expectedSize != 0) {
        if (invoiceSize != 0 && invoiceSize != expectedSize) {
            log.warn("Different package size received for invoice. Expected package size=" + expectedSize
                    + ", invoiced package size=" + invoiceSize); // TODO - log context
        }
        result = expectedSize;
    } else {
        result = invoiceSize;
    }
    return result;
}

From source file:com.etcc.csc.dao.OraclePaymentDAO.java

public boolean statementDataAvailable(String dbSessionId, String ipAddress, String loginId, String ipAddress1,
        BigDecimal docId, String docType, BigDecimal statementId, BigDecimal invoiceId, BigDecimal accountId,
        String licPlate, String licPlateState) {
    try {/*  w w w.j  a  v a  2  s.com*/

        setConnection(Util.getDbConnection());
        OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };
        BigDecimal result = new OLCSC_INV(conn).STATEMENT_DATA_AVAILABLE(dbSessionId, ipAddress, loginId, docId,
                docType, statementId, invoiceId, accountId, licPlate, licPlateState, O_ERROR_MSG_ARR);
        System.out.println(result.intValue() == 1);
        return (result.intValue() == 1);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        closeConnection();
    }
    return false;
}

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

public static int mod(int b0, BigDecimal b1) {
    return mod(b0, b1.intValue());
}

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

public static int ceil(int b0, BigDecimal b1) {
    return ceil(b0, b1.intValue());
}

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

public static int floor(int b0, BigDecimal b1) {
    return floor(b0, b1.intValue());
}

From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java

/**
 * Converts a numeric value to its string representation
 * /*from  w w  w. j  a v a 2  s . com*/
 * @param value
 *            the BigDecimal value
 * @param propertyId
 *            the ID of the property
 * @return
 */
protected String convertToString(BigDecimal value, String propertyId) {
    if (value == null) {
        return null;
    }

    Class<?> clazz = getEditablePropertyClass(propertyId);
    if (clazz.equals(Integer.class)) {
        return VaadinUtils.integerToString(true, value.intValue());
    } else if (clazz.equals(Long.class)) {
        return VaadinUtils.longToString(true, value.longValue());
    } else if (clazz.equals(BigDecimal.class)) {
        return VaadinUtils.bigDecimalToString(false, true, value);
    }
    return null;
}