List of usage examples for java.lang Double valueOf
@HotSpotIntrinsicCandidate public static Double valueOf(double d)
From source file:de.hybris.platform.b2b.punchout.populators.impl.DefaultOrderRequestCartPopulator.java
@Override public void populate(final OrderRequestHeader source, final CartModel target) throws ConversionException { if (!StringUtils.equalsIgnoreCase(source.getType(), "new")) { throw new UnsupportedOperationException("Operation not supported yet: " + source.getType()); }/*from w w w .j a v a 2s. c om*/ target.setPurchaseOrderNumber(source.getOrderID()); final AddressModel deliveryAddress = addressModelConverter.convert(source.getShipTo().getAddress()); deliveryAddress.setOwner(target); target.setDeliveryAddress(deliveryAddress); final AddressModel billToAddress = addressModelConverter.convert(source.getBillTo().getAddress()); billToAddress.setOwner(target); target.setPaymentAddress(billToAddress); target.setDeliveryCost(getDeliveryCost(source)); taxValuePopulator.populate(source.getTax(), target.getTotalTaxValues()); target.setTotalTax(sumUpAllTaxes(target.getTotalTaxValues())); target.setTotalPrice(Double.valueOf(source.getTotal().getMoney().getvalue())); target.setCurrency(commonI18NService.getCurrency(source.getTotal().getMoney().getCurrency())); try { target.setDate(cXmlDateUtil.parseString(source.getOrderDate())); } catch (final ParseException e) { throw new ConversionException("Could not parse date string: " + source.getOrderDate()); } }
From source file:com.schnobosoft.semeval.cortical.Util.java
/** * Read a file that contains one score per line, as a SemEval gold {@code .gs} file. Empty lines * are allowed and are read as missing values. * * @param scoresFile the scores file to read * @return a list of optional double values of the same length as the input file. For an empty * line, a {@link Optional#EMPTY} object is added to the output list. * @throws IOException/*from w w w . j a va 2 s. c o m*/ */ public static List<Optional> readScoresFile(File scoresFile) throws IOException { if (!scoresFile.getName().startsWith(GS_FILE_PREFIX)) { throw new IllegalArgumentException(scoresFile + " does not match expected pattern."); } LOG.info("Reading scores file " + scoresFile); return Files.lines(scoresFile.toPath()) .map(line -> line.isEmpty() ? Optional.empty() : Optional.of(Double.valueOf(line))) .collect(Collectors.toList()); }
From source file:de.hybris.platform.acceleratorservices.config.impl.AbstractConfigLookup.java
@Override public double getDouble(final String key, final double defaultValue) { final String property = getProperty(key); if (property != null && !property.isEmpty()) { try {//w ww .j a v a 2 s .c o m final Double doubleValue = Double.valueOf(property); if (doubleValue != null) { return doubleValue.doubleValue(); } } catch (final NumberFormatException ex) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to parse double property value for key [" + key + "] value was [" + property + "]", ex); } } } return defaultValue; }
From source file:DoubleDocument.java
/** * Strip all non digit characters. The first character must be '-' or '+'. * Only one '.' is allowed.//from w w w . jav a 2s.c om */ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (str == null) { return; } // Get current value String curVal = getText(0, getLength()); boolean hasDot = curVal.indexOf('.') != -1; // Strip non digit characters char[] buffer = str.toCharArray(); char[] digit = new char[buffer.length]; int j = 0; if (offs == 0 && buffer != null && buffer.length > 0 && buffer[0] == '-') digit[j++] = buffer[0]; for (int i = 0; i < buffer.length; i++) { if (Character.isDigit(buffer[i])) digit[j++] = buffer[i]; if (!hasDot && buffer[i] == '.') { digit[j++] = '.'; hasDot = true; } } // Now, test that new value is within range. String added = new String(digit, 0, j); try { StringBuffer val = new StringBuffer(curVal); val.insert(offs, added); String valStr = val.toString(); if (valStr.equals(".") || valStr.equals("-") || valStr.equals("-.")) super.insertString(offs, added, a); else { Double.valueOf(valStr); super.insertString(offs, added, a); } } catch (NumberFormatException e) { // Ignore insertion, as it results in an out of range value } }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValuePrioritizer.java
public void setAssignmentBoundaries(String assignmentBoundaries) { String[] bounds_as_strarr = assignmentBoundaries.split(","); double[] bounds = new double[bounds_as_strarr.length + 1]; // first value is a dummy value, never used for (int i = 0; i < bounds_as_strarr.length; i++) bounds[i + 1] = Double.valueOf(bounds_as_strarr[i]); kp.put("assignmentBoundaries", assignmentBoundaries); kp.put("assignmentBoundaries_doubles", bounds); }
From source file:com.act.lcms.MassCalculator2Test.java
@Test public void testMC2MatchesMC1WithinMeaningfulTolerance() throws Exception { List<Map<String, String>> rows; try (InputStream is = MassCalculator2Test.class.getResourceAsStream(TEST_CASE_RESOURCE)) { TSVParser parser = new TSVParser(); parser.parse(is);/* w w w.j a v a2 s . c o m*/ rows = parser.getResults(); } int testCase = 1; for (Map<String, String> row : rows) { String inchi = row.get("InChI"); Double expectedMass = Double.valueOf(row.get("Mass")); Integer expectedCharge = Integer.valueOf(row.get("Charge")); Pair<Double, Integer> actualMassAndCharge = MassCalculator2.calculateMassAndCharge(inchi); Double threshold = ACCEPTABLE_MASS_DELTA_THRESHOLD; if (actualMassAndCharge.getRight() < 0) { // Widen the window for added electrons' masses included in Chemaxon's calculations for negative ions. threshold += ACCEPTABLE_MASS_DELTA_THRESHOLD * -1.0 * actualMassAndCharge.getRight().doubleValue(); } else if (actualMassAndCharge.getRight() > 0) { // Positively charged molecules have the missing electrons' masses subtracted threshold += ACCEPTABLE_MASS_DELTA_THRESHOLD * actualMassAndCharge.getRight().doubleValue(); } assertEquals( String.format("Case %d: mass for %s is within delta threshold: %.6f vs. %.6f", testCase, inchi, expectedMass, actualMassAndCharge.getLeft()), expectedMass, actualMassAndCharge.getLeft(), threshold); assertEquals(String.format("Case %d: charge %s matches expected", testCase, inchi), expectedCharge, actualMassAndCharge.getRight()); testCase++; } }
From source file:com.crossover.trial.weather.metrics.impl.DropwizardMetricsService.java
@Override public void markRequest(IATA iata, double radius) { Assert.isTrue(iata != null, "iata is required"); Lock read = registryLock.readLock(); read.lock();/*from w ww .j ava 2 s. c om*/ try { registry.meter(iata.getCode()).mark(); registry.histogram("radius").update(Double.valueOf(radius).intValue() / 10); } finally { read.unlock(); } }
From source file:it.osm.gtfs.input.OSMParser.java
public static List<Stop> readOSMStops(String fileName) throws ParserConfigurationException, SAXException, IOException { List<Stop> result = new ArrayList<Stop>(); Multimap<String, Stop> refBuses = HashMultimap.create(); Multimap<String, Stop> refRails = HashMultimap.create(); File file = new File(fileName); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); NodeList nodeLst = doc.getElementsByTagName("node"); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); Stop st = new Stop(null, null, Double.valueOf(fstNode.getAttributes().getNamedItem("lat").getNodeValue()), Double.valueOf(fstNode.getAttributes().getNamedItem("lon").getNodeValue()), null); st.originalXMLNode = fstNode;/*from www . j a v a 2 s . c om*/ NodeList att = fstNode.getChildNodes(); for (int t = 0; t < att.getLength(); t++) { Node attNode = att.item(t); if (attNode.getAttributes() != null) { if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("ref")) st.setCode(attNode.getAttributes().getNamedItem("v").getNodeValue()); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("name")) st.setName(attNode.getAttributes().getNamedItem("v").getNodeValue()); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("gtfs_id")) st.setGtfsId(attNode.getAttributes().getNamedItem("v").getNodeValue()); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("highway") && attNode.getAttributes().getNamedItem("v").getNodeValue().equals("bus_stop")) st.setIsRailway(false); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("railway") && attNode.getAttributes().getNamedItem("v").getNodeValue().equals("tram_stop")) st.setIsRailway(true); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("railway") && attNode.getAttributes().getNamedItem("v").getNodeValue().equals("station")) st.setIsRailway(true); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("public_transport") && attNode.getAttributes().getNamedItem("v").getNodeValue().equals("stop_position") && st.isRailway() == null) st.setIsStopPosition(true); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("train") && attNode.getAttributes().getNamedItem("v").getNodeValue().equals("yes")) st.setIsRailway(true); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("tram") && attNode.getAttributes().getNamedItem("v").getNodeValue().equals("yes")) st.setIsRailway(true); if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals("bus") && attNode.getAttributes().getNamedItem("v").getNodeValue().equals("yes")) st.setIsRailway(false); } } if (st.isRailway() == null) if (st.isStopPosition()) continue; //ignore unsupported stop positions (like ferries) else throw new IllegalArgumentException("Unknow node type for node: " + st.getOSMId() + ". We support only highway=bus_stop, public_transport=stop_position, railway=tram_stop and railway=station"); //Check duplicate ref in osm if (st.getCode() != null) { if (st.isStopPosition() == null || st.isStopPosition() == false) { if (st.isRailway()) { if (refRails.containsKey(st.getCode())) { for (Stop existingStop : refRails.get(st.getCode())) { if (OSMDistanceUtils.distVincenty(st.getLat(), st.getLon(), existingStop.getLat(), existingStop.getLon()) < 500) System.err.println("Warning: The ref " + st.getCode() + " is used in more than one node within 500m this may lead to bad import." + " (nodes ids:" + st.getOSMId() + "," + existingStop.getOSMId() + ")"); } } refRails.put(st.getCode(), st); } else { if (refBuses.containsKey(st.getCode())) { for (Stop existingStop : refBuses.get(st.getCode())) { if (OSMDistanceUtils.distVincenty(st.getLat(), st.getLon(), existingStop.getLat(), existingStop.getLon()) < 500) System.err.println("Warning: The ref " + st.getCode() + " is used in more than one node within 500m this may lead to bad import." + " (nodes ids:" + st.getOSMId() + "," + existingStop.getOSMId() + ")"); } } refBuses.put(st.getCode(), st); } } } result.add(st); } return result; }
From source file:io.github.brinman2002.pipeline.NaiveBayesianClassifierTest.java
@Test public void train() { final PTable<Long, Attribute> attributes = MemPipeline.typedTableOf(TABLE_OF_ATTRIBUTES, attributes()); final PTable<Long, Outcome> outcomes = MemPipeline.typedTableOf(TABLE_OF_OUTCOMES, outcomes()); final Pair<PTable<Attribute, Pair<Outcome, Double>>, PTable<Outcome, Double>> trained = NaiveBayesianClassifier .train(attributes, outcomes); System.out.println(trained.first()); // System.out.println(trained.second()); // TODO assert expected values final Collection<Pair<Outcome, Double>> outcomeProbabilities = trained.second().asCollection().getValue(); assertEquals(4, outcomeProbabilities.size()); assertTrue(outcomeProbabilities.contains(Pair.of(outcome("a"), Double.valueOf(0.5)))); assertTrue(outcomeProbabilities.contains(Pair.of(outcome("b"), Double.valueOf(0.25)))); assertTrue(outcomeProbabilities.contains(Pair.of(outcome("c"), Double.valueOf(0.125)))); assertTrue(outcomeProbabilities.contains(Pair.of(outcome("d"), Double.valueOf(0.125)))); }
From source file:com.safetys.framework.jmesa.view.excel.ExcelView.java
public Object render() { HSSFWorkbook workbook = new HSSFWorkbook(); Table table = this.getTable(); String caption = table.getCaption(); if (StringUtils.isEmpty(caption)) { caption = "JMesa Export"; }/* w ww. ja v a 2 s . c om*/ HSSFSheet sheet = workbook.createSheet(caption); Row row = table.getRow(); row.getRowRenderer(); List<Column> columns = table.getRow().getColumns(); // renderer header HSSFRow hssfRow = sheet.createRow(0); int columncount = 0; for (Column col : columns) { HSSFCell cell = hssfRow.createCell((short) columncount++); cell.setCellValue(new HSSFRichTextString(col.getTitle())); } // renderer body Collection<?> items = getCoreContext().getPageItems(); int rowcount = 1; for (Object item : items) { HSSFRow r = sheet.createRow(rowcount++); columncount = 0; for (Column col : columns) { HSSFCell cell = r.createCell((short) columncount++); Object value = col.getCellRenderer().render(item, rowcount); if (value == null) { value = ""; } if (value instanceof Number) { Double number = Double.valueOf(value.toString()); cell.setCellValue(number); } else { cell.setCellValue(new HSSFRichTextString(value.toString())); } } } return workbook; }