List of usage examples for java.lang Long longValue
@HotSpotIntrinsicCandidate public long longValue()
From source file:com.xie.javacase.json.JSONObject.java
/** * Try to convert a string into a number, boolean, or null. If the string * can't be converted, return the string. * @param s A String.//from www .ja v a2s . com * @return A simple JSON value. */ static public Object stringToValue(String s) { if (s.equals("")) { return s; } if (s.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (s.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (s.equalsIgnoreCase("null")) { return JSONObject.NULL; } /* * If it might be a number, try converting it. We support the 0- and 0x- * conventions. If a number cannot be produced, then the value will just * be a string. Note that the 0-, 0x-, plus, and implied string * conventions are non-standard. A JSON parser is free to accept * non-JSON forms as long as it accepts all correct JSON forms. */ char b = s.charAt(0); if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { if (b == '0') { if (s.length() > 2 && (s.charAt(1) == 'x' || s.charAt(1) == 'X')) { try { return new Integer(Integer.parseInt(s.substring(2), 16)); } catch (Exception e) { /* Ignore the error */ } } else { try { return new Integer(Integer.parseInt(s, 8)); } catch (Exception e) { /* Ignore the error */ } } } try { if (s.indexOf('.') > -1 || s.indexOf('e') > -1 || s.indexOf('E') > -1) { return Double.valueOf(s); } else { Long myLong = new Long(s); if (myLong.longValue() == myLong.intValue()) { return new Integer(myLong.intValue()); } else { return myLong; } } } catch (Exception f) { /* Ignore the error */ } } return s; }
From source file:com.redhat.rhn.manager.rhnpackage.PackageManager.java
/** * Get the ID of the package that needs updating based on the name. * * So, if say the server has up2date version 2.8.0 and * the latest rev of up2date is 3.1.1 this will return the * ID of the package for 3.1.1// www .ja v a 2 s . co m * * @param sid of system * @param packageName of system - up2date for example * @return Long id of package if found. null if not. */ public static Long getServerNeededUpdatePackageByName(Long sid, String packageName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("sid", sid); params.put("name", packageName); SelectMode m = ModeFactory.getMode("Package_queries", "server_packages_needing_update"); DataResult dr = m.execute(params); if (dr.size() > 0) { Long id = (Long) ((Map) dr.get(0)).get("id"); return new Long(id.longValue()); } return null; }
From source file:es.udc.gii.common.eaf.stoptest.BitwiseConvergence.java
/** * Calculates the convergence rate between two individuals. *//*ww w. j a va 2s . c o m*/ private double convergence(Individual i1, Individual i2) { double convergence = 0.0; /* Asume both individuals have the same number of genes !! */ int genes = i1.getChromosomeAt(0).length; /* For each pair of genes */ for (int i = 0; i < genes; i++) { /* Get the value of the genes. Note that only individuals which have * a double as an internal value are considered. */ double d1 = i1.getChromosomeAt(0)[i]; double d2 = i2.getChromosomeAt(0)[i]; /* Get the binary codification of the values. */ Long lg1 = new Long(Double.doubleToRawLongBits(d1)); Long lg2 = new Long(Double.doubleToRawLongBits(d2)); /* Perform a bitwise XOR operation. Bitpositions that are identical * will yield a 0 and bitpositions which differ will yield a 1. So * we are counting the bits in which the two individuals *differ* */ Long lg = new Long(lg1.longValue() ^ lg2.longValue()); /* Count the number of bits in which the two individuals differ. */ convergence += Long.bitCount(lg); } /* Get the average bitwise difference. */ convergence /= Long.SIZE * genes; /* Get the average convergence. */ convergence = 1 - convergence; return convergence; }
From source file:be.solidx.hot.test.TestScriptExecutors.java
@Test public void testJSExecutorSequential2() throws Exception { final ScriptExecutor<org.mozilla.javascript.Script> scriptExecutor = jsScriptExecutor; double sum = 0; for (int i = 0; i < 1000; i++) { Integer j = 1000;//from www . j ava 2 s. c om Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("i", j); parameters.put("tname", Thread.currentThread().getName()); parameters.put("result", new Integer(0)); try { Script<org.mozilla.javascript.Script> script = new Script<org.mozilla.javascript.Script>( IOUtils.toByteArray(getClass().getResourceAsStream("/js-script2.js")), "test_" + Thread.currentThread().getName()); long starting = System.currentTimeMillis(); Double resDouble = (Double) scriptExecutor.execute(script, parameters); Long res = Math.round(resDouble); long end = System.currentTimeMillis() - starting; Assert.assertEquals(1000, res.longValue()); sum += end; } catch (ScriptException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println(sum / 1000.); }
From source file:net.librec.data.convertor.TextDataConvertor.java
/** * Read data from the data file. Note that we didn't take care of the * duplicated lines.//from w w w .ja v a2s. com * * @param dataColumnFormat * the format of input data file * @param inputDataPath * the path of input data file * @param binThold * the threshold to binarize a rating. If a rating is greater * than the threshold, the value will be 1; otherwise 0. To * disable this appender, i.e., keep the original rating value, * set the threshold a negative value * @throws IOException * if the <code>inputDataPath</code> is not valid. */ private void readData(String dataColumnFormat, String inputDataPath, double binThold) throws IOException { LOG.info(String.format("Dataset: %s", StringUtil.last(inputDataPath, 38))); // Table {row-id, col-id, rate} Table<Integer, Integer, Double> dataTable = HashBasedTable.create(); // Table {row-id, col-id, timestamp} Table<Integer, Integer, Long> timeTable = null; // 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 if (this.userIds == null) { this.userIds = HashBiMap.create(); } if (this.itemIds == null) { this.itemIds = HashBiMap.create(); } 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); LOG.info("All dataset files " + files.toString()); long allFileSize = 0; for (Long everyFileSize : fileSizeList) { allFileSize = allFileSize + everyFileSize.longValue(); } LOG.info("All dataset files size " + Long.toString(allFileSize)); int readingFileCount = 0; long loadAllFileByte = 0; // loop every dataFile collecting from walkFileTree for (File dataFile : files) { LOG.info("Now loading dataset file " + dataFile.toString().substring( dataFile.toString().lastIndexOf(File.separator) + 1, dataFile.toString().lastIndexOf("."))); readingFileCount += 1; loadFilePathRate = readingFileCount / (float) files.size(); long readingOneFileByte = 0; 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) { readingOneFileByte += len; loadDataFileRate = readingOneFileByte / (float) fileRead.size(); loadAllFileByte += len; loadAllFileRate = loadAllFileByte / (float) allFileSize; buffer.flip(); buffer.get(bytes, 0, len); bufferLine = bufferLine.concat(new String(bytes, 0, len)); bufferLine = bufferLine.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 user = data[0]; String item = data[1]; Double rate = ((dataColumnFormat.equals("UIR") || dataColumnFormat.equals("UIRT")) && data.length >= 3) ? Double.valueOf(data[2]) : 1.0; // binarize the rating for item recommendation task if (binThold >= 0) { rate = rate > binThold ? 1.0 : 0.0; } // inner id starting from 0 int row = userIds.containsKey(user) ? userIds.get(user) : userIds.size(); userIds.put(user, row); int col = itemIds.containsKey(item) ? itemIds.get(item) : itemIds.size(); itemIds.put(item, col); dataTable.put(row, col, rate); colMap.put(col, row); // record rating's issuing time if (StringUtils.equals(dataColumnFormat, "UIRT") && data.length >= 4) { if (timeTable == null) { timeTable = HashBasedTable.create(); } // convert to million-seconds long mms = 0L; try { mms = Long.parseLong(data[3]); // cannot format // 9.7323480e+008 } catch (NumberFormatException e) { mms = (long) Double.parseDouble(data[3]); } long timestamp = timeUnit.toMillis(mms); timeTable.put(row, col, timestamp); } } if (!isComplete) { bufferLine = bufferData[bufferData.length - 1]; } buffer.clear(); } fileRead.close(); fis.close(); } int numRows = numUsers(), numCols = numItems(); // build rating matrix preferenceMatrix = new SparseMatrix(numRows, numCols, dataTable, colMap); if (timeTable != null) datetimeMatrix = new SparseMatrix(numRows, numCols, timeTable, colMap); // release memory of data table dataTable = null; timeTable = null; }
From source file:eu.planets_project.tb.impl.model.exec.ServiceRecordImpl.java
/** * @return//w w w . j ava2s .co m */ public List<Experiment> getExperiments() { ExperimentPersistencyRemote ep = ExperimentPersistencyImpl.getInstance(); List<Experiment> exps = new Vector<Experiment>(); for (Long eid : this.getExperimentIds()) { Experiment exp = ep.findExperiment(eid.longValue()); if (exp != null) exps.add(exp); } return exps; }
From source file:gov.utah.dts.det.ccl.actions.facility.UserSearchAction.java
public void setRId(Long rId) { if (rId != null && rId.longValue() == -1l) { this.rId = null; } else {//from w ww. j av a2 s . c om this.rId = rId; } }
From source file:gov.utah.dts.det.ccl.actions.facility.UserSearchAction.java
public void setLsId(Long lsId) { if (lsId != null && lsId.longValue() == -1l) { this.lsId = null; } else {/*ww w. j a v a 2 s .c o m*/ this.lsId = lsId; } }
From source file:eu.optimis.ecoefficiencytool.core.ProactiveInfrastructure.java
public ProactiveInfrastructure(EcoEffAssessorIP assessor, EcoEffForecasterIP forecaster, Long timeout) { PropertiesConfiguration configOptimis = ConfigManager .getPropertiesConfiguration(ConfigManager.OPTIMIS_CONFIG_FILE); PropertiesConfiguration configEco = ConfigManager.getPropertiesConfiguration(ConfigManager.ECO_CONFIG_FILE); this.assessor = assessor; this.forecaster = forecaster; if (timeout != null) { this.timeout = timeout.longValue(); } else {/*from www . j av a 2s. c o m*/ this.timeout = configEco.getLong("samplingPeriod"); } co = new CloudOptimizerRESTClient(configOptimis.getString("optimis-ipvm")); //Set Proactive Thresholds hm = new HolisticManagementRESTClient(configOptimis.getString("optimis-ipvm")); ipEnEffTH = null; ipEcoEffTH = null; nodeEnEffTH = new HashMap<String, Double>(); nodeEcoEffTH = new HashMap<String, Double>(); }
From source file:hu.netmind.beankeeper.modification.impl.ModificationTrackerImpl.java
/** * Returns whether the given class changed since the given serial. A class changed, * if any objects of the given class were changed. *//*ww w .j a va2s . c om*/ public boolean isCurrent(Class cl, Long serial) { logger.debug("making sure class " + cl + " is current at: " + serial); if (serial == null) return true; // No serial given, this is always current // Make it a server call if (nodeManager.getRole() == NodeManager.NodeRole.CLIENT) { return (Boolean) nodeManager.callServer(ClassTracker.class.getName(), "isCurrent", new Class[] { Class.class, long.class }, new Object[] { cl, serial }); } // Local synchronized (operationTracker.getMutex()) { // We must check each modification // which concerns this class, whether they are newer than the given serial. Set entries = (Set) entriesByClass.get(cl); if (entries != null) { // If the entries are not null, then check whether there was a valid // modification. Iterator entriesIterator = entries.iterator(); while (entriesIterator.hasNext()) { ModificationEntry entry = (ModificationEntry) entriesIterator.next(); if (hasChanged(entry.id, entry.objectClass, serial)) { logger.debug("meta is a class, and there was an object of this class newer."); return false; // Change of object is newer, so class changed } } } // There were no modifications registered by object changes, but // the class still could have changed before, so check change date. Long lastTableSerial = (Long) lastSerialsByClass.get(cl); if ((lastTableSerial == null) || (lastTableSerial.longValue() < serial)) { logger.debug("class modification table says class is current."); return true; } // Fallback (not current). logger.debug("all checks failed, object is not current"); return false; } }