List of usage examples for java.lang Integer longValue
public long longValue()
From source file:Main.java
public static void main(String[] args) { Integer integerObject = new Integer("1234567"); long l = integerObject.longValue(); System.out.println("long:" + l); }
From source file:Main.java
public static void main(String args[]) { Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("FALSE"); System.out.println(b1.toString() + " or " + b2.toString()); for (int j = 0; j < 16; ++j) System.out.print(Character.forDigit(j, 16)); Integer i = new Integer(Integer.parseInt("ef", 16)); Long l = new Long(Long.parseLong("abcd", 16)); long m = l.longValue() * i.longValue(); System.out.println(Long.toString(m, 8)); }
From source file:Main.java
public static void main(String args[]) { Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("FALSE"); System.out.println(b1.toString() + " or " + b2.toString()); for (int j = 0; j < 16; ++j) System.out.print(Character.forDigit(j, 16)); Integer i = new Integer(Integer.parseInt("ef", 16)); Long l = new Long(Long.parseLong("abcd", 16)); long m = l.longValue() * i.longValue(); System.out.println(Long.toString(m, 8)); System.out.println(Float.MIN_VALUE); System.out.println(Double.MAX_VALUE); }
From source file:WrappedClassApp.java
public static void main(String args[]) { Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("FALSE"); System.out.println(b1.toString() + " or " + b2.toString()); for (int j = 0; j < 16; ++j) System.out.print(Character.forDigit(j, 16)); System.out.println();/*w w w .ja v a2 s . c o m*/ Integer i = new Integer(Integer.parseInt("ef", 16)); Long l = new Long(Long.parseLong("abcd", 16)); long m = l.longValue() * i.longValue(); System.out.println(Long.toString(m, 8)); System.out.println(Float.MIN_VALUE); System.out.println(Double.MAX_VALUE); }
From source file:com.act.lcms.v2.MZCollisionCounter.java
public static void main(String[] args) throws Exception { CLIUtil cliUtil = new CLIUtil(MassChargeCalculator.class, HELP_MESSAGE, OPTION_BUILDERS); CommandLine cl = cliUtil.parseCommandLine(args); File inputFile = new File(cl.getOptionValue(OPTION_INPUT_INCHI_LIST)); if (!inputFile.exists()) { cliUtil.failWithMessage("Input file at does not exist at %s", inputFile.getAbsolutePath()); }/*from w w w . j av a2s . c o m*/ List<MassChargeCalculator.MZSource> sources = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) { String line; while ((line = reader.readLine()) != null) { line = line.trim(); sources.add(new MassChargeCalculator.MZSource(line)); if (sources.size() % 1000 == 0) { LOGGER.info("Loaded %d sources from input file", sources.size()); } } } Set<String> considerIons = Collections.emptySet(); if (cl.hasOption(OPTION_ONLY_CONSIDER_IONS)) { List<String> ions = Arrays.asList(cl.getOptionValues(OPTION_ONLY_CONSIDER_IONS)); LOGGER.info("Only considering ions for m/z calculation: %s", StringUtils.join(ions, ", ")); considerIons = new HashSet<>(ions); } TSVWriter<String, Long> tsvWriter = new TSVWriter<>(Arrays.asList("collisions", "count")); tsvWriter.open(new File(cl.getOptionValue(OPTION_OUTPUT_FILE))); try { LOGGER.info("Loaded %d sources in total from input file", sources.size()); MassChargeCalculator.MassChargeMap mzMap = MassChargeCalculator.makeMassChargeMap(sources, considerIons); if (!cl.hasOption(OPTION_COUNT_WINDOW_INTERSECTIONS)) { // Do an exact analysis of the m/z collisions if windowing is not specified. LOGGER.info("Computing precise collision histogram."); Iterable<Double> mzs = mzMap.ionMZIter(); Map<Integer, Long> collisionHistogram = histogram( StreamSupport.stream(mzs.spliterator(), false).map(mz -> { // See comment about Iterable below. try { return mzMap.ionMZToMZSources(mz).size(); } catch (NoSuchElementException e) { LOGGER.error("Caught no such element exception for mz %f: %s", mz, e.getMessage()); throw e; } })); List<Integer> sortedCollisions = new ArrayList<>(collisionHistogram.keySet()); Collections.sort(sortedCollisions); for (Integer collision : sortedCollisions) { tsvWriter.append(new HashMap<String, Long>() { { put("collisions", collision.longValue()); put("count", collisionHistogram.get(collision)); } }); } } else { /* After some deliberation (thanks Gil!), the windowed variant of this calculation counts the number of * structures whose 0.01 Da m/z windows (for some set of ions) overlap with each other. * * For example, let's assume we have five total input structures, and are only searching for one ion. Let's * also assume that three of those structures have m/z A and the remaining two have m/z B. The windows might * look like this in the m/z domain: * |----A----| * |----B----| * Because A represents three structures and overlaps with B, which represents two, we assign A a count of 5-- * this is the number of structures we believe could fall into the range of A given our current peak calling * approach. Similarly, B is assigned a count of 5, as the possibility for collision/confusion is symmetric. * * Note that this is an over-approximation of collisions, as we could more precisely only consider intersections * when the exact m/z of B falls within the window around A and vice versa. However, because we have observed * cases where the MS sensor doesn't report structures at exactly the m/z we predict, we employ this weaker * definition of intersection to give a slightly pessimistic view of what confusions might be possible. */ // Compute windows for every m/z. We don't care about the original mz values since we just want the count. List<Double> mzs = mzMap.ionMZsSorted(); final Double windowHalfWidth; if (cl.hasOption(OPTION_WINDOW_HALFWIDTH)) { // Don't use get with default for this option, as we want the exact FP value of the default tolerance. windowHalfWidth = Double.valueOf(cl.getOptionValue(OPTION_WINDOW_HALFWIDTH)); } else { windowHalfWidth = DEFAULT_WINDOW_TOLERANCE; } /* Window = (lower bound, upper bound), counter of represented m/z's that collide with this window, and number * of representative structures (which will be used in counting collisions). */ LinkedList<CollisionWindow> allWindows = new LinkedList<CollisionWindow>() { { for (Double mz : mzs) { // CPU for memory trade-off: don't re-compute the window bounds over and over and over and over and over. try { add(new CollisionWindow(mz, windowHalfWidth, mzMap.ionMZToMZSources(mz).size())); } catch (NoSuchElementException e) { LOGGER.error("Caught no such element exception for mz %f: %s", mz, e.getMessage()); throw e; } } } }; // Sweep line time! The window ranges are the interesting points. We just accumulate overlap counts as we go. LinkedList<CollisionWindow> workingSet = new LinkedList<>(); List<CollisionWindow> finished = new LinkedList<>(); while (allWindows.size() > 0) { CollisionWindow thisWindow = allWindows.pop(); // Remove any windows from the working set that don't overlap with the next window. while (workingSet.size() > 0 && workingSet.peekFirst().getMaxMZ() < thisWindow.getMinMZ()) { finished.add(workingSet.pop()); } for (CollisionWindow w : workingSet) { /* Add the size of the new overlapping window's structure count to each of the windows in the working set, * which represents the number of possible confused structures that fall within the overlapping region. * We exclude the window itself as it should already have counted the colliding structures it represents. */ w.getAccumulator().add(thisWindow.getStructureCount()); /* Reciprocally, add the structure counts of all windows with which the current window overlaps to it. */ thisWindow.getAccumulator().add(w.getStructureCount()); } // Now that accumulation is complete, we can safely add the current window. workingSet.add(thisWindow); } // All the interesting events are done, so drop the remaining windows into the finished set. finished.addAll(workingSet); Map<Long, Long> collisionHistogram = histogram( finished.stream().map(w -> w.getAccumulator().longValue())); List<Long> sortedCollisions = new ArrayList<>(collisionHistogram.keySet()); Collections.sort(sortedCollisions); for (Long collision : sortedCollisions) { tsvWriter.append(new HashMap<String, Long>() { { put("collisions", collision); put("count", collisionHistogram.get(collision)); } }); } } } finally { if (tsvWriter != null) { tsvWriter.close(); } } }
From source file:com.act.biointerpretation.analytics.ReactionDeletion.java
public static void searchForDroppedReactions(NoSQLAPI srcApi, NoSQLAPI sinkApi, File outputFile) throws IOException { Set<Long> srcIds = new HashSet<>(); DBIterator iterator = srcApi.getReadDB().getIteratorOverReactions( new BasicDBObject("$query", new BasicDBObject()).append("$orderby", new BasicDBObject("_id", 1)), new BasicDBObject("_id", true)); while (iterator.hasNext()) { DBObject obj = iterator.next();/* w w w.ja v a 2 s. c om*/ Object id = obj.get("_id"); if (id instanceof Integer) { Integer idi = (Integer) id; srcIds.add(idi.longValue()); } else { String msg = String.format("Found unexpected %s value for _id in src DB: %s", id.getClass().getName(), id); LOGGER.error(msg); throw new RuntimeException(msg); } } iterator.close(); Iterator<Reaction> sinkRxns = sinkApi.readRxnsFromInKnowledgeGraph(); while (sinkRxns.hasNext()) { Reaction rxn = sinkRxns.next(); for (JSONObject protein : rxn.getProteinData()) { if (protein.has("source_reaction_id")) { Long srcId = protein.getLong("source_reaction_id"); srcIds.remove(srcId); } else LOGGER.error("Found protein without source id for reaction %d", rxn.getUUID()); } } if (srcIds.size() == 0) { LOGGER.info( "No source read DB ids were unaccounted for in the write DB. Exiting without writing output."); return; } List<Long> sortedSrcIds = new ArrayList<>(srcIds); Collections.sort(sortedSrcIds); try (TSVWriter<String, String> writer = new TSVWriter<>(OUTPUT_HEADER)) { writer.open(outputFile); int noProteinReactions = 0; for (Long id : sortedSrcIds) { Reaction rxn = srcApi.readReactionFromInKnowledgeGraph(id); if (rxn == null) { LOGGER.error("Could not read reaction %d from source DB", id); continue; } if (rxn.getProteinData().size() == 0) { LOGGER.debug("Reaction %d has no proteins, and so cannot participate in the provenance chain", rxn.getUUID()); noProteinReactions++; continue; } Map<String, String> row = new HashMap<String, String>(OUTPUT_HEADER.size()) { { put("id", Long.valueOf(rxn.getUUID()).toString()); put("substrates", "{" + StringUtils.join(rxn.getSubstrates(), ",") + "}"); put("products", "{" + StringUtils.join(rxn.getProducts(), ",") + "}"); put("ecnum", rxn.getECNum()); put("easy_desc", rxn.getReactionName()); } }; writer.append(row); writer.flush(); } LOGGER.info("Found %d reactions with no proteins of %d reactions that might have been deleted", noProteinReactions, srcIds.size()); } }
From source file:eu.project.ttc.readers.TermSuiteJsonCasSerializer.java
private static void writeIntField(JsonGenerator jg, String fieldName, Integer value) throws IOException { writeLongField(jg, fieldName, value.longValue()); }
From source file:org.asoem.greyfish.utils.collect.BitStringTest.java
public static double chiSquareTest(final Map<Integer, Integer> samples1, final Map<Integer, Integer> samples2) { final ArrayList<Long> observed1 = Lists.newArrayList(); final ArrayList<Long> observed2 = Lists.newArrayList(); for (Integer key : Sets.union(samples1.keySet(), samples2.keySet())) { final Integer freq1 = Optional.fromNullable(samples1.get(key)).or(0); final Integer freq2 = Optional.fromNullable(samples2.get(key)).or(0); observed1.add(freq1.longValue()); observed2.add(freq2.longValue()); }// w w w.j a va2 s. c om return new ChiSquareTest().chiSquareTestDataSetsComparison(Longs.toArray(observed1), Longs.toArray(observed2)); }
From source file:org.loklak.api.search.SuggestServlet.java
public static ResultList<QueryEntry> suggest(final String protocolhostportstub, final String q, final String source, final int count, final String order, final String orderby, final int timezoneOffset, final String since, final String until, final String selectby, final int random) throws IOException { int httpport = (int) DAO.getConfig("port.http", 9000); int httpsport = (int) DAO.getConfig("port.https", 9443); String peername = (String) DAO.getConfig("peername", "anonymous"); ResultList<QueryEntry> rl = new ResultList<QueryEntry>(); String urlstring = ""; urlstring = protocolhostportstub + "/api/suggest.json?q=" + URLEncoder.encode(q.replace(' ', '+'), "UTF-8") + "&timezoneOffset=" + timezoneOffset + "&count=" + count + "&source=" + (source == null ? "all" : source) + (order == null ? "" : ("&order=" + order)) + (orderby == null ? "" : ("&orderby=" + orderby)) + (since == null ? "" : ("&since=" + since)) + (until == null ? "" : ("&until=" + until)) + (selectby == null ? "" : ("&selectby=" + selectby)) + (random < 0 ? "" : ("&random=" + random)) + "&minified=true" + "&port.http=" + httpport + "&port.https=" + httpsport + "&peername=" + peername; byte[] response = ClientConnection.downloadPeer(urlstring); if (response == null || response.length == 0) return rl; String responseString = UTF8.String(response); if (responseString == null || responseString.length() == 0 || responseString.startsWith("<")) { // fail/* www .ja va 2s . co m*/ return rl; } JSONObject json = new JSONObject(responseString); JSONArray queries = json.has("queries") ? json.getJSONArray("queries") : null; if (queries != null) { for (Object query_obj : queries) { if (query_obj == null) continue; QueryEntry qe = new QueryEntry((JSONObject) query_obj); rl.add(qe); } } Object metadata_obj = json.get("search_metadata"); if (metadata_obj != null && metadata_obj instanceof Map<?, ?>) { Integer hits = (Integer) ((JSONObject) metadata_obj).get("hits"); if (hits != null) rl.setHits(hits.longValue()); } return rl; }
From source file:com.example.mobilewebproxy.MainActivity.java
private static String getBytesTextValue(String prevCount, long countRaise) { long totalBytes = countRaise; Double prevNum;/*from w ww .j a v a 2 s . c o m*/ Double convertedValue; StringBuilder builder = new StringBuilder(prevCount); if (!prevCount.endsWith("kb") && !prevCount.endsWith("mb")) { builder.deleteCharAt(prevCount.length() - 1); Integer temp = Integer.parseInt(builder.toString()); totalBytes += temp.longValue(); } else if (prevCount.endsWith("kb")) { builder.delete(prevCount.length() - 2, prevCount.length()); prevNum = Double.parseDouble(builder.toString()); convertedValue = prevNum * 1024.0; totalBytes += convertedValue.longValue(); } else if (prevCount.endsWith("mb")) { builder.delete(prevCount.length() - 2, prevCount.length()); prevNum = Double.parseDouble(builder.toString()); convertedValue = prevNum * 1024.0 * 1024.0; totalBytes += convertedValue.longValue(); } return bytesToReadableString(totalBytes); }