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:org.kuali.kpme.tklm.time.util.TKUtilsTest.java

@Test
public void testConvertMinutesToHours() throws Exception {
    BigDecimal minutes = new BigDecimal(60);
    BigDecimal hours = TKUtils.convertMinutesToHours(minutes);
    Assert.assertEquals("Wrong Hours", 1, hours.intValue());
}

From source file:org.egov.infstr.utils.EgovMasterDataCaching.java

/**
 * This method returns a list of LabelValueBean using the resultList object.
 * @param resultList the rs/*  w ww.ja  v a2  s.  c o  m*/
 * @return List
 * @throws ApplicationRuntimeException the eGOV runtime exception
 */

private List resultSetToArrayList(final List<Object[]> resultList) throws ApplicationRuntimeException {

    final List list = new ArrayList();
    LabelValueBean labelValueBean = null;
    BigDecimal id;
    try {
        for (final Object[] objArr : resultList) {
            labelValueBean = new LabelValueBean();
            id = (BigDecimal) objArr[0];
            labelValueBean.setId(id.intValue());
            labelValueBean.setName((String) objArr[1]);
            list.add(labelValueBean);
        }
    } catch (final Exception e) {
        LOGGER.error("Error occurred in EgovMasterDataCaching resultSetToArrayList", e);
        throw new ApplicationRuntimeException("Error occurred in EgovMasterDataCaching resultSetToArrayList",
                e);
    }
    return list;
}

From source file:org.openvpms.component.system.common.jxpath.OpenVPMSTypeConverter.java

/**
 * Convert a {@link BigDecimal} to another type
 * /*from  w w  w.  ja va  2 s .co m*/
 * @param type
 *            the class to convert too
 * @param value
 *            the value to convert
 * @return Number
 *            the converted number of null.
 *            
 */
protected Number allocateNumber(Class type, BigDecimal value) {
    if (type == Byte.class || type == byte.class) {
        return new Byte(value.byteValue());
    }
    if (type == Short.class || type == short.class) {
        return new Short(value.shortValue());
    }
    if (type == Integer.class || type == int.class) {
        return new Integer(value.intValue());
    }
    if (type == Long.class || type == long.class) {
        return new Long(value.longValue());
    }
    if (type == Float.class || type == float.class) {
        return new Float(value.floatValue());
    }
    if (type == Double.class || type == double.class) {
        return new Double(value.doubleValue());
    }
    if (type == BigDecimal.class) {
        return value;
    }
    if (type == BigInteger.class) {
        return BigInteger.valueOf(value.longValue());
    }

    if (type == Money.class) {
        return new Money((BigDecimal) value);
    }

    return null;
}

From source file:richtercloud.reflection.form.builder.components.AmountMoneyPanel.java

/**
 * Creates a new AmountMoneyPanel with {@link #DEFAULT_CURRENCIES} and
 * {@code additionalCurrencies}.//from  ww w.j av  a  2s  . c  o  m
 * @param amountMoneyCurrencyStorage
 * @param amountMoneyUsageStatisticsStorage
 * @param amountMoneyExchangeRateRetriever
 * @param messageHandler
 * @throws richtercloud.reflection.form.builder.components.AmountMoneyCurrencyStorageException
 */
public AmountMoneyPanel(AmountMoneyCurrencyStorage amountMoneyCurrencyStorage,
        AmountMoneyUsageStatisticsStorage amountMoneyUsageStatisticsStorage,
        AmountMoneyExchangeRateRetriever amountMoneyExchangeRateRetriever, MessageHandler messageHandler)
        throws AmountMoneyCurrencyStorageException {
    this.messageHandler = messageHandler;
    Set<Currency> exchangeRateRetrieverSupportedCurrencies = amountMoneyExchangeRateRetriever
            .getSupportedCurrencies();
    for (Currency currency : amountMoneyCurrencyStorage.getCurrencies()) {
        if (!exchangeRateRetrieverSupportedCurrencies.contains(currency)) {
            try {
                currency.getExchangeRate();
            } catch (ConversionException ex) {
                throw new IllegalArgumentException(String.format(
                        "Currency %s isn't supported by exchange rate retriever and doesn't have an exchange rate set",
                        currency));
            }
        }
        currencyComboBoxModel.addElement(currency);
    }
    initComponents();
    ((SpinnerNumberModel) amountIntegerSpinner.getModel())
            .setMaximum(((long) (Double.MAX_VALUE * MINIMAL_STEP)));
    //cast to long is necessary to make ChangeListener of
    //amountIntegerSpinner be notified
    this.amountIntegerSpinner.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            for (AmountMoneyPanelUpdateListener updateListener : AmountMoneyPanel.this.updateListeners) {
                updateListener.onUpdate(new AmountMoneyPanelUpdateEvent(getValue()));
            }
        }
    });
    this.amountDecimalSpinner.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            for (AmountMoneyPanelUpdateListener updateListener : AmountMoneyPanel.this.updateListeners) {
                updateListener.onUpdate(new AmountMoneyPanelUpdateEvent(getValue()));
            }
        }
    });
    this.currencyComboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            //convert after currency change (not necessary, but useful)
            Currency oldCurrency = (Currency) itemEvent.getItem();
            Currency newCurrency = (Currency) itemEvent.getItemSelectable().getSelectedObjects()[0];
            double newAmount;
            try {
                newAmount = oldCurrency.getConverterTo(newCurrency).convert(getAmount());
            } catch (ConversionException ex) {
                try {
                    //if the exchange rate isn't set
                    AmountMoneyPanel.this.amountMoneyExchangeRateRetriever.retrieveExchangeRate(newCurrency);
                    AmountMoneyPanel.this.amountMoneyExchangeRateRetriever.retrieveExchangeRate(oldCurrency);
                    newAmount = oldCurrency.getConverterTo(newCurrency).convert(getAmount());
                } catch (AmountMoneyCurrencyStorageException amountMoneyCurrencyStorageException) {
                    throw new RuntimeException(amountMoneyCurrencyStorageException);
                }
            }
            AmountMoneyPanel.this.amountIntegerSpinner.setValue((int) newAmount);
            BigDecimal bd = new BigDecimal(newAmount * 100);
            bd = bd.setScale(0, //newScale
                    RoundingMode.HALF_UP //the rounding mode "taught in school"
            );
            AmountMoneyPanel.this.amountDecimalSpinner.setValue(bd.intValue() % 100);
            //notify registered update listeners
            for (AmountMoneyPanelUpdateListener updateListener : AmountMoneyPanel.this.updateListeners) {
                updateListener.onUpdate(new AmountMoneyPanelUpdateEvent(getValue()));
            }
        }
    });
    this.amountMoneyCurrencyStorage = amountMoneyCurrencyStorage;
    this.amountMoneyUsageStatisticsStorage = amountMoneyUsageStatisticsStorage;
    this.amountMoneyExchangeRateRetriever = amountMoneyExchangeRateRetriever;
}

From source file:org.pentaho.pms.schema.concept.ConceptUtilityBase.java

public int getRelativeSize() {
    ConceptPropertyInterface property = concept.getProperty(DefaultPropertyID.RELATIVE_SIZE.getId());
    if (property != null) {
        BigDecimal value = (BigDecimal) property.getValue();
        if (value != null) {
            return value.intValue();
        }//from  w  w w. j  a  v  a  2s .c om
    }
    return -1;
}

From source file:org.kalypso.model.hydrology.internal.binding.cm.LinearSumGenerator.java

@Override
public long getLastModifiedTimeseries() {
    final IFeatureBindingCollection<ICatchment> catchments = getCatchments();
    if (catchments == null || catchments.size() == 0)
        return -1;

    long result = -1;
    for (final ICatchment catchment : catchments) {
        final IFeatureBindingCollection<IFactorizedTimeseries> timeseries = catchment.getFactorizedTimeseries();
        for (final IFactorizedTimeseries oneTimeseries : timeseries) {
            final ZmlLink timeseriesLink = oneTimeseries.getTimeseriesLink();
            final BigDecimal factor = oneTimeseries.getFactor();
            if (timeseriesLink == null || !timeseriesLink.isLinkExisting() || factor == null
                    || factor.intValue() == 0)
                continue;

            final File javaFile = timeseriesLink.getJavaFile();
            final long lastModified = javaFile.lastModified();
            result = Math.max(result, lastModified);
        }/* ww w .j  av  a 2s .c o m*/
    }

    return result;
}

From source file:org.kuali.kpme.tklm.time.util.TKUtilsTest.java

@Test
public void testGetHoursBetween() throws Exception {
    DateTime beginDateTime = new DateTime(2010, 10, 16, 12, 3, 0, 0, TKUtils.getSystemDateTimeZone());
    DateTime endDateTime = new DateTime(2010, 10, 17, 12, 3, 0, 0, TKUtils.getSystemDateTimeZone());
    BigDecimal hours = TKUtils.getHoursBetween(beginDateTime.getMillis(), endDateTime.getMillis());
    Assert.assertEquals("Wrong hours", 24, hours.intValue());

    endDateTime = new DateTime(2010, 10, 16, 18, 3, 0, 0, TKUtils.getSystemDateTimeZone());
    hours = TKUtils.getHoursBetween(beginDateTime.getMillis(), endDateTime.getMillis());
    Assert.assertEquals("Wrong hours", 6, hours.intValue());

    endDateTime = new DateTime(2010, 10, 16, 18, 0, 0, 0, TKUtils.getSystemDateTimeZone());
    hours = TKUtils.getHoursBetween(beginDateTime.getMillis(), endDateTime.getMillis());
    Assert.assertEquals("Wrong hours", 5, hours.intValue());

}

From source file:net.sourceforge.fenixedu.domain.residence.StudentsPerformanceReport.java

private int getApprovedGradeValuesSum(final Student student) {
    Collection<ICurriculumEntry> entries = student.getLastActiveRegistration()
            .getCurriculum(getExecutionSemester().getEndDateYearMonthDay().toDateTimeAtCurrentTime(),
                    getExecutionSemester().getExecutionYear(), null)
            .getCurriculumEntries();// ww  w. ja  va  2s  .  c  om
    BigDecimal sum = new BigDecimal(0d);

    for (final ICurriculumEntry entry : entries) {
        if (entry.getGrade().isNumeric()) {
            final BigDecimal weigth = entry.getWeigthForCurriculum();
            if (GradeScale.TYPE20.equals(entry.getGrade().getGradeScale())) {
                sum = sum.add(entry.getGrade().getNumericValue());
            }
        }
    }

    return sum.intValue();
}

From source file:fr.univlorraine.mondossierweb.services.apogee.MultipleApogeeServiceImpl.java

@Override
public boolean isBoursier(String cod_ind, String cod_anu) {
    if (StringUtils.hasText(cod_ind) && StringUtils.hasText(cod_anu)) {
        @SuppressWarnings("unchecked")
        BigDecimal nbInsAdmBoursier = (BigDecimal) entityManagerApogee
                .createNativeQuery("select count(*) from ins_adm_anu iaa " + "where iaa.COD_ANU = " + cod_anu
                        + " " + "and iaa.cod_soc = '" + Utils.COD_SOC_BOURSIER + "' " + "and iaa.ETA_IAA = 'E' "
                        + "and iaa.cod_ind = " + cod_ind)
                .getSingleResult();//  www  .  j  a  v  a 2s . co m
        return nbInsAdmBoursier.intValue() > 0;
    }
    return false;
}

From source file:com.ipcglobal.fredimport.xls.DistinctCategoriesSpreadsheet.java

/**
 * Populate cell.// w ww  . ja va  2s  .  c  om
 *
 * @param rowData the row data
 * @param colCnt the col cnt
 * @param dataType the data type
 * @param obj the obj
 * @throws Exception the exception
 */
private void populateCell(Row rowData, int colCnt, DataType dataType, Object obj) throws Exception {
    int cellType = 0;

    if (dataType == DataType.Numeric)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    else if (dataType == DataType.NumericDec2)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    else if (dataType == DataType.Text)
        cellType = XSSFCell.CELL_TYPE_STRING;
    else if (dataType == DataType.Date)
        cellType = XSSFCell.CELL_TYPE_STRING;
    else if (dataType == DataType.Accounting)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    else if (dataType == DataType.Percent)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    Cell cellData = rowData.createCell(colCnt, cellType);

    short findFormat = -1;
    if (dataType == DataType.Date)
        findFormat = formatMmDdYyyy;
    else if (dataType == DataType.Percent)
        findFormat = formatPercent;
    else if (dataType == DataType.Accounting)
        findFormat = formatAccounting;
    else if (dataType == DataType.Numeric)
        findFormat = formatNumeric;
    else if (dataType == DataType.NumericDec2)
        findFormat = formatNumericDec2;
    else
        findFormat = formatGeneral;
    CellStyle style = findCellStyle("Arial", HSSFColor.BLACK.index, (short) 11, XSSFFont.BOLDWEIGHT_NORMAL,
            cellStyleFromDataAlign(findAlignByDataType(dataType)), XSSFCellStyle.VERTICAL_TOP, BG_COLOR_NONE,
            CellBorder.All_Thin, findFormat);
    cellData.setCellStyle(style);

    if (dataType == DataType.Numeric || dataType == DataType.NumericDec2 || dataType == DataType.Accounting
            || dataType == DataType.Percent) {
        if (obj == null)
            ; // leave the cell empty
        else if (obj instanceof BigDecimal) {
            BigDecimal value = (BigDecimal) obj;
            if (value != null)
                cellData.setCellValue(value.doubleValue());
        } else if (obj instanceof Integer) {
            Integer value = (Integer) obj;
            if (value != null)
                cellData.setCellValue(value.intValue());
        } else if (obj instanceof Long) {
            Long value = (Long) obj;
            if (value != null)
                cellData.setCellValue(value.longValue());
        } else if (obj instanceof Double) {
            Double value = (Double) obj;
            if (value != null)
                cellData.setCellValue(value.doubleValue());
        } else if (obj instanceof Short) {
            Short value = (Short) obj;
            if (value != null)
                cellData.setCellValue(value.shortValue());
        } else if (obj instanceof String) {
            String value = (String) obj;
            if (value != null)
                cellData.setCellValue(value);
        } else
            throw new Exception("Unsupported numeric type: " + obj.getClass().getSimpleName());
    } else if (dataType == DataType.Date) {
        Date date = (Date) obj;
        if (date != null)
            cellData.setCellValue(date);
    } else {
        cellData.setCellValue((String) obj);
    }
}