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:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java

@Override
public EBusDateTime decodeInt(byte[] data) throws EBusTypeException {

    if (data == null) {
        // TODO replace value
        return null;
    }// w  w  w. ja va 2  s .  c  o  m

    IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD);
    IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD);
    IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR);

    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    BigDecimal day = null;
    BigDecimal month = null;
    BigDecimal year = null;

    if (data.length != getTypeLength()) {
        throw new EBusTypeException(
                String.format("Input byte array must have a length of %d bytes!", getTypeLength()));
    }

    if (StringUtils.equals(variant, SHORT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, DEFAULT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, HEX_SHORT)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, HEX)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, DAYS)) {
        BigDecimal daysSince1900 = wordType.decode(data);
        calendar.set(1900, 0, 1, 0, 0);
        calendar.add(Calendar.DAY_OF_YEAR, daysSince1900.intValue());
    }

    if (day != null && month != null && year != null) {
        if (day.intValue() < 1 || day.intValue() > 31) {
            throw new EBusTypeException("A valid day must be in a range between 1-31 !");
        }
        if (month.intValue() < 1 || month.intValue() > 12) {
            throw new EBusTypeException("A valid day must be in a range between 1-12 !");
        }
    }

    if (year != null) {
        if (year.intValue() < 70) {
            year = year.add(new BigDecimal(2000));
        } else {
            year = year.add(new BigDecimal(1900));
        }
        calendar.set(Calendar.YEAR, year.intValue());
    }

    if (month != null) {
        calendar.set(Calendar.MONTH, month.intValue() - 1);
    }

    if (day != null && day.intValue() > 0 && day.intValue() < 32) {
        calendar.set(Calendar.DAY_OF_MONTH, day.intValue());
    }

    return new EBusDateTime(calendar, false, true);
}

From source file:com.glaf.core.db.mybatis2.SqlMapClientDAOImpl.java

public Paging getPage(int pageNo, int pageSize, SqlExecutor countExecutor, SqlExecutor queryExecutor) {
    if (LogUtils.isDebug()) {
        logger.debug("count executor:" + countExecutor);
        logger.debug("query executor:" + queryExecutor);
    }//from   w  w w  .  j  a va  2s.co m
    Paging page = new Paging();

    if (pageSize <= 0) {
        pageSize = Paging.DEFAULT_PAGE_SIZE;
    }
    if (pageNo <= 0) {
        pageNo = 1;
    }

    Object params = countExecutor.getParameter();

    Object object = null;
    int totalCount = 0;

    if (params != null) {
        object = getSqlMapClientTemplate().queryForObject(countExecutor.getStatementId(), params);
    } else {
        object = getSqlMapClientTemplate().queryForObject(countExecutor.getStatementId(), null);
    }

    if (object instanceof Integer) {
        Integer iCount = (Integer) object;
        totalCount = iCount.intValue();
    } else if (object instanceof Long) {
        Long iCount = (Long) object;
        totalCount = iCount.intValue();
    } else if (object instanceof BigDecimal) {
        BigDecimal bg = (BigDecimal) object;
        totalCount = bg.intValue();
    } else if (object instanceof BigInteger) {
        BigInteger bi = (BigInteger) object;
        totalCount = bi.intValue();
    }

    if (totalCount == 0) {
        page.setRows(new java.util.concurrent.CopyOnWriteArrayList<Object>());
        page.setCurrentPage(0);
        page.setPageSize(0);
        page.setTotal(0);
        return page;
    }

    page.setTotal(totalCount);

    int maxPageNo = (page.getTotal() + (pageSize - 1)) / pageSize;
    if (pageNo > maxPageNo) {
        pageNo = maxPageNo;
    }

    List<Object> rows = null;

    Object queryParams = queryExecutor.getParameter();

    int begin = (pageNo - 1) * pageSize + 1;

    if (queryParams != null) {
        rows = getSqlMapClientTemplate().queryForList(queryExecutor.getStatementId(), queryParams, begin,
                pageSize);
    } else {
        rows = getSqlMapClientTemplate().queryForList(queryExecutor.getStatementId(), null, begin, pageSize);
    }

    page.setRows(rows);
    page.setPageSize(pageSize);
    page.setCurrentPage(pageNo);

    if (LogUtils.isDebug()) {
        logger.debug("params:" + params);
        logger.debug("rows size:" + rows.size());
    }

    return page;
}

From source file:ch.algotrader.service.ib.IBNativeOrderServiceImpl.java

@Override
public void init() {
    BigDecimal num = this.orderDao.findLastIntOrderIdByServiceType(OrderServiceType.IB_NATIVE.name());
    if (num != null) {
        long currentId = this.orderIdGenerator.updateIfGreater(num.intValue());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(EWrapperMsgGenerator.nextValidId((int) (currentId + 1)));
        }//from  www  .  ja  v a 2  s  . c  o  m
    }
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Test the function to get charged amount without total charged amount.
 *//* w  w w. j av  a 2  s  . com*/
@Test
public void getValueToAddFromTxChargedAndNotTax() {
    BigDecimal txAmount = new BigDecimal("10.10");
    DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
    tx.setFtChargedAmount(txAmount);
    tx.setFtChargedTaxAmount(null);
    BigDecimal value = utils.getValueToAddFromTx(tx);
    Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue());
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Test the function to get charged and charged tax amount without total charged amount.
 *///  w  w  w.  j  a  va2s  .  c  o  m
@Test
public void getValueToAddFromTxChargedAndTax() {
    BigDecimal txAmount = new BigDecimal("10.10");
    BigDecimal txTaxAmount = new BigDecimal("0.50");
    DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
    tx.setFtChargedAmount(txAmount);
    tx.setFtChargedTaxAmount(txTaxAmount);
    BigDecimal value = utils.getValueToAddFromTx(tx);
    Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue() + txTaxAmount.intValue());
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Test the function to get internal amount.
 *///from w w w .j av  a 2 s.  c  o  m
@Test
public void getValueToAddFromTxInternalAndNotTax() {
    BigDecimal txAmount = new BigDecimal("10.10");
    DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
    tx.setFtChargedAmount(null);
    tx.setFtChargedTaxAmount(null);
    tx.setFtInternalTotalAmount(null);
    tx.setFtInternalAmount(txAmount);
    tx.setFtInternalTaxAmount(null);
    BigDecimal value = utils.getValueToAddFromTx(tx);
    Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue());
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Test the function to get requested total amount.
 *///  ww  w  .  j  av  a  2  s.c  om
@Test
public void getValueToAddFromTxRequestedTotal() {
    BigDecimal txAmount = new BigDecimal("10.10");
    DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
    tx.setFtChargedAmount(null);
    tx.setFtChargedTaxAmount(null);
    tx.setFtInternalTotalAmount(null);
    tx.setFtInternalAmount(null);
    tx.setFtInternalTaxAmount(null);
    tx.setFtRequestTotalAmount(txAmount);
    BigDecimal value = utils.getValueToAddFromTx(tx);
    Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue());
}

From source file:com.safasoft.treeweb.dao.SupportDAO.java

/**
 * Get amount of table record options based on given SQL statement, searched text and records to be excluded
 * @param sql//  w w w  .  jav  a  2s. c  o m
 * @param searchText
 * @param excludeText
 * @return amount of table record options
 */
public Integer getRecordCountList(String sql, String searchText, String excludeText) {
    BigDecimal bd = (BigDecimal) sessionFactory
            .getCurrentSession().createSQLQuery("SELECT count(*) " + "FROM (" + sql + ") "
                    + "WHERE UPPER(name) LIKE '%" + searchText.toUpperCase() + "%' " + excludeText)
            .list().get(0);
    return bd.intValue();
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Test the function to get requested amount.
 *//*  w  w w . ja  v  a2s .c  o m*/
@Test
public void getValueToAddFromTxRequestedAmount() {
    BigDecimal txAmount = new BigDecimal("10.10");
    DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
    tx.setFtChargedAmount(null);
    tx.setFtChargedTaxAmount(null);
    tx.setFtInternalTotalAmount(null);
    tx.setFtInternalAmount(null);
    tx.setFtInternalTaxAmount(null);
    tx.setFtRequestTotalAmount(null);
    tx.setFtRequestAmount(txAmount);
    tx.setFtRequestTaxAmount(null);
    BigDecimal value = utils.getValueToAddFromTx(tx);
    Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue());
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Test the function to get nulled requested amount.
 *///from  w  w w  .  j  a v a2s.c o  m
@Test
public void getValueToAddFromTxNulledAmount() {
    BigDecimal txAmount = new BigDecimal("0");
    DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
    tx.setFtChargedAmount(null);
    tx.setFtChargedTaxAmount(null);
    tx.setFtInternalTotalAmount(null);
    tx.setFtInternalAmount(null);
    tx.setFtInternalTaxAmount(null);
    tx.setFtRequestTotalAmount(null);
    tx.setFtRequestAmount(null);
    tx.setFtRequestTaxAmount(null);
    BigDecimal value = utils.getValueToAddFromTx(tx);
    Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue());
}