List of usage examples for java.lang Long longValue
@HotSpotIntrinsicCandidate public long longValue()
From source file:net.librec.data.convertor.appender.SocialDataAppender.java
/** * Read data from the data file. Note that we didn't take care of the * duplicated lines./*from w w w .ja v a 2 s . co m*/ * * @param inputDataPath * the path of the data file * @throws IOException if I/O error occurs during reading */ private void readData(String inputDataPath) throws IOException { // Table {row-id, col-id, rate} Table<Integer, Integer, Double> dataTable = HashBasedTable.create(); // Map {col-id, multiple row-id}: used to fast build a rating matrix Multimap<Integer, Integer> colMap = HashMultimap.create(); // BiMap {raw id, inner id} userIds, itemIds final List<File> files = new ArrayList<File>(); final ArrayList<Long> fileSizeList = new ArrayList<Long>(); SimpleFileVisitor<Path> finder = new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { fileSizeList.add(file.toFile().length()); files.add(file.toFile()); return super.visitFile(file, attrs); } }; Files.walkFileTree(Paths.get(inputDataPath), finder); long allFileSize = 0; for (Long everyFileSize : fileSizeList) { allFileSize = allFileSize + everyFileSize.longValue(); } // loop every dataFile collecting from walkFileTree for (File dataFile : files) { FileInputStream fis = new FileInputStream(dataFile); FileChannel fileRead = fis.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(BSIZE); int len; String bufferLine = new String(); byte[] bytes = new byte[BSIZE]; while ((len = fileRead.read(buffer)) != -1) { buffer.flip(); buffer.get(bytes, 0, len); bufferLine = bufferLine.concat(new String(bytes, 0, len)).replaceAll("\r", "\n"); String[] bufferData = bufferLine.split("(\n)+"); boolean isComplete = bufferLine.endsWith("\n"); int loopLength = isComplete ? bufferData.length : bufferData.length - 1; for (int i = 0; i < loopLength; i++) { String line = new String(bufferData[i]); String[] data = line.trim().split("[ \t,]+"); String userA = data[0]; String userB = data[1]; Double rate = (data.length >= 3) ? Double.valueOf(data[2]) : 1.0; if (userIds.containsKey(userA) && userIds.containsKey(userB)) { int row = userIds.get(userA); int col = userIds.get(userB); dataTable.put(row, col, rate); colMap.put(col, row); } } if (!isComplete) { bufferLine = bufferData[bufferData.length - 1]; } buffer.clear(); } fileRead.close(); fis.close(); } int numRows = userIds.size(), numCols = userIds.size(); // build rating matrix userSocialMatrix = new SparseMatrix(numRows, numCols, dataTable, colMap); // release memory of data table dataTable = null; }
From source file:com.redhat.rhn.domain.kickstart.KickstartFactory.java
/** * Lookup a list of KickstartableTree objects that use the passed in channelId * * @param channelId that owns the kickstart trees * @param org who owns the trees/*from w ww .j ava 2 s . c o m*/ * @return List of KickstartableTree objects */ public static List<KickstartableTree> lookupKickstartTreesByChannelAndOrg(Long channelId, Org org) { Session session = null; List retval = null; String query = "KickstartableTree.findByChannelAndOrg"; session = HibernateFactory.getSession(); retval = session.getNamedQuery(query).setLong("channel_id", channelId.longValue()) .setLong("org_id", org.getId().longValue()) //Retrieve from cache if there .setCacheable(true).list(); return retval; }
From source file:biz.taoconsulting.dominodav.methods.GET.java
/** * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#action() *//*from www . j ava 2s . c o m*/ public void action() { InputStream stream = null; // The input stream coming from the resource OutputStream out = null; // The Servlet Response HttpServletResponse res = this.getResp(); try { // check if focused resource is a collection or a file resource... // collections are handled by propfind method // files / data will be send through the response stream writer... IDAVRepository rep = this.getRepository(); // Resource-Path is stripped by the repository name! // String curPath = (String) // this.getHeaderValues().get("resource-path"); // uri is the unique identifier on the host includes servlet and // repository but not server String curURI = (String) this.getHeaderValues().get("uri"); IDAVResource resource = rep.getResource(curURI); // Not ideal for browser access: we get the resource twice if (resource.isCollection()) { // LOGGER.info("Resource "+curURI +" is a collection"); PROPFIND p = new PROPFIND(); // Transfer the context if any p.setContext(this.getContext()); p.calledFromGET(); // LOGGER.info("After Called from GET"); p.process(this.getReq(), res, this.getRepository(), this.getLockManager()); // LOGGER.info("After Process "); } else { // LOGGER.info("Resource "+curURI +" is NOT a collection"); res.setHeader("Content-Type", resource.getMimeType()); res.setHeader("Pragma", "no-cache"); res.setHeader("Expires", "0"); res.setHeader("ETag", resource.getETag()); // TODO: Do we need content-disposition attachment or should it // be inline? res.setHeader("Content-disposition", "inline; filename*=" + ((IDAVAddressInformation) resource).getName()); // LOGGER.info("Set header finnish"); Long curLen = resource.getContentLength(); if (curLen != null && curLen.longValue() > 0) { // LOGGER.info("CurrLen is not null and positive="+ // curLen.toString()); res.setHeader("Content-Length", resource.getContentLength().toString()); } else { // LOGGER.info("CurrLen is null!!!"); } // Get the stream of the resource object and copy it into // the outputstream which is provided by the response object try { // LOGGER.info("Before resource getStream; class="+resource.getClass().toString()); stream = resource.getStream(); int read = 0; byte[] bytes = new byte[32768]; // ToDo is 32k a good // buffer? int totalread = 0; // TODO: Improve on this - is there a better way from input // to output stream? out = this.getOutputStream(); while ((read = stream.read(bytes)) != -1) { out.write(bytes, 0, read); totalread += read; } // Capture the result length // LOGGER.info("Before resource setContentLength"); res.setContentLength(totalread); // LOGGER.info("After resource setContentLength"); } catch (IOException iox) { this.setErrorMessage("Get method failed with:" + iox.getMessage(), HttpServletResponse.SC_INTERNAL_SERVER_ERROR); LOGGER.error(iox); } } } catch (Exception exc) { LOGGER.error("Get method failed with:" + exc.getMessage(), exc); this.setErrorMessage("Get method failed with:" + exc.getMessage(), HttpServletResponse.SC_NOT_FOUND); } finally { // Close of all resources try { if (out != null) { out.flush(); out.close(); } if (stream != null) { stream.close(); } } catch (Exception e) { LOGGER.error("GET Object cleanup failed:" + e.getMessage(), e); } } }
From source file:com.redhat.rhn.domain.kickstart.KickstartFactory.java
/** * Lookup a crypto key by its id.// w w w. ja v a 2 s .co m * @param keyId to lookup * @param org who owns the key * @return CryptoKey if found. Null if not */ public static CryptoKey lookupCryptoKeyById(Long keyId, Org org) { Session session = null; CryptoKey retval = null; //look for Kickstart data by id session = HibernateFactory.getSession(); retval = (CryptoKey) session.getNamedQuery("CryptoKey.findByIdAndOrg").setLong("key_id", keyId.longValue()) .setLong("org_id", org.getId().longValue()).uniqueResult(); return retval; }
From source file:egovframework.rte.fdl.idgnr.impl.EgovTableIdGnrService.java
/** * blockSize ID (long)//from w w w. j a v a 2 s .c om * * @param blockSize ? blockSize * @return ? ? ? * @throws FdlException ID?? ? */ protected long allocateLongIdBlock(int blockSize) throws FdlException { Long id = (Long) allocateIdBlock(blockSize, false); return id.longValue(); }
From source file:com.rcs.service.service.impl.MessageSourceLocalServiceImpl.java
public long getMessageSourcesKeyCount(String resourceKey, String resourceLocale, String resourceValue, String resourceBundle) throws SystemException { DynamicQuery query = DynamicQueryFactoryUtil.forClass(MessageSource.class); if (StringUtils.isNotBlank(resourceKey)) { query.add(RestrictionsFactoryUtil.ilike("primaryKey.key", "%" + resourceKey + "%")); }//from ww w .ja v a2 s . c o m if (StringUtils.isNotBlank(resourceLocale)) { query.add(PropertyFactoryUtil.forName("primaryKey.locale").eq(resourceLocale)); } if (StringUtils.isNotBlank(resourceValue)) { query.add(RestrictionsFactoryUtil.ilike("value", "%" + resourceValue + "%")); //forName("resourceValue").ilike("%" + resourceValue + "%")); } if (StringUtils.isNotBlank(resourceBundle) && !RcsConstants.ALL_BUNDLES.equals(resourceBundle)) { query.add(PropertyFactoryUtil.forName("bundle").eq(resourceBundle)); } query.setProjection(ProjectionFactoryUtil.countDistinct("primaryKey.key")); List result = MessageSourceLocalServiceUtil.dynamicQuery(query); Long count = (Long) result.get(0); return count.longValue(); }
From source file:com.technophobia.substeps.report.DetailedJsonBuilder.java
private String convert(Long runningDurationMillis) { return runningDurationMillis == null ? "No duration recorded" : convert(runningDurationMillis.longValue()); }
From source file:it.unitn.disi.smatch.webapi.server.utils.JsonUtils.java
/** * Creates a JSON response with the given body and optional request * processing time/*from w w w . j ava2 s . com*/ * * @param body The body * @param requestTime The request processing time, can be null * @return The JSON response * @throws JSONException */ public JSONObject createResponse(JSONObject body, Long requestTime) throws JSONException { body.put(JSONHelper.TAG_VERSION, version); body.put(JSONHelper.TAG_STATUS, Status.OK.name()); if (requestTime != null) { body.put(JSONHelper.TAG_TIME, System.currentTimeMillis() - requestTime.longValue()); } JSONObject resp = new JSONObject(); resp.put(JSONHelper.TAG_RESPONSE, body); return resp; }
From source file:com.roncoo.pay.controller.sett.SettController.java
@RequestMapping(value = "/ajaxSettList", method = { RequestMethod.POST, RequestMethod.GET }) @ResponseBody/*from w ww.ja v a 2 s . c o m*/ public String ajaxPaymentList(HttpServletRequest request, @RequestBody JSONParam[] params) throws IllegalAccessException, InvocationTargetException { // convertToMap?HashMap HashMap<String, String> paramMap = convertToMap(params); String sEcho = paramMap.get("sEcho"); int start = Integer.parseInt(paramMap.get("iDisplayStart")); int length = Integer.parseInt(paramMap.get("iDisplayLength")); String beginDate = paramMap.get("beginDate"); String endDate = paramMap.get("endDate"); if (StringUtil.isEmpty(beginDate) && !StringUtil.isEmpty(endDate)) { beginDate = endDate; } if (StringUtil.isEmpty(endDate) && !StringUtil.isEmpty(beginDate)) { endDate = beginDate; } String merchantRequestNo = paramMap.get("merchantRequestNo"); String status = paramMap.get("status"); RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER); // ???? PageParam pageParam = new PageParam(start / length + 1, length); Map<String, Object> settMap = new HashMap<String, Object>(); settMap.put("userNo", userInfo.getUserNo()); settMap.put("settStatus", status); settMap.put("merchantRequestNo", merchantRequestNo); settMap.put("beginDate", beginDate); settMap.put("endDate", endDate); PageBean pageBean = rpSettQueryService.querySettRecordListPage(pageParam, settMap); Long count = Long.valueOf(pageBean.getTotalCount() + ""); String jsonString = JSON.toJSONString(pageBean.getRecordList()); String json = "{\"sEcho\":" + sEcho + ",\"iTotalRecords\":" + count.longValue() + ",\"iTotalDisplayRecords\":" + count.longValue() + ",\"aaData\":" + jsonString + "}"; return json; }
From source file:JobBase.java
/** * Increment the given counter by the given incremental value If the counter * does not exist, one is created with value 0. * //from w ww. j av a2s . c om * @param name * the counter name * @param inc * the incremental value * @return the updated value. */ protected Long addLongValue(Object name, long inc) { Long val = this.longCounters.get(name); Long retv = null; if (val == null) { retv = new Long(inc); } else { retv = new Long(val.longValue() + inc); } this.longCounters.put(name, retv); return retv; }