List of usage examples for java.util.concurrent.atomic AtomicLong longValue
public long longValue()
From source file:Main.java
public static void main(String[] argv) { AtomicLong nextId = new AtomicLong(); System.out.println(nextId.longValue()); }
From source file:Main.java
public static void main(String[] argv) { AtomicLong nextId = new AtomicLong(); nextId.set(12312L);//from w w w . j a v a 2 s . co m System.out.println(nextId.longValue()); }
From source file:com.amaze.filemanager.utils.files.FileUtils.java
/** * Helper method to get size of an otg folder *//* w ww.j a va2 s .c o m*/ public static long otgFolderSize(String path, final Context context) { final AtomicLong totalBytes = new AtomicLong(0); OTGUtil.getDocumentFiles(path, context, file -> totalBytes.addAndGet(getBaseFileSize(file, context))); return totalBytes.longValue(); }
From source file:net.hydromatic.foodbench.Main.java
/** Does the work. */ private void run(String jdbcUrl, String catalog, String driverClassName) throws IOException, SQLException, ClassNotFoundException { URL url = FoodMartQuery.class.getResource("/queries.json"); InputStream inputStream = url.openStream(); ObjectMapper mapper = new ObjectMapper(); Map values = mapper.readValue(inputStream, Map.class); //noinspection unchecked List<Map<String, Object>> tests = (List) values.get("queries"); if (driverClassName != null) { Class.forName(driverClassName); }/*from w ww . j av a2 s .c o m*/ Connection connection = DriverManager.getConnection(jdbcUrl); if (catalog != null) { connection.setCatalog(catalog); } Statement statement = connection.createStatement(); for (Map<String, Object> test : tests) { int id = (Integer) test.get("id"); if (!idSet.contains(id)) { continue; } String sql = (String) test.get("sql"); if (jdbcUrl.startsWith("jdbc:mysql:")) { sql = sql.replace("\"", "`"); sql = sql.replace(" NULLS FIRST", ""); sql = sql.replace(" NULLS LAST", ""); if (sql.contains("VALUES ")) { System.out.println("query id: " + id + " sql: " + sql + " skipped"); continue; } } if (jdbcUrl.startsWith("jdbc:optiq:")) { sql = sql.replace("RTRIM(", "TRIM(TRAILING ' ' FROM "); } final AtomicLong tPrepare = new AtomicLong(0); Hook.Closeable hook = Hook.JAVA_PLAN.add(new Function1<Object, Object>() { public Object apply(Object a0) { tPrepare.set(System.nanoTime()); return null; } }); try { final long t0 = System.nanoTime(); ResultSet resultSet = statement.executeQuery(sql); int n = 0; while (resultSet.next()) { ++n; } resultSet.close(); final long tEnd = System.nanoTime(); final long nanos = tEnd - t0; final long prepare = tPrepare.longValue() - t0; final long execute = tEnd - tPrepare.longValue(); System.out.println("query id: " + id + " rows: " + n + " nanos: " + NF.format(nanos) + " prepare: " + NF.format(prepare) + " execute: " + NF.format(execute) + " prepare%: " + ((float) prepare / (float) nanos * 100f)); } catch (SQLException e) { System.out.println("query id: " + id + " sql: " + sql + " error: " + e.getMessage()); if (verbose) { e.printStackTrace(); } } finally { hook.close(); } } statement.close(); connection.close(); }
From source file:okuyama.imdst.util.KeyManagerValueMap.java
public long getDataUseSize(String unique) { AtomicLong size = new AtomicLong(0L); if (unique == null) unique = "all"; if (dataSizeMap.containsKey(unique)) { size = (AtomicLong) dataSizeMap.get(unique); }//from w w w . ja va 2 s . c om return size.longValue(); }
From source file:org.hyperledger.fabric.sdkintegration.End2endMTIT.java
void runChannel(HFClient client, Channel channel, final int workerId, final int runId, SampleOrg sampleOrg, final int delta, final int start) { int ret = -1; class ChaincodeEventCapture { //A test class to capture chaincode events final String handle; final BlockEvent blockEvent; final ChaincodeEvent chaincodeEvent; ChaincodeEventCapture(String handle, BlockEvent blockEvent, ChaincodeEvent chaincodeEvent) { this.handle = handle; this.blockEvent = blockEvent; this.chaincodeEvent = chaincodeEvent; }/*from w ww. j a va 2 s . com*/ } Vector<ChaincodeEventCapture> chaincodeEvents = new Vector<>(); // Test list to capture chaincode events. try { final String channelName = channel.getName(); boolean isFooChain = FOO_CHANNEL_NAME.equals(channelName); out("Running channel %s", channelName); Collection<Orderer> orderers = channel.getOrderers(); final ChaincodeID chaincodeID; Collection<ProposalResponse> responses; Collection<ProposalResponse> successful = new LinkedList<>(); Collection<ProposalResponse> failed = new LinkedList<>(); // Register a chaincode event listener that will trigger for any chaincode id and only for EXPECTED_EVENT_NAME event. // String chaincodeEventListenerHandle = channel.registerChaincodeEventListener(Pattern.compile(".*"), // Pattern.compile(Pattern.quote(EXPECTED_EVENT_NAME)), // (handle, blockEvent, chaincodeEvent) -> { // // chaincodeEvents.add(new ChaincodeEventCapture(handle, blockEvent, chaincodeEvent)); // // String es = blockEvent.getPeer() != null ? blockEvent.getPeer().getName() : blockEvent.getEventHub().getName(); // out("RECEIVED Chaincode event with handle: %s, chaincode Id: %s, chaincode event name: %s, " // + "transaction id: %s, event payload: \"%s\", from eventhub: %s", // handle, chaincodeEvent.getChaincodeId(), // chaincodeEvent.getEventName(), // chaincodeEvent.getTxId(), // new String(chaincodeEvent.getPayload()), es); // // }); //For non foo channel unregister event listener to test events are not called. // if (!isFooChain) { // channel.unregisterChaincodeEventListener(chaincodeEventListenerHandle); // chaincodeEventListenerHandle = null; // // } ChaincodeID.Builder chaincodeIDBuilder = ChaincodeID.newBuilder().setName(CHAIN_CODE_NAME) .setVersion(CHAIN_CODE_VERSION); if (null != CHAIN_CODE_PATH) { chaincodeIDBuilder.setPath(CHAIN_CODE_PATH); } chaincodeID = chaincodeIDBuilder.build(); successful.clear(); failed.clear(); final User user = sampleOrg.getUser(TESTUSER_1_NAME); /////////////// /// Send transaction proposal to all peers TransactionProposalRequest transactionProposalRequest = client.newTransactionProposalRequest(); transactionProposalRequest.setChaincodeID(chaincodeID); transactionProposalRequest.setChaincodeLanguage(CHAIN_CODE_LANG); transactionProposalRequest.setUserContext(user); //transactionProposalRequest.setFcn("invoke"); transactionProposalRequest.setFcn("move"); transactionProposalRequest.setProposalWaitTime(testConfig.getProposalWaitTime()); transactionProposalRequest.setArgs("a" + workerId, "b" + workerId, delta + ""); Map<String, byte[]> tm2 = new HashMap<>(); tm2.put("HyperLedgerFabric", "TransactionProposalRequest:JavaSDK".getBytes(UTF_8)); //Just some extra junk in transient map tm2.put("method", "TransactionProposalRequest".getBytes(UTF_8)); // ditto tm2.put("result", ":)".getBytes(UTF_8)); // This should be returned see chaincode why. tm2.put(EXPECTED_EVENT_NAME, EXPECTED_EVENT_DATA); //This should trigger an event see chaincode why. transactionProposalRequest.setTransientMap(tm2); out("Sending transactionProposal to all peers with arguments: move(a%d,b%d,%d) with b at %d", workerId, workerId, delta, start); Collection<ProposalResponse> transactionPropResp = channel .sendTransactionProposal(transactionProposalRequest, channel.getPeers()); for (ProposalResponse response : transactionPropResp) { if (response.getStatus() == ProposalResponse.Status.SUCCESS) { out("Successful channel%s worker id %d transaction proposal response Txid: %s from peer %s", channelName, workerId, response.getTransactionID(), response.getPeer().getName()); successful.add(response); } else { failed.add(response); } } // Check that all the proposals are consistent with each other. We should have only one set // where all the proposals above are consistent. Note the when sending to Orderer this is done automatically. // Shown here as an example that applications can invoke and select. // See org.hyperledger.fabric.sdk.proposal.consistency_validation config property. Collection<Set<ProposalResponse>> proposalConsistencySets = SDKUtils .getProposalConsistencySets(transactionPropResp); if (proposalConsistencySets.size() != 1) { fail(format("Expected only one set of consistent proposal responses but got %d", proposalConsistencySets.size())); } out("Channel %s worker id %d, received %d transaction proposal responses. Successful+verified: %d . Failed: %d", channelName, workerId, transactionPropResp.size(), successful.size(), failed.size()); if (failed.size() > 0) { ProposalResponse firstTransactionProposalResponse = failed.iterator().next(); fail("Not enough endorsers for invoke(move a,b,100):" + failed.size() + " endorser error: " + firstTransactionProposalResponse.getMessage() + ". Was verified: " + firstTransactionProposalResponse.isVerified()); } out("Channel %s, worker id %d successfully received transaction proposal responses.", channelName, workerId); ProposalResponse resp = successful.iterator().next(); byte[] x = resp.getChaincodeActionResponsePayload(); // This is the data returned by the chaincode. String resultAsString = null; if (x != null) { resultAsString = new String(x, "UTF-8"); } assertEquals(":)", resultAsString); assertEquals(200, resp.getChaincodeActionResponseStatus()); //Chaincode's status. TxReadWriteSetInfo readWriteSetInfo = resp.getChaincodeActionResponseReadWriteSetInfo(); //See blockwalker below how to transverse this assertNotNull(readWriteSetInfo); assertTrue(readWriteSetInfo.getNsRwsetCount() > 0); ChaincodeID cid = resp.getChaincodeID(); assertNotNull(cid); final String path = cid.getPath(); if (null == CHAIN_CODE_PATH) { assertTrue(path == null || "".equals(path)); } else { assertEquals(CHAIN_CODE_PATH, path); } assertEquals(CHAIN_CODE_NAME, cid.getName()); assertEquals(CHAIN_CODE_VERSION, cid.getVersion()); //////////////////////////// // Send Transaction Transaction to orderer out("Sending chaincode transaction(move a%d,b%d,%d) to orderer. with b value %d", workerId, workerId, delta, start); channel.sendTransaction(successful, user).thenApply(transactionEvent -> { try { waitOnFabric(0); assertTrue(transactionEvent.isValid()); // must be valid to be here. out("Channel %s worker id %d Finished transaction with transaction id %s", channelName, workerId, transactionEvent.getTransactionID()); testTxID = transactionEvent.getTransactionID(); // used in the channel queries later //////////////////////////// // Send Query Proposal to all peers // String expect = start + delta + ""; out("Channel %s Now query chaincode for the value of b%d.", channelName, workerId); QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest(); queryByChaincodeRequest.setArgs(new String[] { "b" + workerId }); queryByChaincodeRequest.setFcn("query"); queryByChaincodeRequest.setChaincodeID(chaincodeID); tm2.clear(); tm2.put("HyperLedgerFabric", "QueryByChaincodeRequest:JavaSDK".getBytes(UTF_8)); tm2.put("method", "QueryByChaincodeRequest".getBytes(UTF_8)); queryByChaincodeRequest.setTransientMap(tm2); Collection<ProposalResponse> queryProposals = channel.queryByChaincode(queryByChaincodeRequest, channel.getPeers()); for (ProposalResponse proposalResponse : queryProposals) { if (!proposalResponse.isVerified() || proposalResponse.getStatus() != ProposalResponse.Status.SUCCESS) { fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() + ". Messages: " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified()); } else { String payload = proposalResponse.getProposalResponse().getResponse().getPayload() .toStringUtf8(); out("Channel %s worker id %d, query payload of b%d from peer %s returned %s and was expecting: %d", channelName, workerId, workerId, proposalResponse.getPeer().getName(), payload, delta + start); assertEquals(expect, payload); } } return null; } catch (Exception e) { out("Caught exception while running query"); e.printStackTrace(); fail("Failed during chaincode query with error : " + e.getMessage()); } return null; }).exceptionally(e -> { if (e instanceof TransactionEventException) { BlockEvent.TransactionEvent te = ((TransactionEventException) e).getTransactionEvent(); if (te != null) { throw new AssertionError(format("Transaction with txid %s failed. %s", te.getTransactionID(), e.getMessage()), e); } } throw new AssertionError( format("Test failed with %s exception %s", e.getClass().getName(), e.getMessage()), e); }).get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS); // Channel queries // We can only send channel queries to peers that are in the same org as the SDK user context // Get the peers from the current org being used and pick one randomly to send the queries to. // Set<Peer> peerSet = sampleOrg.getPeers(); // Peer queryPeer = peerSet.iterator().next(); // out("Using peer %s for channel queries", queryPeer.getName()); final AtomicLong atomicHeight = new AtomicLong(Long.MAX_VALUE); final BlockchainInfo[] bcInfoA = new BlockchainInfo[1]; channel.getPeers().forEach(peer -> { try { BlockchainInfo channelInfo2 = channel.queryBlockchainInfo(peer, user); final long height = channelInfo2.getHeight(); if (height < atomicHeight.longValue()) { atomicHeight.set(height); bcInfoA[0] = channelInfo2; } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }); BlockchainInfo channelInfo = bcInfoA[0]; out("Channel info for : " + channelName); out("Channel height: " + channelInfo.getHeight()); String chainCurrentHash = Hex.encodeHexString(channelInfo.getCurrentBlockHash()); String chainPreviousHash = Hex.encodeHexString(channelInfo.getPreviousBlockHash()); out("Chain current block hash: " + chainCurrentHash); out("Chainl previous block hash: " + chainPreviousHash); final long getBlockNumber = atomicHeight.longValue() - 1L; // Query by block number. Should return latest block, i.e. block number 2 BlockInfo returnedBlock = channel.queryBlockByNumber(getBlockNumber, user); String previousHash = Hex.encodeHexString(returnedBlock.getPreviousHash()); out("queryBlockByNumber returned correct block with blockNumber " + returnedBlock.getBlockNumber() + " \n previous_hash " + previousHash); assertEquals(getBlockNumber, returnedBlock.getBlockNumber()); assertEquals(chainPreviousHash, previousHash); returnedBlock.getEnvelopeCount(); out("Worker: %d, run: %d, channel: %s block transaction count: %d", workerId, runId, channelName, returnedBlock.getEnvelopeCount()); // Query by block hash. Using latest block's previous hash so should return block number 1 byte[] hashQuery = returnedBlock.getPreviousHash(); returnedBlock = channel.queryBlockByHash(hashQuery, user); out("queryBlockByHash returned block with blockNumber " + returnedBlock.getBlockNumber()); assertEquals(format("query by hash expected block number %d but was %d ", getBlockNumber - 1L, returnedBlock.getBlockNumber()), getBlockNumber - 1L, returnedBlock.getBlockNumber()); // Query block by TxID. Since it's the last TxID, should be block 2 //TODO RICK returnedBlock = channel.queryBlockByTransactionID(testTxID); // out("queryBlockByTxID returned block with blockNumber " + returnedBlock.getBlockNumber()); // assertEquals(channelInfo.getHeight() - 1, returnedBlock.getBlockNumber()); // query transaction by ID // TransactionInfo txInfo = channel.queryTransactionByID(testTxID); // out("QueryTransactionByID returned TransactionInfo: txID " + txInfo.getTransactionID() // + "\n validation code " + txInfo.getValidationCode().getNumber()); // if (chaincodeEventListenerHandle != null) { // // channel.unregisterChaincodeEventListener(chaincodeEventListenerHandle); // //Should be two. One event in chaincode and two notification for each of the two event hubs // // final int numberEventsExpected = channel.getEventHubs().size() + // channel.getPeers(EnumSet.of(PeerRole.EVENT_SOURCE)).size(); // //just make sure we get the notifications. // for (int i = 15; i > 0; --i) { // if (chaincodeEvents.size() == numberEventsExpected) { // break; // } else { // Thread.sleep(90); // wait for the events. // } // // } // assertEquals(numberEventsExpected, chaincodeEvents.size()); // // for (ChaincodeEventCapture chaincodeEventCapture : chaincodeEvents) { // assertEquals(chaincodeEventListenerHandle, chaincodeEventCapture.handle); // assertEquals(testTxID, chaincodeEventCapture.chaincodeEvent.getTxId()); // assertEquals(EXPECTED_EVENT_NAME, chaincodeEventCapture.chaincodeEvent.getEventName()); // assertTrue(Arrays.equals(EXPECTED_EVENT_DATA, chaincodeEventCapture.chaincodeEvent.getPayload())); // assertEquals(CHAIN_CODE_NAME, chaincodeEventCapture.chaincodeEvent.getChaincodeId()); // // BlockEvent blockEvent = chaincodeEventCapture.blockEvent; // assertEquals(channelName, blockEvent.getChannelId()); // // assertTrue(channel.getEventHubs().contains(blockEvent.getEventHub())); // // } // // } else { // assertTrue(chaincodeEvents.isEmpty()); // } out("Running for Channel %s done", channelName); } catch (Exception e) { out("Caught an exception running channel %s", channel.getName()); e.printStackTrace(); fail("Test failed with error : " + e.getMessage()); } }
From source file:org.apache.hadoop.hbase.regionserver.Store.java
private StoreFile commitFile(final Path path, final long logCacheFlushId, TimeRangeTracker snapshotTimeRangeTracker, AtomicLong flushedSize, MonitoredTask status) throws IOException { // Write-out finished successfully, move into the right spot String fileName = path.getName(); Path dstPath = new Path(homedir, fileName); validateStoreFile(path);//from w ww.j a v a 2 s.c om String msg = "Renaming flushed file at " + path + " to " + dstPath; LOG.debug(msg); status.setStatus("Flushing " + this + ": " + msg); if (!HBaseFileSystem.renameDirForFileSystem(fs, path, dstPath)) { LOG.warn("Unable to rename " + path + " to " + dstPath); } status.setStatus("Flushing " + this + ": reopening flushed file"); StoreFile sf = new StoreFile(this.fs, dstPath, this.conf, this.cacheConf, this.family.getBloomFilterType(), this.dataBlockEncoder, isAssistant()); passSchemaMetricsTo(sf); StoreFile.Reader r = sf.createReader(); this.storeSize += r.length(); this.totalUncompressedBytes += r.getTotalUncompressedBytes(); // This increments the metrics associated with total flushed bytes for this // family. The overall flush count is stored in the static metrics and // retrieved from HRegion.recentFlushes, which is set within // HRegion.internalFlushcache, which indirectly calls this to actually do // the flushing through the StoreFlusherImpl class getSchemaMetrics().updatePersistentStoreMetric(SchemaMetrics.StoreMetricType.FLUSH_SIZE, flushedSize.longValue()); if (LOG.isInfoEnabled()) { LOG.info("Added " + sf + ", entries=" + r.getEntries() + ", sequenceid=" + logCacheFlushId + ", filesize=" + StringUtils.humanReadableInt(r.length())); } return sf; }
From source file:ca.oson.json.Oson.java
private <E, R> AtomicLong json2AtomicLongDefault(FieldData objectDTO) { E value = (E) objectDTO.valueToProcess; Class<R> returnType = objectDTO.returnType; boolean required = objectDTO.required(); Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (getDefaultType() == JSON_INCLUDE.DEFAULT || required) { AtomicLong defaultValue = (AtomicLong) objectDTO.getDefaultValue(); if (defaultValue != null) { if (min != null && min > defaultValue.longValue()) { return new AtomicLong(min); }/*from w w w .ja v a2s . co m*/ if (max != null && max < defaultValue.longValue()) { return new AtomicLong(max); } return defaultValue; } if (min != null && min > DefaultValue.atomicLong.longValue()) { return new AtomicLong(min); } return DefaultValue.atomicLong; } return null; }
From source file:ca.oson.json.Oson.java
private <E, R> String atomicLong2Json(FieldData objectDTO) { if (objectDTO == null || objectDTO.json2Java) { return null; }// w ww .j ava2s. c o m E value = (E) objectDTO.valueToProcess; Class<R> returnType = objectDTO.returnType; if (value != null && value.toString().trim().length() > 0) { AtomicLong valueToProcess = null; String valueToReturn = null; if (value instanceof AtomicLong) { valueToProcess = (AtomicLong) value; } else { try { valueToProcess = new AtomicLong(Long.parseLong(NumberUtil.removeTrailingDecimalZeros(value))); } catch (Exception ex) { } } if (valueToProcess != null) { try { Function function = objectDTO.getSerializer(); if (function != null) { try { if (function instanceof DataMapper2JsonFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); return ((DataMapper2JsonFunction) function).apply(classData); } else if (function instanceof AtomicLong2JsonFunction) { return ((AtomicLong2JsonFunction) function).apply(valueToProcess); } else { Object returnedValue = null; if (function instanceof FieldData2JsonFunction) { FieldData2JsonFunction f = (FieldData2JsonFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else { returnedValue = function.apply(value); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } else if (returnedValue instanceof AtomicLong) { valueToProcess = (AtomicLong) returnedValue; } else { objectDTO.valueToProcess = returnedValue; return object2String(objectDTO); } } } catch (Exception e) { } } if (valueToProcess != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min > valueToProcess.longValue()) { valueToProcess = new AtomicLong(min); } if (max != null && max < valueToProcess.longValue()) { valueToProcess = new AtomicLong(max); } Integer precision = objectDTO.getPrecision(); if (precision != null) { valueToProcess = (AtomicLong) NumberUtil.setPrecision(valueToProcess, precision, getRoundingMode()); } return NumberUtil.toPlainString(valueToProcess); } } catch (Exception ex) { //ex.printStackTrace(); } } } return atomicLong2JsonDefault(objectDTO); }
From source file:ca.oson.json.Oson.java
private <E, R> AtomicLong json2AtomicLong(FieldData objectDTO) { if (objectDTO == null || !objectDTO.json2Java) { return null; }//from ww w.ja v a2s . c o m E value = (E) objectDTO.valueToProcess; Class<R> returnType = objectDTO.returnType; if (value != null && value.toString().trim().length() > 0) { String valueToProcess = value.toString().trim(); AtomicLong valueToReturn = null; try { Function function = objectDTO.getDeserializer(); if (function != null) { try { Object returnedValue = null; if (function instanceof Json2DataMapperFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); returnedValue = ((Json2DataMapperFunction) function).apply(classData); } else if (function instanceof Json2FieldDataFunction) { Json2FieldDataFunction f = (Json2FieldDataFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else if (function instanceof Json2AtomicLongFunction) { return ((Json2AtomicLongFunction) function).apply(valueToProcess); } else { returnedValue = function.apply(valueToProcess); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } else if (Number.class.isAssignableFrom(returnedValue.getClass()) || returnedValue.getClass().isPrimitive()) { if (returnedValue instanceof AtomicLong) { valueToReturn = (AtomicLong) returnedValue; } else if (returnedValue instanceof String) { valueToReturn = new AtomicLong( Long.parseLong(NumberUtil.removeTrailingDecimalZeros(returnedValue))); } else if (returnedValue instanceof Integer) { valueToReturn = new AtomicLong((Integer) returnedValue); } else if (returnedValue instanceof Long) { valueToReturn = new AtomicLong(((Long) returnedValue).longValue()); } else if (returnedValue instanceof Short) { valueToReturn = new AtomicLong((Short) returnedValue); } else if (returnedValue instanceof Double) { valueToReturn = new AtomicLong(((Double) returnedValue).longValue()); } else if (returnedValue instanceof Float) { valueToReturn = new AtomicLong(((Float) returnedValue).intValue()); } else if (returnedValue instanceof BigDecimal) { valueToReturn = new AtomicLong(((BigDecimal) returnedValue).longValue()); } else if (returnedValue instanceof Byte) { valueToReturn = new AtomicLong((Byte) returnedValue); } else if (returnedValue instanceof BigInteger) { valueToReturn = new AtomicLong(((BigInteger) returnedValue).longValue()); } else if (returnedValue instanceof AtomicInteger) { valueToReturn = new AtomicLong(((AtomicInteger) returnedValue).intValue()); } else { valueToReturn = new AtomicLong(((Number) returnedValue).longValue()); } } else if (returnedValue instanceof Character) { valueToReturn = new AtomicLong(((Character) returnedValue)); } else if (returnedValue instanceof Boolean) { if ((Boolean) returnedValue) valueToReturn = new AtomicLong(1); else valueToReturn = new AtomicLong(0); } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = new AtomicLong(((Enum) returnedValue).ordinal()); } else if (Date.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = new AtomicLong(((Date) returnedValue).getTime()); } else { valueToReturn = new AtomicLong( Long.parseLong(NumberUtil.removeTrailingDecimalZeros(returnedValue))); } return valueToReturn; } catch (Exception e) { e.printStackTrace(); } } else { valueToReturn = new AtomicLong( Long.parseLong(NumberUtil.removeTrailingDecimalZeros(valueToProcess))); } if (valueToReturn != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min > valueToReturn.longValue()) { return new AtomicLong(min); } if (max != null && valueToReturn.longValue() > max) { valueToReturn = new AtomicLong(max); } return valueToReturn; } } catch (Exception ex) { //ex.printStackTrace(); } } return json2AtomicLongDefault(objectDTO); }