List of usage examples for java.math BigDecimal intValue
@Override public int intValue()
From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java
/** * Test the function to get requested amount and requested tax. *///from w w w. j a v a 2 s. c om @Test public void getValueToAddFromTxRequestedAmountAndTax() { BigDecimal txAmount = new BigDecimal("10.10"); BigDecimal txTaxAmount = new BigDecimal("0.60"); 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(txTaxAmount); BigDecimal value = utils.getValueToAddFromTx(tx); Assert.assertEquals("Amount restored", value.intValue(), txAmount.intValue() + txTaxAmount.intValue()); }
From source file:com.glaf.core.entity.mybatis.MyBatisEntityDAOImpl.java
public Paging getPage(int pageNo, int pageSize, SqlExecutor countExecutor, SqlExecutor queryExecutor) { if (pageNo < 1) { pageNo = 1;/* www . j a v a2s .c o m*/ } if (pageSize <= 0) { pageSize = Paging.DEFAULT_PAGE_SIZE; } 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; logger.debug("begin:" + begin); logger.debug("pageSize:" + 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); if (LogUtils.isDebug()) { logger.debug("params:" + queryParams); logger.debug("rows size:" + rows.size()); } return page; }
From source file:co.nubetech.apache.hadoop.TextSplitter.java
/** * Return the string encoded in a BigDecimal. Repeatedly multiply the input * value by 65536; the integer portion after such a multiplication * represents a single character in base 65536. Convert that back into a * char and create a string out of these until we have no data left. *//*from ww w . j av a 2 s . c om*/ String bigDecimalToString(BigDecimal bd) { BigDecimal cur = bd.stripTrailingZeros(); StringBuilder sb = new StringBuilder(); for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) { cur = cur.multiply(ONE_PLACE); int curCodePoint = cur.intValue(); if (0 == curCodePoint) { break; } cur = cur.subtract(new BigDecimal(curCodePoint)); sb.append(Character.toChars(curCodePoint)); } return sb.toString(); }
From source file:org.apache.sqoop.mapreduce.db.TextSplitter.java
/** * Return the string encoded in a BigDecimal. * Repeatedly multiply the input value by 65536; the integer portion after * such a multiplication represents a single character in base 65536. * Convert that back into a char and create a string out of these until we * have no data left.//ww w .j a va 2s. co m */ public String bigDecimalToString(BigDecimal bd) { BigDecimal cur = bd.stripTrailingZeros(); StringBuilder sb = new StringBuilder(); for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) { cur = cur.multiply(ONE_PLACE); int curCodePoint = cur.intValue(); if (0 == curCodePoint) { break; } cur = cur.subtract(new BigDecimal(curCodePoint)); sb.append(Character.toChars(curCodePoint)); } return sb.toString(); }
From source file:org.openhab.binding.yamahareceiver.handler.YamahaBridgeHandler.java
/** * Sets up a refresh timer (using the scheduler) with the CONFIG_REFRESH interval. * * @param initialWaitTime The delay before the first refresh. Maybe 0 to immediately * initiate a refresh./*from ww w .j ava 2s . c om*/ */ private void setupRefreshTimer(int initialWaitTime) { BigDecimal intervalConfig = (BigDecimal) thing.getConfiguration() .get(YamahaReceiverBindingConstants.CONFIG_REFRESH); if (intervalConfig != null && intervalConfig.intValue() != refrehInterval) { refrehInterval = intervalConfig.intValue(); } if (refreshTimer != null) { refreshTimer.cancel(false); } refreshTimer = scheduler.scheduleWithFixedDelay(() -> updateAllZoneInformation(), initialWaitTime, refrehInterval, TimeUnit.SECONDS); }
From source file:org.eclipse.smarthome.binding.fsinternetradio.handler.FSInternetRadioHandler.java
private void radioLogin() { // read configuration and spawn thread to establish connection to device final String ip = (String) getThing().getConfiguration().get(CONFIG_PROPERTY_IP); final BigDecimal port = (BigDecimal) getThing().getConfiguration().get(CONFIG_PROPERTY_PORT); final String pin = (String) getThing().getConfiguration().get(CONFIG_PROPERTY_PIN); if (ip == null || StringUtils.isEmpty(pin) || port.intValue() == 0) { // configuration incomplete updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Configuration incomplete"); } else {//ww w . ja v a 2 s . c o m scheduler.execute(new Runnable() { @Override public void run() { logger.debug("creating new connection to " + ip + ":" + port); try { final FrontierSiliconRadio tmpRadio = new FrontierSiliconRadio(ip, port.intValue(), pin); tmpRadio.login(); radio = tmpRadio; // login successful, now store radio in field // Thing initialized. If done set status to ONLINE to indicate proper working. updateStatus(ThingStatus.ONLINE); // now update all channels! updateRunnable.run(); } catch (Exception e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } } }); } }
From source file:org.openhab.binding.fsinternetradio.internal.handler.FSInternetRadioHandler.java
@Override public void initialize() { // read configuration final String ip = (String) getThing().getConfiguration().get(CONFIG_PROPERTY_IP); final BigDecimal port = (BigDecimal) getThing().getConfiguration().get(CONFIG_PROPERTY_PORT); final String pin = (String) getThing().getConfiguration().get(CONFIG_PROPERTY_PIN); if (ip == null || StringUtils.isEmpty(pin) || port.intValue() == 0) { // configuration incomplete updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Configuration incomplete"); } else {/*from w w w. java2s .c om*/ radio = new FrontierSiliconRadio(ip, port.intValue(), pin, httpClient); logger.debug("Initializing connection to {}:{}", ip, port); // Long running initialization should be done asynchronously in background radioLogin(); // also schedule a thread for polling with configured refresh rate final BigDecimal period = (BigDecimal) getThing().getConfiguration().get(CONFIG_PROPERTY_REFRESH); if (period != null && period.intValue() > 0) { updateJob = scheduler.scheduleWithFixedDelay(updateRunnable, period.intValue(), period.intValue(), SECONDS); } } }
From source file:org.jlgranda.fede.ui.util.UI.java
/** * Imprime emoticons para ocultar la cantidad factor * @param total/*w w w.java2 s . c om*/ * @param gap * @return */ public String calculeEmoticon(BigDecimal total, int gap) { String emoticon = "<i class=\"fa fa-flag-o\"></i>"; int half_gap = gap / 2; if (total.compareTo(BigDecimal.valueOf(gap)) > 0) { int factor; factor = total.intValue() / gap; emoticon = ""; for (int i = 0; i < factor; i++) { emoticon = emoticon + "<i class=\"fa fa-flag\"></i>"; } BigDecimal excedente = total.subtract(new BigDecimal(factor * gap)); if (excedente.compareTo(BigDecimal.valueOf(half_gap)) > 0) { emoticon = emoticon + "<i class=\"fa fa-flag-checkered\"></i>"; } else { emoticon = emoticon + "<i class=\"fa fa-flag-o\"></i>"; } } else if (total.compareTo(BigDecimal.valueOf(half_gap)) > 0) { emoticon = "<i class=\"fa fa-flag-checkered\"></i>"; } return emoticon; }
From source file:org.openhab.binding.yamahareceiver.handler.YamahaBridgeHandler.java
/** * We handle the update ourself to avoid a costly dispose/initialize */// ww w . jav a 2 s .c om @Override public void handleConfigurationUpdate(Map<String, Object> configurationParameters) { if (!isInitialized()) { super.handleConfigurationUpdate(configurationParameters); return; } validateConfigurationParameters(configurationParameters); // can be overridden by subclasses Configuration configuration = editConfiguration(); for (Entry<String, Object> configurationParmeter : configurationParameters.entrySet()) { configuration.put(configurationParmeter.getKey(), configurationParmeter.getValue()); } updateConfiguration(configuration); // Check if host configuration has changed String hostConfig = (String) thing.getConfiguration().get(YamahaReceiverBindingConstants.CONFIG_HOST_NAME); if (hostConfig != null) { connection.setHost(hostConfig); } // Check if refresh configuration has changed BigDecimal intervalConfig = (BigDecimal) thing.getConfiguration() .get(YamahaReceiverBindingConstants.CONFIG_REFRESH); if (intervalConfig != null && intervalConfig.intValue() != refrehInterval) { setupRefreshTimer(intervalConfig.intValue()); } // Read the configuration for the relative volume change factor. BigDecimal relativeVolumeChangeFactorBD = (BigDecimal) thing.getConfiguration() .get(YamahaReceiverBindingConstants.CONFIG_RELVOLUMECHANGE); if (relativeVolumeChangeFactorBD != null) { relativeVolumeChangeFactor = relativeVolumeChangeFactorBD.floatValue(); } else { relativeVolumeChangeFactor = 0.5f; } }
From source file:com.siapa.managedbean.DetalleMuestreoManagedBean.java
@Override public void saveNew(ActionEvent event) { DetalleMuestreo detallemuestreo = getDetallemuestreo(); detallemuestreo.setIdMuestreo(muestreo); detallemuestreoService.save(detallemuestreo); BigInteger cant = detallemuestreoService.cantidad(muestreo.getIdMuestreo()); BigDecimal dividir = new BigDecimal(cant); List<DetalleMuestreo> q = detallemuestreoService.findAll(); BigDecimal suma = BigDecimal.ZERO; BigDecimal promedio = BigDecimal.ZERO; for (DetalleMuestreo detalle : q) { if (detalle.getIdMuestreo().getIdMuestreo() == muestreo.getIdMuestreo()) { suma = suma.add(detalle.getPesoDetalleMuestreo()); }/* w ww . ja va2 s . com*/ } int sumaint = suma.intValue(); int cantint = cant.intValue(); //int prom=sumaint/cantint; // promedio=new BigDecimal(prom); // System.out.println(prom); promedio = suma.divide(dividir); Muestreo newMuestreo = getMuestreo(); newMuestreo.setPesoPromedioMuestreo(suma.divide(dividir)); // muestreo.setPesoPromedioMuestreo(suma); System.out.println(promedio); muestreoService.merge(newMuestreo); loadLazyModels(); FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMessage("Successful")); try { FacesContext context1 = FacesContext.getCurrentInstance(); context1.getExternalContext().redirect("/siapa/views/detalleMuestreo/index.xhtml"); } catch (IOException e) { } }