List of usage examples for java.lang Long intValue
public int intValue()
From source file:com.evolveum.midpoint.repo.sql.util.RUtil.java
public static Integer toInteger(Long l) { if (l == null) { return null; }/* w ww .j a v a 2 s . c o m*/ if (l > Integer.MAX_VALUE || l < Integer.MIN_VALUE) { throw new IllegalArgumentException("Couldn't cast value to Integer " + l); } return l.intValue(); }
From source file:model.manager.AdherenceManager.java
/** * Get days supply for a drug in a package * // w w w .j a va 2 s .co m * @param session * @param d * @param p * @return int * @throws HibernateException */ public static int getDaysSuppliedForDrugInPackage(Session session, Drug d, Packages p) throws HibernateException { Long unitsSupplied = (Long) session .createQuery( "select sum(pd.amount) from PackagedDrugs as pd where pd.parentPackage.id = :thePackageId" + " and pd.stock.drug.id = :theDrugId") .setInteger("thePackageId", p.getId()).setInteger("theDrugId", d.getId()).uniqueResult(); int unitsPerDay = getUnitsPerDayForDrugInPackage(session, d, p); if (unitsPerDay == 0) return 0; return unitsSupplied.intValue() / unitsPerDay; }
From source file:model.manager.AdherenceManager.java
/** * Get days accumulated for a drug in a package * /*from w ww .ja v a2s . c o m*/ * @param session * @param d * @param p * @return int * @throws HibernateException */ public static int getDaysAccumulatedForDrugInPackage(Session session, Drug d, Packages p) throws HibernateException { Long unitsAccum = (Long) session.createQuery( "select sum(ad.pillCount.accum) from AccumulatedDrugs as ad where ad.withPackage = :thePackageId" + " and ad.pillCount.drug.id = :theDrugId") .setInteger("thePackageId", p.getId()).setInteger("theDrugId", d.getId()).uniqueResult(); int unitsPerDay = getUnitsPerDayForDrugInPackage(session, d, p); if (unitsPerDay == 0) return 0; if (unitsAccum == null) return 0; return unitsAccum.intValue() / unitsPerDay; }
From source file:ext.msg.model.Message.java
/** * ???/*from w w w . java2 s.c o m*/ * @return */ public static ChatMsgCount chatMsgUnReadInfo(User user) { ChatMsgCount msgCountVO = new ChatMsgCount(); try { List<ChatMsgUnReadNumVO> cmurnVO = ChatMessageResult.getChatMsgUnReadNumVOList(user); if (CollectionUtils.isNotEmpty(cmurnVO)) { Long totalChatMsgNum = 0L; for (ChatMsgUnReadNumVO vo : cmurnVO) { totalChatMsgNum += vo.getMsgNum(); } msgCountVO.setChatMsgNum(totalChatMsgNum.intValue()); } msgCountVO.setChatMsgNumJson(play.libs.Json.toJson(cmurnVO).toString()); } catch (IOException e) { e.printStackTrace(); msgCountVO.setChatMsgNumJson("{\"status\":\"0\",\"error\":\"??\"}"); } return msgCountVO; }
From source file:com.github.codingtogenomic.CodingToGenomic.java
private static String threePrimeUtrToGenomicCoordinate(final String id, final int coord) throws ParseException, MalformedURLException, IOException, InterruptedException { final String trEndpoint = "/lookup/id/" + id + "?expand=1"; final JSONObject trInfo = (JSONObject) getJSON(trEndpoint); if (trInfo.isEmpty()) { throw new RuntimeException("Got nothing for endpoint " + trEndpoint); }//from ww w . ja va 2 s . c o m final TranscriptDetails trDetails = getTranscriptDetailsFromJson(trInfo); final int cdsLength = trDetails.getCodingLength(); final String cdsEndpoint = "/map/cds/" + id + "/" + cdsLength + ".." + cdsLength; final JSONObject cdsInfo = (JSONObject) getJSON(cdsEndpoint); if (cdsInfo.isEmpty()) { throw new RuntimeException("Got nothing for endpoint " + cdsEndpoint); } if (cdsInfo.containsKey("mappings")) { StringBuilder mapStrings = new StringBuilder(); final JSONArray mappings = (JSONArray) cdsInfo.get("mappings"); int n = 0; for (Object map : mappings) { n++; if (n > 1) { mapStrings.append("|"); } JSONObject m = (JSONObject) map; if (m.containsKey("start") && m.containsKey("seq_region_name")) { //assembly = (String) m.get("assembly_name"); String chr = (String) m.get("seq_region_name"); Long genomicCoord = (Long) m.get("start"); String trPos = trDetails.getCdnaPosition(chr, genomicCoord.intValue()); try { int pos = Integer.parseInt(trPos); if (coord > pos) { mapStrings.append("UTR position > length of 3' UTR"); } else { String cdnaPos = cdnaToGenomicCoordinate(id, pos + coord); if (cdnaPos != null) { mapStrings.append(cdnaPos); } } } catch (NumberFormatException | ParseException | IOException | InterruptedException ex) { mapStrings.append("Could not parse cDNA position " + "(" + trPos + ") for " + id); } } } return mapStrings.toString(); } return null; }
From source file:com.github.codingtogenomic.CodingToGenomic.java
private static String fivePrimeUtrToGenomicCoordinate(final String id, final int coord) throws ParseException, MalformedURLException, IOException, InterruptedException { if (coord > 0) { throw new RuntimeException( "fivePrimeUtrToGenomicCoordinate method requires " + "coordinate to be less than zero"); }// w ww .j ava2 s . co m final String trEndpoint = "/lookup/id/" + id + "?expand=1"; final JSONObject trInfo = (JSONObject) getJSON(trEndpoint); if (trInfo.isEmpty()) { throw new RuntimeException("Got nothing for endpoint " + trEndpoint); } final TranscriptDetails trDetails = getTranscriptDetailsFromJson(trInfo); final String cdsEndpoint = "/map/cds/" + id + "/" + 1 + ".." + 1; final JSONObject cdsInfo = (JSONObject) getJSON(cdsEndpoint); if (cdsInfo.isEmpty()) { throw new RuntimeException("Got nothing for endpoint " + cdsEndpoint); } if (cdsInfo.containsKey("mappings")) { StringBuilder mapStrings = new StringBuilder(); final JSONArray mappings = (JSONArray) cdsInfo.get("mappings"); int n = 0; for (Object map : mappings) { n++; if (n > 1) { mapStrings.append("|"); } JSONObject m = (JSONObject) map; if (m.containsKey("start") && m.containsKey("seq_region_name")) { //assembly = (String) m.get("assembly_name"); String chr = (String) m.get("seq_region_name"); Long genomicCoord = (Long) m.get("start"); String trPos = trDetails.getCdnaPosition(chr, genomicCoord.intValue()); try { int pos = Integer.parseInt(trPos); if (Math.abs(coord) > pos) { mapStrings.append("UTR position > length of 5' UTR"); } else { String cdnaPos = cdnaToGenomicCoordinate(id, pos + coord); if (cdnaPos != null) { mapStrings.append(cdnaPos); } } } catch (NumberFormatException | ParseException | IOException | InterruptedException ex) { mapStrings.append("Could not parse cDNA position " + "(" + trPos + ") for " + id); } } } return mapStrings.toString(); } return null; }
From source file:com.cloud.utils.StringUtils.java
public static <T> List<T> applyPagination(final List<T> originalList, final Long startIndex, final Long pageSizeVal) { // Most likely pageSize will never exceed int value, and we need integer to partition the listToReturn final boolean applyPagination = startIndex != null && pageSizeVal != null && startIndex <= Integer.MAX_VALUE && startIndex >= Integer.MIN_VALUE && pageSizeVal <= Integer.MAX_VALUE && pageSizeVal >= Integer.MIN_VALUE; List<T> listWPagination = null; if (applyPagination) { listWPagination = new ArrayList<>(); final int index = startIndex.intValue() == 0 ? 0 : startIndex.intValue() / pageSizeVal.intValue(); final List<List<T>> partitions = StringUtils.partitionList(originalList, pageSizeVal.intValue()); if (index < partitions.size()) { listWPagination = partitions.get(index); }/*from w w w . j a v a 2 s . c om*/ } return listWPagination; }
From source file:com.github.codingtogenomic.CodingToGenomic.java
private static TranscriptDetails getTranscriptDetailsFromJson(final JSONObject j) throws ParseException, MalformedURLException, IOException, InterruptedException { final TranscriptDetails trans = new TranscriptDetails(); trans.setTranscriptId((String) j.get("id")); final String biotype = (String) j.get("biotype"); trans.setBiotype(biotype);/* www.j av a2 s.co m*/ if (j.containsKey("is_canonical")) { String isCanon = j.get("is_canonical").toString(); if (Integer.parseInt(isCanon) > 0) { trans.setIsCanonical(true); } else { trans.setIsCanonical(false); } } if (j.containsKey("strand")) { if ((Long) j.get("strand") > 0) { trans.setStrand(1); } else { trans.setStrand(-1); } } //get exons if (j.containsKey("Exon")) { JSONArray exons = (JSONArray) j.get("Exon"); for (Object e : exons) { JSONObject jxon = (JSONObject) e; TranscriptDetails.Exon exon = trans.new Exon(); Long start = (Long) jxon.get("start"); Long end = (Long) jxon.get("end"); exon.setStart(start.intValue()); exon.setEnd(end.intValue()); trans.getExons().add(exon); } //sort and number exons Collections.sort(trans.getExons()); for (int i = 0; i < trans.getExons().size(); i++) { if (trans.getStrand() < 0) { trans.getExons().get(i).setOrder(trans.getExons().size() - i); } else { trans.getExons().get(i).setOrder(i + 1); } } } //get chromosome if (j.containsKey("seq_region_name")) { trans.setChromosome((String) j.get("seq_region_name")); } //get transcription start and end if (j.containsKey("start")) { Long start = (Long) j.get("start"); trans.setTxStart(start.intValue()); } if (j.containsKey("end")) { Long end = (Long) j.get("end"); trans.setTxEnd(end.intValue()); } //get translation start and end if coding if (j.containsKey("Translation")) { JSONObject p = (JSONObject) j.get("Translation"); trans.setProteinId((String) p.get("id")); Long start = (Long) p.get("start"); Long end = (Long) p.get("end"); trans.setCdsStart(start.intValue()); trans.setCdsEnd(end.intValue()); Long length = (Long) p.get("length"); trans.setProteinLength(length.intValue()); } else { //if using a transcript id for some reason rest won't return translation } return trans; }
From source file:com.redhat.rhn.domain.config.ConfigurationFactory.java
/** * Convert input stream to byte array//from www. j ava2 s . c om * @param stream input stream * @param size stream size * @return byte array */ public static byte[] bytesFromStream(InputStream stream, Long size) { byte[] foo = new byte[size.intValue()]; try { //this silly bit of logic is to ensure that we read as much from the file //as we possibly can. Most likely, stream.read(foo) would do the exact same //thing, but according to the javadoc, that may not always be the case. int offset = 0; int read = 0; // mark and reset stream, so that stream can be re-read later stream.mark(size.intValue()); do { read = stream.read(foo, offset, (foo.length - offset)); offset += read; } while (read > 0 && offset < foo.length); stream.reset(); } catch (IOException e) { log.error("IOException while reading config content from input stream!", e); throw new RuntimeException("IOException while reading config content from" + " input stream!"); } return foo; }
From source file:de.dailab.plistacontest.client.RecommenderItem.java
/** * Parse the ORP json Messages.// w w w . j ava 2s .co m * * @param _jsonMessageBody * @return the parsed values encapsulated in a map; null if an error has * been detected. */ public static RecommenderItem parseRecommendationRequest(String _jsonMessageBody) { try { final JSONObject jsonObj = (JSONObject) JSONValue.parse(_jsonMessageBody); // parse JSON structure to obtain "context.simple" JSONObject jsonObjectContext = (JSONObject) jsonObj.get("context"); JSONObject jsonObjectContextSimple = (JSONObject) jsonObjectContext.get("simple"); Long domainID = -3L; try { domainID = Long.valueOf(jsonObjectContextSimple.get("27").toString()); } catch (Exception ignored) { try { domainID = Long.valueOf(jsonObjectContextSimple.get("domainId").toString()); } catch (Exception e) { System.err.println("[Exception] no domainID found in " + _jsonMessageBody); } } Long itemID = null; try { itemID = Long.valueOf(jsonObjectContextSimple.get("25").toString()); } catch (Exception ignored) { try { itemID = Long.valueOf(jsonObjectContextSimple.get("itemId").toString()); } catch (Exception e) { System.err.println("[Exception] no itemID found in " + _jsonMessageBody); } } Long userID = -2L; try { userID = Long.valueOf(jsonObjectContextSimple.get("57").toString()); } catch (Exception ignored) { try { userID = Long.valueOf(jsonObjectContextSimple.get("userId").toString()); } catch (Exception e) { System.err.println("[INFO] no userID found in " + _jsonMessageBody); } } long timeStamp = 0; try { timeStamp = (Long) jsonObj.get("created_at") + 0L; } catch (Exception ignored) { timeStamp = (Long) jsonObj.get("timestamp"); } try { userID = Long.valueOf(jsonObjectContextSimple.get("userId").toString()); } catch (Exception e) { System.err.println("[INFO] no userID found in " + _jsonMessageBody); } Long limit = 0L; try { limit = (Long) jsonObj.get("limit"); } catch (Exception e) { System.err.println("[Exception] no limit found in " + _jsonMessageBody); } RecommenderItem result = new RecommenderItem(userID, itemID, domainID, timeStamp); result.setNumberOfRequestedResults(limit.intValue()); return result; } catch (Exception e) { e.printStackTrace(); } return null; }