List of usage examples for java.math BigDecimal longValue
@Override public long longValue()
From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java
BigDecimal decodeBinDecimal(ByteBuf cb, int bufferLen, boolean isIntegerPortion) throws PEException { BigDecimal decimalPortion = new BigDecimal(0); if (bufferLen > 0) { ByteBuf decimalPortionBuf = cb.readBytes(bufferLen); if (isIntegerPortion) { int initialBytes = bufferLen % 4; if (initialBytes > 0) { long intValue = readValue(decimalPortionBuf, initialBytes); decimalPortion = BigDecimal.valueOf(intValue); }//from ww w .j a va 2 s . co m } int decimalPortionLen = decimalPortionBuf.readableBytes(); while (decimalPortionLen > 0) { int nextLen = (decimalPortionLen < 4) ? decimalPortionLen : 4; long intValue = readValue(decimalPortionBuf, nextLen); if (intValue > 0) { if (decimalPortion.longValue() == 0) { decimalPortion = decimalPortion.add(BigDecimal.valueOf(intValue)); } else { int digits = (int) (Math.log10(intValue) + 1); decimalPortion = decimalPortion.movePointRight(digits).add(BigDecimal.valueOf(intValue)); } } decimalPortionLen = decimalPortionBuf.readableBytes(); } } return decimalPortion; }
From source file:es.juntadeandalucia.panelGestion.negocio.vo.TaskVO.java
private void updateCSVProgress(BigDecimal totalSize) { if (taskEntity.getState().getStatus() == Status.FINISHED) { finishState();//from w w w. j a v a 2 s . c o m } else { // gets current data int readLines = fileProcessor.getNumCurrentEntry() + 1; long readBytes = fileProcessor.getReadBytes(); // calculates the current process BigDecimal readBytesBD = BigDecimal.valueOf(readBytes); double progress = readBytesBD.divide(totalSize, 4, RoundingMode.HALF_UP) .multiply(BigDecimal.valueOf(100)).doubleValue(); // updates the task state taskEntity.getState().setReadLines(readLines); taskEntity.getState().setProgress(progress); // finishes when all bytes were read if (readBytesBD.longValue() == totalSize.longValue()) { finishState(); } } }
From source file:es.juntadeandalucia.panelGestion.negocio.vo.TaskVO.java
private void updateShapeProgress(BigDecimal numFeatures) { if (taskEntity.getState().getStatus() == Status.FINISHED) { finishState();//from w w w . j av a 2s . c o m } else { // gets current data int readLines = fileProcessor.getNumCurrentEntry(); int currentNumFeature = fileProcessor.getNumCurrentEntry(); // calculates the progress BigDecimal currentNumFeatureBD = BigDecimal.valueOf(currentNumFeature); double progress = currentNumFeatureBD.divide(numFeatures, 4, RoundingMode.HALF_UP) .multiply(BigDecimal.valueOf(100)).doubleValue(); // updates the task state taskEntity.getState().setReadLines(readLines); taskEntity.getState().setProgress(progress); // finishes when all bytes are read if (currentNumFeatureBD.longValue() == numFeatures.longValue()) { finishState(); } } }
From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java
/** * Converts a numeric value from its BigDecimal representation to its native form * //from w w w. j a v a2s. 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.opentaps.common.util.UtilCommon.java
/** * Gets the <code>Timestamp</code> which time is the given milliseconds before the given <code>Timestamp</code>. * @param ts the reference <code>Timestamp</code> * @param milliseconds number of milliseconds before ts for which to return * @return a <code>Timestamp</code>, <code>null</code> if ts is <code>null</code> *///from w w w .j ava 2 s . c om public static Timestamp beforeMillisecs(Timestamp ts, BigDecimal milliseconds) { if (milliseconds == null) { milliseconds = BigDecimal.ZERO; } return beforeMillisecs(ts, milliseconds.longValue()); }
From source file:com.zhumeng.dream.orm.hibernate.HibernateDao.java
protected long countSqlResult(final String sql, final Object... values) { String countSql = prepareCountSql(sql); BigDecimal count = findUniqueBySql(countSql, values); return count.longValue(); }
From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java
/** * Converts a numeric value to its string representation * /*w ww. 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; }
From source file:org.egov.services.cheque.ChequeAssignmentService.java
@SuppressWarnings("unchecked") private List<Object[]> getDetailTypeKeyAmtForBillVHId(final List<Long> billVHIds) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Starting getDetailTypeKeyAmtForBillVHId..."); final List<Long> cBillGlcodeIdsList = new ArrayList<Long>(); for (final BigDecimal glCodeId : cBillGlcodeIdList) cBillGlcodeIdsList.add(glCodeId.longValue()); List<Object[]> generalLedgerDetailList = new ArrayList<Object[]>(); int size = billVHIds.size(); if (size > 999) { int fromIndex = 0; int toIndex = 0; final int step = 1000; List<Object[]> newGLDList; while (size - step >= 0) { newGLDList = new ArrayList<Object[]>(); toIndex += step;// www .java 2s . c om final Query generalLedgerDetailsQuery = getSession().createQuery( " select gld.detailTypeId.id,gld.detailKeyId.id,gld.amount,gl.voucherHeaderId.id from CGeneralLedger gl, CGeneralLedgerDetail gld where gl.voucherHeaderId.id in ( :IDS ) and gl.id = gld.generalLedgerId.id and gl.creditAmount>0 and gl.glcodeId.id in (:glcodeIdList)"); generalLedgerDetailsQuery.setParameterList("IDS", billVHIds.subList(fromIndex, toIndex)); generalLedgerDetailsQuery.setParameterList("glcodeIdList", cBillGlcodeIdsList); newGLDList = generalLedgerDetailsQuery.list(); fromIndex = toIndex; size -= step; if (newGLDList != null) generalLedgerDetailList.addAll(newGLDList); } if (size > 0) { newGLDList = new ArrayList<Object[]>(); fromIndex = toIndex; toIndex = fromIndex + size; final Query generalLedgerDetailsQuery = getSession().createQuery( " select gld.detailTypeId.id,gld.detailKeyId,gld.amount,gl.voucherHeaderId.id from CGeneralLedger gl, CGeneralLedgerDetail gld where gl.voucherHeaderId.id in ( :IDS ) and gl.id = gld.generalLedgerId.id and gl.creditAmount>0 and gl.glcodeId.id in (:glcodeIdList)"); generalLedgerDetailsQuery.setParameterList("IDS", billVHIds.subList(fromIndex, toIndex)); generalLedgerDetailsQuery.setParameterList("glcodeIdList", cBillGlcodeIdsList); newGLDList = generalLedgerDetailsQuery.list(); if (newGLDList != null) generalLedgerDetailList.addAll(newGLDList); } } else { final Query generalLedgerDetailsQuery = getSession().createQuery( " select gld.detailTypeId.id,gld.detailKeyId,gld.amount,gl.voucherHeaderId.id from CGeneralLedger gl, CGeneralLedgerDetail gld where gl.voucherHeaderId.id in ( :IDS ) and gl.id = gld.generalLedgerId.id and gl.creditAmount>0 and gl.glcodeId.id in (:glcodeIdList)"); generalLedgerDetailsQuery.setParameterList("IDS", billVHIds); generalLedgerDetailsQuery.setParameterList("glcodeIdList", cBillGlcodeIdsList); generalLedgerDetailList = generalLedgerDetailsQuery.list(); } if (LOGGER.isDebugEnabled()) LOGGER.debug("Completed getDetailTypeKeyAmtForBillVHId."); return generalLedgerDetailList; }
From source file:com.baidu.rigel.biplatform.tesseract.isservice.index.service.impl.IndexServiceImpl.java
/** * doIndexByIndexAction/*from w ww .j ava 2 s .co m*/ * @param indexMeta ? * @param idxAction * @param dataMap ??? * @throws Exception ? */ private void doIndexByIndexAction(IndexMeta indexMeta, IndexAction idxAction, Map<String, BigDecimal> dataMap) throws Exception { LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_BEGIN, "doIndexByIndexAction", "[indexMeta:" + indexMeta + "][idxAction:" + idxAction + "]")); IndexMeta idxMeta = this.indexMetaService.getIndexMetaByIndexMetaId(indexMeta.getIndexMetaId(), indexMeta.getStoreKey()); if ((idxMeta.getLocked().equals(Boolean.FALSE)) || ((System.currentTimeMillis() - idxMeta.getIdxVersion()) > this.indexInterval)) { idxMeta.setLocked(Boolean.TRUE); this.indexMetaService.saveIndexMetaLocally(idxMeta); } else { LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_PROCESS, "doIndexByIndexAction", "[indexMeta:" + indexMeta.getIndexMetaId() + ", Locked:" + idxMeta.getLocked() + ", last update:" + idxMeta.getIdxVersion() + " ,indexInterval:" + this.indexInterval + ",test (System.currentTimeMillis()-idxMeta.getIdxVersion()):" + (System.currentTimeMillis() - idxMeta.getIdxVersion()) + "]", "[skip index]")); return; } if (idxMeta == null || idxAction == null) { LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_EXCEPTION, "doIndexByIndexAction", "[indexMeta:" + indexMeta + "][idxAction:" + idxAction + "]")); throw new IllegalArgumentException(); } // 1. IndexMeta-->SQLQuery Map<String, SqlQuery> sqlQueryMap = transIndexMeta2SQLQuery(idxMeta, idxAction, dataMap); // 2. get a connection SqlDataSourceWrap dataSourceWrape = (SqlDataSourceWrap) this.dataSourcePoolService .getDataSourceByKey(idxMeta.getDataSourceInfo()); if (dataSourceWrape == null) { LOGGER.info( String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_PROCESS, "doIndexByIndexAction", "[indexMeta:" + indexMeta + "][idxAction:" + idxAction + "]"), "getDataSourceByKey return null"); throw new DataSourceException(); } // 3. get data & write index Map<String, BigDecimal> maxDataIdMap = new HashMap<String, BigDecimal>(); for (String tableName : sqlQueryMap.keySet()) { SqlQuery sqlQuery = sqlQueryMap.get(tableName); if (!StringUtils.isEmpty(sqlQuery.getIdName())) { sqlQuery.getOrderBy().add(sqlQuery.getIdName()); } long total = 0; BigDecimal currMaxId = BigDecimal.valueOf(-1); if (idxMeta.getDataDescInfo().getMaxDataId(tableName) != null && !idxAction.getFromScratch()) { // ?ID currMaxId = idxMeta.getDataDescInfo().getMaxDataId(tableName); } // init?mergecurrMaxId=0modcurrMaxId?0 String currWhereStr = sqlQuery.getIdName() + " > " + currMaxId.longValue(); sqlQuery.getWhereList().add(currWhereStr); if (idxAction.equals(IndexAction.INDEX_INIT_LIMITED)) { total = IndexFileSystemConstants.INDEX_DATA_TOTAL_IN_LIMITEDMODEL; } else { total = this.dataQueryService.queryForLongWithSql(getCountSQLBySQLQuery(sqlQuery), dataSourceWrape); } boolean isLastPiece = false; long pcount = IndexFileSystemConstants.FETCH_SIZE_FROM_DATASOURCE; // ???? if (pcount > total) { pcount = total; } if (!StringUtils.isEmpty(sqlQuery.getIdName()) && !CollectionUtils.isEmpty(sqlQuery.getSelectList())) { sqlQuery.getSelectList().add(sqlQuery.getIdName()); } for (int i = 0; i * pcount < total; i++) { long limitStart = 0; long limitEnd = pcount; if ((i + 1) * pcount >= total || idxAction.equals(IndexAction.INDEX_MOD)) { isLastPiece = true; } if (sqlQuery.getWhereList().contains(currWhereStr)) { sqlQuery.getWhereList().remove(currWhereStr); } currWhereStr = sqlQuery.getIdName() + " > " + currMaxId.longValue(); sqlQuery.getWhereList().add(currWhereStr); TesseractResultSet currResult = this.dataQueryService.queryForDocListWithSQLQuery(sqlQuery, dataSourceWrape, limitStart, limitEnd); IndexShard currIdxShard = null; int currIdxShardIdx = -1; while (currResult.size() != 0) { // ????? if (currIdxShard == null) { currIdxShardIdx = this.getIndexShardByIndexAction(idxMeta, idxAction, currIdxShardIdx); currIdxShard = idxMeta.getIdxShardList().get(currIdxShardIdx); currIdxShard.setFull(Boolean.FALSE); } // ? Map<String, Object> result = writeIndex(currResult, idxAction, currIdxShard, isLastPiece, sqlQuery.getIdName()); // this.indexMetaService.saveOrUpdateIndexMeta(idxMeta); currResult = (TesseractResultSet) result.get(RESULT_KEY_DATA); currMaxId = (BigDecimal) result.get(RESULT_KEY_MAXID); currIdxShard = (IndexShard) result.get(RESULT_KEY_INDEXSHARD); if (currIdxShard.isFull() || isLastPiece) { // ??? currIdxShard = null; if (idxAction.equals(IndexAction.INDEX_MOD) || idxAction.equals(IndexAction.INDEX_MERGE) || idxAction.equals(IndexAction.INDEX_MERGE_NORMAL)) { currIdxShardIdx++; if (idxAction.equals(IndexAction.INDEX_MERGE_NORMAL)) { idxAction = IndexAction.INDEX_MERGE; } if (currIdxShardIdx >= idxMeta.getIdxShardList().size()) { idxAction = IndexAction.INDEX_NORMAL; } } else { currIdxShardIdx = -1; if (!idxAction.equals(IndexAction.INDEX_MOD) && !idxAction.equals(IndexAction.INDEX_MERGE_NORMAL)) { idxAction = IndexAction.INDEX_NORMAL; } } } else if (idxAction.equals(IndexAction.INDEX_MERGE)) { idxAction = IndexAction.INDEX_MERGE_NORMAL; } else if (!idxAction.equals(IndexAction.INDEX_MOD) && !idxAction.equals(IndexAction.INDEX_MERGE_NORMAL)) { idxAction = IndexAction.INDEX_NORMAL; } } } maxDataIdMap.put(tableName, currMaxId); } if (!idxAction.equals(IndexAction.INDEX_MOD)) { // init merge update???id idxMeta.getDataDescInfo().setMaxDataIdMap(maxDataIdMap); } if (idxMeta.getIdxState().equals(IndexState.INDEX_AVAILABLE_NEEDMERGE)) { idxMeta.getCubeIdSet().addAll(idxMeta.getCubeIdMergeSet()); idxMeta.getCubeIdMergeSet().clear(); idxMeta.getDimSet().addAll(idxMeta.getDimInfoMergeSet()); idxMeta.getMeasureSet().addAll(idxMeta.getMeasureInfoMergeSet()); idxMeta.getDimInfoMergeSet().clear(); idxMeta.getMeasureInfoMergeSet().clear(); } if (idxMeta.getIdxState().equals(IndexState.INDEX_AVAILABLE_NEEDMERGE) || idxMeta.getIdxState().equals(IndexState.INDEX_UNINIT)) { idxMeta.setIdxState(IndexState.INDEX_AVAILABLE); } // for (IndexShard idxShard : idxMeta.getIdxShardList()) { // if (idxShard.isUpdate()) { // String servicePath = idxShard.getFilePath(); // String bakFilePath = idxShard.getIdxFilePath(); // idxShard.setIdxFilePath(servicePath); // idxShard.setFilePath(bakFilePath); // idxShard.setIdxState(IndexState.INDEX_AVAILABLE); // } else if (idxAction.equals(IndexAction.INDEX_MERGE)) { // idxMeta.getIdxShardList().remove(idxShard); // } // } Iterator<IndexShard> idxShardIt = idxMeta.getIdxShardList().iterator(); while (idxShardIt.hasNext()) { IndexShard idxShard = idxShardIt.next(); if (idxShard.isUpdate()) { String servicePath = idxShard.getFilePath(); String bakFilePath = idxShard.getIdxFilePath(); idxShard.setIdxFilePath(servicePath); idxShard.setFilePath(bakFilePath); idxShard.setIdxState(IndexState.INDEX_AVAILABLE); if (idxAction.equals(IndexAction.INDEX_MOD) && (idxShard.getShardId() < idxMeta.getIdxShardList().size())) { idxShard.setFull(Boolean.TRUE); } } else if (idxAction.equals(IndexAction.INDEX_MERGE)) { idxShardIt.remove(); } } idxMeta.setLocked(Boolean.FALSE); this.indexMetaService.saveOrUpdateIndexMeta(idxMeta); publistIndexMetaWriteEvent(idxMeta); LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_END, "doIndex", "[indexMeta:" + indexMeta + "][idxAction:" + idxAction + "]")); return; }
From source file:it.geosolutions.geobatch.destination.vulnerability.VulnerabilityComputation.java
/** * This method calculates the vulnerability for the level 3 * /* ww w .j a v a2s. com*/ * @param currentImage * @param currentBPT * @param keySet * @param targetID * @param bbox * @param outFeatureName * @param trace * @param vse * @param vulnerabilityObj * @param concreteOperation * @param monitor * @param allDistances * @param reportingLoopStep * @param geoName * @param partnerFilter * @param total * @throws IOException */ private void vulnerabilityLevel3(RenderedImage currentImage, Map<Integer, TargetInfo> currentBPT, String targetID, Envelope2D bbox, String outFeatureName, int trace, VulnerabilityStatsEngine vse, OutputObject vulnerabilityObj, VulnerabilityOperation concreteOperation, VulnerabilityMonitor monitor, List<Double> allDistances, int reportingLoopStep, String geoName, Filter partnerFilter, ConcurrentSkipListSet<BigDecimal> arcIdsSet) throws IOException { SimpleFeature currentCell; // Setting of the input filter BigDecimal idCellStart = new BigDecimal(startOriginId); BigDecimal idCellStop = new BigDecimal(endOriginId); concreteOperation.setStartOriginId(idCellStart.longValue()); concreteOperation.setEndOriginId(idCellStop.longValue()); // Creation of the input filter used setInputFilter(concreteOperation.buildOriginFilterExtended(partner, monitor.getTotal(), null, bbox, null)); try { while ((currentCell = readInputSorted()) != null) { calculateCell(currentImage, currentBPT, targetID, outFeatureName, trace, vse, vulnerabilityObj, concreteOperation, monitor, allDistances, reportingLoopStep, geoName, partnerFilter, arcIdsSet, currentCell); } } catch (Exception e) { monitor.incrementErrors(); monitor.newMessage(new VulnerabilityMonitor.Message(TYPE.ERROR, "Raster=" + targetID + ", TILE=(" + idCellStart + "," + idCellStop + ") Generic error", e)); LOGGER.error("Raster=" + targetID + ", CELLS=(" + idCellStart + "," + idCellStop + ") Generic error", e); } //monitor.newMessage(new VulnerabilityMonitor.Message(TYPE.FINISH, "Vulnerability calculation completed")); }