List of usage examples for java.math BigInteger longValue
public long longValue()
From source file:com.abiquo.am.services.download.OVFDocumentFetch.java
public EnvelopeType checkEnvelopeIsValid(final EnvelopeType envelope) { try {//from w ww. j a va2s. c o m Map<String, VirtualDiskDescType> diskIdToDiskFormat = new HashMap<String, VirtualDiskDescType>(); Map<String, FileType> fileIdToFileType = new HashMap<String, FileType>(); DiskSectionType diskSectionType = OVFEnvelopeUtils.getSection(envelope, DiskSectionType.class); if (diskSectionType.getDisk().size() != 1) { // more than one disk in disk section throw new AMException(AMError.TEMPLATE_INVALID_MULTIPLE_DISKS); } else { int references = 0; for (FileType fileType : envelope.getReferences().getFile()) { fileIdToFileType.put(fileType.getId(), fileType); if (diskSectionType.getDisk().get(0).getFileRef().equals(fileType.getId())) { references++; } } if (references != 1) { // file referenced in diskSection isn't found in file references or found more // than one throw new AMException(AMError.TEMPLATE_INVALID_MULTIPLE_FILES); } } // Create a hash for (VirtualDiskDescType virtualDiskDescType : diskSectionType.getDisk()) { diskIdToDiskFormat.put(virtualDiskDescType.getDiskId(), virtualDiskDescType); } // / ContentType content = OVFEnvelopeUtils.getTopLevelVirtualSystemContent(envelope); if (content instanceof VirtualSystemCollectionType) { throw new EmptyEnvelopeException( "Current OVF description document includes a VirtualSystemCollection, " + "abicloud only deal with single virtual system based OVFs"); } VirtualSystemType vsystem = (VirtualSystemType) content; VirtualHardwareSectionType hardwareSectionType; Integer cpu = null; Long hd = null; Long ram = null; try { hardwareSectionType = OVFEnvelopeUtils.getSection(vsystem, VirtualHardwareSectionType.class); } catch (InvalidSectionException e) { throw new SectionNotPresentException("VirtualHardware on a virtualSystem", e); } for (RASDType rasdType : hardwareSectionType.getItem()) { ResourceType resourceType = rasdType.getResourceType(); if (resourceType == null) // empty rasd element { continue; } int resTnumeric = Integer.parseInt(resourceType.getValue()); // Get the information on the ram if (CIMResourceTypeEnum.Processor.getNumericResourceType() == resTnumeric) { try { String cpuVal = rasdType.getVirtualQuantity().getValue().toString(); cpu = Integer.parseInt(cpuVal); } catch (Exception e) { throw new AMException(AMError.TEMPLATE_INVALID, "Invalid CPU virtualQuantity"); } } else if (CIMResourceTypeEnum.Memory.getNumericResourceType() == resTnumeric) { try { BigInteger ramVal = rasdType.getVirtualQuantity().getValue(); ram = ramVal.longValue(); } catch (Exception e) { throw new AMException(AMError.TEMPLATE_INVALID, "Invalid RAM virtualQuantity"); } if (rasdType.getAllocationUnits() != null & rasdType.getAllocationUnits().getValue() != null) { final String allocationUnits = rasdType.getAllocationUnits().getValue(); final MemorySizeUnit ramSizeUnit = getMemoryUnitsFromOVF(allocationUnits); } } else if (CIMResourceTypeEnum.Disk_Drive.getNumericResourceType() == resTnumeric) { // HD requirements are extracted from the associated Disk on ''hostResource'' String diskId = getVirtualSystemDiskId(rasdType.getHostResource()); if (!diskIdToDiskFormat.containsKey(diskId)) { throw new RequiredAttributeException( "Virtual System makes reference to an undeclared disk " + diskId); } VirtualDiskDescType diskDescType = diskIdToDiskFormat.get(diskId); String capacity = diskDescType.getCapacity(); hd = Long.parseLong(capacity); final String allocationUnits = diskDescType.getCapacityAllocationUnits(); final MemorySizeUnit hdSizeUnit = getMemoryUnitsFromOVF(allocationUnits); } } // rasd if (cpu == null) { throw new RequiredAttributeException("Not CPU RASD element found on the envelope"); } if (ram == null) { throw new RequiredAttributeException("Not RAM RASD element found on the envelope"); } if (hd == null) { throw new RequiredAttributeException("Not HD RASD element found on the envelope"); } } catch (AMException amException) { throw amException; } catch (Exception e) { throw new AMException(AMError.TEMPLATE_INVALID, e); } return envelope; }
From source file:org.alfresco.services.ContentGetterImpl.java
@Override public Content getContentByNodeId(String nodeId, Long nodeVersion) { Content content = null;//w w w . jav a 2 s . c om StringBuilder sb = new StringBuilder(nodeId); if (nodeVersion != null) { sb.append(";"); sb.append(nodeVersion); } ObjectId objectId = new ObjectIdImpl(sb.toString()); Session session = getCMISSession(); try { Document document = (Document) session.getObject(objectId); if (document != null) { if (document.isLatestVersion()) { String mimeType = (String) document.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE) .getFirstValue(); BigInteger size = (BigInteger) document.getProperty(PropertyIds.CONTENT_STREAM_LENGTH) .getFirstValue(); ContentStream stream = document.getContentStream(); if (stream != null) { InputStream is = stream.getStream(); ReadableByteChannel channel = Channels.newChannel(is); content = new Content(channel, size.longValue()); } } else { logger.warn("Node " + nodeId + "." + nodeVersion + " not latest version"); } } else { logger.warn("Node " + nodeId + "." + nodeVersion + " not found"); } } catch (CmisObjectNotFoundException e) { logger.warn("Node " + nodeId + "." + nodeVersion + " not found"); } return content; }
From source file:de.schildbach.wallet.ui.ChannelRequestActivity.java
private boolean validateAmounts(final boolean popups) { final BigInteger amount = currencyCalculatorLink.getAmount(); if (popups)// w w w . j a v a 2 s .c o m dismissPopup(); View popup = SendCoinsFragment.validateAmount(this, wallet, amount, popupMessageView, popupAvailableView); if (popup == null && amount.longValue() < appSpecifiedMinValue) { // app wants more value than allowed, popup an error to the user so they know why accept doesn't work final CurrencyTextView viewAvailable = (CurrencyTextView) popupAvailableView .findViewById(R.id.send_coins_popup_available_amount); viewAvailable.setPrefix(Constants.CURRENCY_CODE_BITCOIN); viewAvailable.setAmount(BigInteger.valueOf(appSpecifiedMinValue)); final TextView viewPending = (TextView) popupAvailableView .findViewById(R.id.send_coins_popup_available_pending); viewPending.setVisibility(View.GONE); final TextView textLabel = (TextView) popupAvailableView .findViewById(R.id.send_coins_popup_available_label); textLabel.setText(R.string.send_coins_fragment_channel_label); popup = popupAvailableView; } if (popup == null) return true; else if (popups) { if (popup == popupMessageView) popupMessageView.setMaxWidth(getWindow().getDecorView().getWidth()); popup(currencyCalculatorLink.activeView(), popup); } return false; //TODO ? updateView(); }
From source file:net.umpay.mailbill.hql.orm.hibernate.HibernateDao.java
protected long countSqlResult(final String sql, final Object... values) { String countHql = "select count(1) from (" + sql + ") totalcount"; try {//from www .ja v a2 s. c om BigInteger count = new BigInteger(findUniqueSql(countHql, values).toString()); return count.longValue(); } catch (Exception e) { throw new RuntimeException("hql can't be auto count, hql is:" + countHql, e); } }
From source file:net.umpay.mailbill.hql.orm.hibernate.HibernateDao.java
public long countSqlResult(final String sql, final Map<String, ?> values) { String countHql = "select count(1) from (" + sql + ") totalcount"; try {// ww w . j a va 2 s . c o m BigInteger count = new BigInteger(findUniqueSql(countHql, values).toString()); return count.longValue(); } catch (Exception e) { throw new RuntimeException("hql can't be auto count, hql is:" + countHql, e); } }
From source file:controllers.CommentController.java
public Result getMentions(String email) { Long userId = userRepository.getUserIdByEmail(email); String username = userRepository.getUsernameByEmail(email); List<BigInteger> commentIds = mentionRepository.findAllCommentIdByUsername(username); ArrayNode commentArray = JsonNodeFactory.instance.arrayNode(); Long total_comment = 0L;// w w w . j a va 2s . c o m ObjectNode response = Json.newObject(); ObjectNode result = Json.newObject(); ObjectNode user = Json.newObject(); // User node if (userId == null) { user.put("user_id", -1); user.put("fullname", "Visitor"); user.put("is_logged_in", false); user.put("is_add_allowed", false); user.put("is_edit_allowed", false); } else { user.put("user_id", userId); user.put("fullname", username); user.put("is_logged_in", true); user.put("is_add_allowed", true); user.put("is_edit_allowed", true); } user.put("picture", "/assets/images/user_blank_picture.png"); for (BigInteger commentId : commentIds) { //Long commentId = ((BigInteger)commentIds[i]).longValue(); Comment comment = commentRepository.findCommentById(commentId.longValue()); ObjectNode oneComment = JsonNodeFactory.instance.objectNode(); oneComment.put("comment_id", comment.getCommentId()); oneComment.put("parent_id", 0); oneComment.put("in_reply_to", comment.getInReplyTo()); oneComment.put("element_id", comment.getElementId()); oneComment.put("created_by", comment.getCreatedBy()); oneComment.put("fullname", comment.getFullname()); oneComment.put("picture", comment.getPicture()); oneComment.put("posted_date", timeFormat.format(comment.getPostedDate())); oneComment.put("text", comment.getText()); oneComment.put("attachments", JsonNodeFactory.instance.arrayNode()); oneComment.put("childrens", JsonNodeFactory.instance.arrayNode()); commentArray.add(oneComment); total_comment++; } // result result.put("comments", commentArray); result.put("total_comment", total_comment); result.put("user", user); // response response.put("results", result); return ok(response.toString()); }
From source file:chibi.gemmaanalysis.SummaryStatistics.java
/** * For each pair of genes, count how many expression experiments both appear in. * //from www .j a v a 2 s.c o m * @param taxon */ public void genePairOccurrenceDistributions(Taxon taxon) { Collection<ExpressionExperiment> eeColl = expressionExperimentService.loadAll(); CompressedSparseDoubleMatrix<Long, Long> mat = new CompressedSparseDoubleMatrix<Long, Long>(MAX_GENES, MAX_GENES); int numEEs = 0; for (ExpressionExperiment experiment : eeColl) { if (numEEs > MAX_EXPS) break; Taxon eeTax = expressionExperimentService.getTaxon(experiment); if (eeTax == null || !eeTax.equals(taxon)) continue; Collection<ArrayDesign> ads = expressionExperimentService.getArrayDesignsUsed(experiment); // only count each gene once per data set. Collection<Long> seenids = new HashSet<Long>(); for (ArrayDesign design : ads) { Collection<Object[]> vals = compositeSequenceService.getRawSummary(design, null); log.info(numEEs + " " + design + "Got " + vals.size() + " reports"); for (Object[] objects : vals) { BigInteger geneidi = (BigInteger) objects[10]; if (geneidi == null) { continue; } Long geneid = geneidi.longValue(); if (seenids.contains(geneid)) continue; if (!mat.containsRowName(geneid)) { mat.addRowName(geneid); } int outerIndex = mat.getRowIndexByName(geneid); int j = 0; for (Object[] ojbB : vals) { BigInteger geneBidi = (BigInteger) ojbB[10]; if (geneBidi == null || geneBidi.equals(geneidi)) { continue; } Long geneBid = geneBidi.longValue(); if (seenids.contains(geneBid)) continue; int innerIndex; if (!mat.containsColumnName(geneBid)) { mat.addColumnName(geneBid); innerIndex = mat.getColIndexByName(geneBid); mat.set(outerIndex, innerIndex, 0.0); // initialize } innerIndex = mat.getColIndexByName(geneBid); mat.set(outerIndex, innerIndex, mat.get(outerIndex, innerIndex) + 1); if (mat.columns() > MAX_GENES) { log.warn("Too many genes!"); break; } j++; if (j > 1000) break; } seenids.add(geneid); if (mat.rows() > MAX_GENES) { break; } } } numEEs++; } // print the histogram. int[] counts = new int[MAX_EXPS + 1]; for (Long outer : mat.getRowNames()) { double[] row = mat.getRowByName(outer); for (double d : row) { counts[(int) d]++; } } for (int j = 0; j < counts.length; j++) { System.out.println(j + "\t" + counts[j]); } }
From source file:com.healthcit.cacure.dao.FormElementDao.java
/** * @param q/*from ww w. jav a 2 s . c o m*/ * String * @return List<Question> */ @SuppressWarnings("unchecked") public List<FormElement> getFormElementsByText(String q) { List<FormElement> elements = new ArrayList<FormElement>(); // List<Object> result = Collections.emptyList(); List<BigInteger> result = Collections.emptyList(); if (StringUtils.isNotEmpty(q)) { String query = q.replaceAll("'", "''"); Query nativeQuery = em.createNativeQuery("select q.id" + " from form_element q, form f, plainto_tsquery('ts_config', '" + query + "') query" + " where q.form_id = f.id AND f.form_type = 'questionLibraryForm' AND q.ts_data @@ query" + " order by ts_rank_cd(q.ts_data, query) desc"); result = nativeQuery.getResultList(); Query selectElement = em.createQuery("from FormElement fe where id = :id"); for (BigInteger id : result) { selectElement.setParameter("id", id.longValue()); elements.add((FormElement) selectElement.getSingleResult()); } } return elements; }
From source file:org.opendaylight.netvirt.vpnmanager.ArpNotificationHandler.java
private boolean isIpInArpMigrateCache(String vpnName, String ipToQuery) { if (migrateArpCache == null || migrateArpCache.size() == 0) { return false; }/* ww w .ja v a 2s . co m*/ Pair<String, String> keyPair = new ImmutablePair<>(vpnName, ipToQuery); BigInteger prevTimeStampCached = migrateArpCache.getIfPresent(keyPair); if (prevTimeStampCached == null) { LOG.debug("ARP_MIGRATE_CACHE: there is no IP {} vpnName {} in dirty cache, so learn it", ipToQuery, vpnName); return false; } if (System.currentTimeMillis() > prevTimeStampCached.longValue() + config.getArpLearnTimeout()) { LOG.debug("ARP_MIGRATE_CACHE: older than timeout value - remove from dirty cache IP {} vpnName {}", ipToQuery, vpnName); migrateArpCache.invalidate(keyPair); return false; } LOG.debug("ARP_MIGRATE_CACHE: younger than timeout value - ignore learning IP {} vpnName {}", ipToQuery, vpnName); return true; }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
/** * @param binBigInteger/*from w w w. ja v a 2s .c om*/ * @param value * @return 0 if equal , + value if greater than , - value if less than */ public static long compare(BigInteger binBigInteger, String value) { return binBigInteger.longValue() - Long.parseLong(value); }