List of usage examples for java.lang Double valueOf
@HotSpotIntrinsicCandidate public static Double valueOf(double d)
From source file:org.hawkular.alerts.api.model.condition.RateConditionEval.java
public RateConditionEval(RateCondition condition, Data data, Data previousData) { super(Type.RATE, condition.match(data.getTimestamp(), Double.valueOf(data.getValue()), previousData.getTimestamp(), Double.valueOf(previousData.getValue())), data.getTimestamp(), data.getContext());//from ww w.j av a2s . c om this.condition = condition; this.time = data.getTimestamp(); this.value = Double.valueOf(data.getValue()); this.previousTime = previousData.getTimestamp(); this.previousValue = Double.valueOf(previousData.getValue()); this.rate = condition.getRate(this.time, this.value, this.previousTime, this.previousValue); }
From source file:com.sarm.aussiepayslipgenerator.view.PaySlipControllerTest.java
/** * * The idea is only to test if the Request Handler completes the process and * returns the view. Test of calculatePay method, of class * PaySlipController.//w w w . j a va 2 s . com */ @Test public void testCalculatePay() { System.out.println("calculatePay"); EmployeeInfo employee = new EmployeeInfo(); employee.setAnnualSalary(75425); employee.setFirstName("Bracket3"); employee.setLastName("Emp3"); employee.setSuperRate(Double.valueOf("9")); employee.setStartDate(new DateTime(2013, 11, 23, 00, 00)); // ModelMap model = new ModelMap(); String expResult = "employeePaySlip"; String result = instance.calculatePay(employee, model); assertEquals(expResult, result); }
From source file:gov.nih.nci.queue.servlet.FileUploadServlet.java
/** * ************************************************* * URL: /upload doPost(): upload the files and other parameters * * @param request// w ww. j a va2s . c o m * @param response * @throws javax.servlet.ServletException * @throws java.io.IOException * ************************************************** */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Create an object for JSON response. ResponseModel rm = new ResponseModel(); // Set response type to json response.setContentType("application/json"); PrintWriter writer = response.getWriter(); // Get property values. // SOCcer related. final Double estimatedThreshhold = Double .valueOf(PropertiesUtil.getProperty("gov.nih.nci.soccer.computing.time.threshhold").trim()); // FileUpload Settings. final String repositoryPath = PropertiesUtil.getProperty("gov.nih.nci.queue.repository.dir"); final String strOutputDir = PropertiesUtil.getProperty("gov.nih.cit.soccer.output.dir").trim(); final long fileSizeMax = 10000000000L; // 10G LOGGER.log(Level.INFO, "repository.dir: {0}, filesize.max: {1}, time.threshhold: {2}", new Object[] { repositoryPath, fileSizeMax, estimatedThreshhold }); // Check that we have a file upload request // Check that we have a file upload request boolean isMultipart = ServletFileUpload.isMultipartContent(request); // Ensuring that the request is actually a file upload request. if (isMultipart) { // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); //upload file dirctory. If it does not exist, create one. File f = new File(repositoryPath); if (!f.exists()) { f.mkdir(); } // Set factory constraints // factory.setSizeThreshold(yourMaxMemorySize); // Configure a repository factory.setRepository(new File(repositoryPath)); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); upload.setFileSizeMax(fileSizeMax); try { // Parse the request List<FileItem> items = upload.parseRequest(request); // Process the uploaded items Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (!item.isFormField()) { // Handle file field. String fileName = item.getName(); rm.setFileName(fileName); String contentType = item.getContentType(); rm.setFileType(contentType); long sizeInBytes = item.getSize(); rm.setFileSize(String.valueOf(sizeInBytes)); String inputFileId = new UniqueIdUtil(fileName).getInputUniqueID(); rm.setInputFileId(inputFileId); String absoluteInputFileName = repositoryPath + File.separator + inputFileId; rm.setRepositoryPath(repositoryPath); // Write file to the destination folder. File inputFile = new File(absoluteInputFileName); item.write(inputFile); // Validation. InputFileValidator validator = new InputFileValidator(); List<String> validationErrors = validator.validateFile(inputFile); if (validationErrors == null) { // Pass validation // check estimatedProcessingTime. SoccerServiceHelper soccerHelper = new SoccerServiceHelper(strOutputDir); Double estimatedTime = soccerHelper.getEstimatedTime(absoluteInputFileName); rm.setEstimatedTime(String.valueOf(estimatedTime)); if (estimatedTime > estimatedThreshhold) { // STATUS: QUEUE (Ask client for email) // Construct Response String in JSON format. rm.setStatus("queue"); } else { // STATUS: PASS (Ask client to confirm calculate) // all good. Process the output and Go to result page directly. rm.setStatus("pass"); } } else { // STATUS: FAIL // Did not pass validation. // Construct Response String in JSON format. rm.setStatus("invalid"); rm.setDetails(validationErrors); } } else { // TODO: Handle Form Fields such as SOC_SYSTEM. } // End of isFormField } } catch (Exception e) { LOGGER.log(Level.SEVERE, "FileUploadException or FileNotFoundException. Error Message: {0}", new Object[] { e.getMessage() }); rm.setStatus("fail"); rm.setErrorMessage( "Oops! We met with problems when uploading your file. Error Message: " + e.getMessage()); } // Send the response. ObjectMapper jsonMapper = new ObjectMapper(); LOGGER.log(Level.INFO, "Response: {0}", new Object[] { jsonMapper.writeValueAsString(rm) }); // Generate metadata file new MetadataFileUtil(rm.getInputFileId(), repositoryPath) .generateMetadataFile(jsonMapper.writeValueAsString(rm)); // Responde to the client. writer.print(jsonMapper.writeValueAsString(rm)); } else { // The request is NOT actually a file upload request writer.print("You hit the wrong file upload page. The request is NOT actually a file upload request."); } }
From source file:com.itemanalysis.psychometrics.cfa.GeneralizedLeastSquares.java
public double agfi() { double gfi = gfi(); double q = Double.valueOf(model.getNumberOfItems()).doubleValue(); double p1 = (q * (q + 1)) / (2.0 * degreesOfFreedom()); double p2 = 1.0 - gfi; double fit = 1.0 - p1 * p2; return fit;/*from www .j a va2 s. c o m*/ }
From source file:com.supinfo.supfriends.ejb.controller.editProfileController.java
public String saveChanges() { getLoggedUser().setFirstName(firstname); getLoggedUser().setLastName(lastname); getLoggedUser().setEmail(email);/*from ww w .ja va2s. c o m*/ getLoggedUser().setLatitude(Double.valueOf(latitude)); getLoggedUser().setLongitude(Double.valueOf(longitude)); String passwordCrypted = DigestUtils.sha256Hex(password); getLoggedUser().setPassword(passwordCrypted); getLoggedUser().setPhoneNumber(phonenumber); getLoggedUser().setUserName(username); boolean isEdited = userFacade.edit(getLoggedUser()); FacesContext context = FacesContext.getCurrentInstance(); if (!isEdited) { FacesMessage message = new FacesMessage( "Un problme est survenu lors de la sauvegarde de votre profil."); context.addMessage(getMybutton().getClientId(context), message); return null; } FacesMessage message = new FacesMessage("Votre profil a t sauvegard."); context.addMessage(getMybutton().getClientId(context), message); return null; }
From source file:cn.org.citycloud.srdz.utils.StringUtils.java
/** * ?Double// w w w . j a va 2s . c o m */ public static Double toDouble(Object val) { if (val == null) { return 0D; } try { return Double.valueOf(trim(val.toString())); } catch (Exception e) { return 0D; } }
From source file:edu.stanford.mobisocial.dungbeetle.ui.adapter.ObjectListCursorAdapter.java
private static int getBestBatchSize() { Runtime runtime = Runtime.getRuntime(); if (runtime.availableProcessors() > 1) return 100; try {//from w ww. ja v a 2 s. c o m File max_cpu_freq = new File("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"); byte[] freq_bytes = IOUtils.toByteArray(new FileInputStream(max_cpu_freq)); String freq_string = new String(freq_bytes); double freq = Double.valueOf(freq_string); if (freq > 950000) { return 50; } } catch (IOException e) { e.printStackTrace(); } return 15; }
From source file:net.ceos.project.poi.annotated.bean.AutomaticPositionObjectBuilder.java
/** * Create a PerformanceObject for tests. * /* ww w . j a v a 2 s . c o m*/ * @return the {@link PerformanceObject} */ public static AutomaticPositionObject buildAutomaticPositionObject(int multiplier) { AutomaticPositionObject toValidate = new AutomaticPositionObject(); toValidate.setDateAttribute1(new Date()); toValidate.setDateAttribute2(new Date()); toValidate.setDateAttribute3(new Date()); toValidate.setStringAttribute1("some string"); toValidate.setStringAttribute2("some string"); toValidate.setStringAttribute3("some string"); toValidate.setStringAttribute4("some string"); toValidate.setStringAttribute5("some string"); toValidate.setStringAttribute6("some string"); toValidate.setStringAttribute7("some string"); toValidate.setStringAttribute8("some string"); toValidate.setStringAttribute9("some string"); toValidate.setStringAttribute10("some string"); toValidate.setStringAttribute11("some string"); toValidate.setStringAttribute12("some string"); toValidate.setIntegerAttribute1(6 * multiplier); toValidate.setIntegerAttribute2(11 * multiplier); toValidate.setIntegerAttribute3(33 * multiplier); toValidate.setIntegerAttribute4(46 * multiplier); toValidate.setIntegerAttribute5(2 * multiplier); toValidate.setIntegerAttribute6(7 * multiplier); toValidate.setIntegerAttribute7(9 * multiplier); toValidate.setDoubleAttribute1(Double.valueOf("11.3") * multiplier); toValidate.setDoubleAttribute2(Double.valueOf("237.131") * multiplier); toValidate.setDoubleAttribute3(Double.valueOf("25.777") * multiplier); toValidate.setLongAttribute(Long.valueOf("1234567890") * multiplier); toValidate.setBooleanAttribute1(Boolean.TRUE); toValidate.setBooleanAttribute2(Boolean.TRUE); toValidate.setBooleanAttribute3(Boolean.FALSE); toValidate.setBooleanAttribute4(Boolean.TRUE); /* create sub object Job */ Job job = new Job(); job.setJobCode(0005); job.setJobFamily("Family Job Name"); job.setJobName("Job Name"); toValidate.setJob(job); toValidate.setIntegerPrimitiveAttribute1(2 * multiplier); toValidate.setIntegerPrimitiveAttribute2(3 * multiplier); toValidate.setIntegerPrimitiveAttribute3(11 * multiplier); toValidate.setIntegerPrimitiveAttribute4(5 * multiplier); toValidate.setIntegerPrimitiveAttribute5(12 * multiplier); toValidate.setDoublePrimitiveAttribute(44.6 * multiplier); toValidate.setLongPrimitiveAttribute(987654321L * multiplier); toValidate.setBooleanPrimitiveAttribute(true); /* create sub object AddressInfo */ AddressInfo ai = new AddressInfo(); ai.setAddress("this is the street"); ai.setNumber(99); ai.setCity("this is the city"); ai.setCityCode(70065); ai.setCountry("This is a Country"); toValidate.setAddressInfo(ai); toValidate.setFloatAttribute(14.765f * multiplier); toValidate.setFloatPrimitiveAttribute(11.1125f * multiplier); toValidate.setUnitFamily(UnitFamily.COMPONENTS); toValidate.setBigDecimalAttribute(BigDecimal.valueOf(24.777).multiply(BigDecimal.valueOf(multiplier))); // TODO add new fields below return toValidate; }
From source file:de.boksa.jasper.rt.data.JRRTRESTInterfaceDataSource.java
private Object parseValue(Class<?> type, String value) { try {// w w w . jav a 2 s .c om if (Long.class.equals(type)) { return Long.valueOf(value); } else if (Double.class.equals(type)) { return Double.valueOf(value.replace(',', '.')); // TODO check if this can be handled using the user's locale } else if (BigDecimal.class.equals(type)) { return new BigDecimal(value.replace(',', '.')); // TODO check if this can be handled using the user's locale } else { return value; } } catch (Exception ex) { LOG.warn( String.format("Could not parse '%s' from value '%s', returning value.", type.getName(), value)); return value; } }
From source file:com.nubits.nubot.pricefeeds.CoinbasePriceFeed.java
@Override public LastPrice getLastPrice(CurrencyPair pair) { long now = System.currentTimeMillis(); long diff = now - lastRequest; if (diff >= refreshMinTime) { String url = getUrl(pair); String htmlString;//from w w w. j ava 2 s . com try { htmlString = Utils.getHTML(url, true); } catch (IOException ex) { LOG.severe(ex.toString()); return new LastPrice(true, name, pair.getOrderCurrency(), null); } JSONParser parser = new JSONParser(); try { JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString)); double last = Double.valueOf((String) httpAnswerJson.get("amount")); lastRequest = System.currentTimeMillis(); lastPrice = new LastPrice(false, name, pair.getOrderCurrency(), new Amount(last, pair.getPaymentCurrency())); return lastPrice; } catch (Exception ex) { LOG.severe(ex.toString()); lastRequest = System.currentTimeMillis(); return new LastPrice(true, name, pair.getOrderCurrency(), null); } } else { LOG.fine("Wait " + (refreshMinTime - (System.currentTimeMillis() - lastRequest)) + " ms " + "before making a new request. Now returning the last saved price\n\n"); return lastPrice; } }