List of usage examples for java.math BigDecimal intValue
@Override public int intValue()
From source file:es.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java
/** * Test the function to get charged amount without total charged amount. *//* ww w .ja va 2s. com*/ 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.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java
/** * Test the function to get internal amount. *//*from www .j av a2 s. c om*/ public void getValueToAddFromTxInternalAndNotTax() { 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.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java
/** * Test the function to get nulled requested amount. *///from w w w .j a v a 2s .c o m public void getValueToAddFromTxNulledAmount() { BigDecimal txAmount = new BigDecimal("0"); DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction(); tx.setFtChargedAmount(null); tx.setFtChargedTaxAmount(null); BigDecimal value = utils.getValueToAddFromTx(tx); Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue()); }
From source file:es.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java
/** * Test the function to get charged and charged tax amount without total charged amount. *//*from w w w . java 2s.co m*/ 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.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java
/** * Test the function to get requested amount and requested tax. *//* w ww .j a v a 2 s . c om*/ public void getValueToAddFromTxRequestedAmountAndTax() { BigDecimal txAmount = new BigDecimal("10.10"); BigDecimal txTaxAmount = new BigDecimal("0.60"); 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:com.glaf.core.dao.MyBatisEntityDAO.java
public Paging getPage(int pageNo, int pageSize, SqlExecutor countExecutor, SqlExecutor queryExecutor) { if (pageSize <= 0) { pageSize = Paging.DEFAULT_PAGE_SIZE; }/*from w ww . ja v a 2 s .c o m*/ if (pageNo <= 0) { pageNo = 1; } Object object = null; int totalCount = 0; Paging page = new Paging(); SqlSession session = getSqlSession(); Object parameter = countExecutor.getParameter(); if (parameter != null) { object = session.selectOne(countExecutor.getStatementId(), parameter); } else { object = session.selectOne(countExecutor.getStatementId()); } 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(); } else { String value = object.toString(); totalCount = Integer.parseInt(value); } if (totalCount == 0) { page.setRows(new java.util.ArrayList<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; RowBounds rowBounds = new RowBounds(begin, pageSize); if (queryParams != null) { rows = session.selectList(queryExecutor.getStatementId(), queryParams, rowBounds); } else { rows = session.selectList(queryExecutor.getStatementId(), null, rowBounds); } page.setRows(rows); page.setPageSize(pageSize); page.setCurrentPage(pageNo); logger.debug("params:" + queryParams); logger.debug("rows size:" + rows.size()); return page; }
From source file:com.safasoft.treeweb.dao.SupportDAO.java
/** * Get amount of table records based on given table and where clause statement * @param tableName/*from w w w. j a v a 2 s. com*/ * @param whereClause * @return amount of table records */ public Integer getRecordCount(String tableName, String whereClause) { BigDecimal bd = (BigDecimal) sessionFactory.getCurrentSession() .createSQLQuery("SELECT count(*) " + "FROM " + tableName + " " + "WHERE " + whereClause).list() .get(0); return bd.intValue(); }
From source file:com.glaf.core.db.mybatis2.SqlMapClientDAOImpl.java
public int getCount(String statementId, Object parameterObject) { int totalCount = 0; Object object = null;//from w ww . j av a2s . c om if (parameterObject != null) { object = getSqlMapClientTemplate().queryForObject(statementId, parameterObject); } else { object = getSqlMapClientTemplate().queryForObject(statementId, 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(); } return totalCount; }
From source file:com.glaf.jbpm.db.mybatis2.SqlMapClientDAOImpl.java
public Paging getPage(int pageNo, int pageSize, SqlExecutor countExecutor, SqlExecutor queryExecutor) { Paging page = new Paging(); if (pageSize <= 0) { pageSize = Paging.DEFAULT_PAGE_SIZE; }// w ww . j ava2s .c o m 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.ArrayList<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); return page; }
From source file:com.sangupta.murmur.MurmurEnglishTest.java
private boolean bigMatch(String actual, String computed) { // try with big decimal try {/*from ww w.j a v a 2 s .c o m*/ BigDecimal in = new BigDecimal(actual); long x = in.longValue(); if (computed.equals(String.valueOf(x))) { return true; } int y = in.intValue(); if (computed.equals(String.valueOf(y))) { return true; } } catch (NumberFormatException e) { System.out.println("actual: " + actual); System.out.println("computed: " + computed); throw new RuntimeException("Failed"); } return false; }