List of usage examples for java.lang Double toString
public static String toString(double d)
From source file:info.magnolia.cms.util.NodeDataUtil.java
/** * <p/> Returns the representation of the value as a String: * </p>//from w w w . j a va 2s .c o m * @return String */ public String getValueString(String dateFormat) { try { NodeData nodeData = this.getNodeData(); switch (nodeData.getType()) { case (PropertyType.STRING): return nodeData.getString(); case (PropertyType.DOUBLE): return Double.toString(nodeData.getDouble()); case (PropertyType.LONG): return Long.toString(nodeData.getLong()); case (PropertyType.BOOLEAN): return Boolean.toString(nodeData.getBoolean()); case (PropertyType.DATE): Date valueDate = nodeData.getDate().getTime(); return new DateUtil().getFormattedDate(valueDate, dateFormat); case (PropertyType.BINARY): // ??? default: return StringUtils.EMPTY; } } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$ } return StringUtils.EMPTY; }
From source file:ee.ria.xroad.common.RequestTest.java
/** * Test to ensure bodymass index test request creation is correct. * @throws IOException if request template file could not be read */// w w w .j a v a 2 s . com @Test public void shouldCreateBodyMassIndexDoclitRequest() throws IOException { // Given ClientId client = ClientId.create("EE", "riigiasutus", "consumer", "subClient"); ServiceId service = ServiceId.create("EE", "riigiasutus", "producer", "subService", "bodyMassIndex", "v1"); String id = "1234567890"; List<RequestTag> content = Arrays.asList(new RequestTag("height", Integer.toString(180)), new RequestTag("weight", Double.toString(80.1))); String template = FileUtils .readFileToString(new File(TEMPLATES_DIR + File.separator + "xroadDoclitRequest.st")); Request request = new Request(template, client, service, id, content); // When String xmlFromRequest = request.toXml(); System.out.println("XML from request: " + xmlFromRequest); // Then String expectedRequest = FileUtils.readFileToString(new File("src/test/resources/xroadDoclit2.request")); assertEquals(expectedRequest, xmlFromRequest); }
From source file:com.cloudera.oryx.kmeans.serving.web.DistanceToNearestServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;/*w w w. j a va 2 s .c o m*/ } String line = pathInfo.subSequence(1, pathInfo.length()).toString(); Generation generation = getGenerationManager().getCurrentGeneration(); if (generation == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "API method unavailable until model has been built and loaded"); return; } String[] tokens = DelimitedDataUtils.decode(line); RealVector vector = generation.toVector(tokens); if (vector == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count"); return; } double distance = findClosest(generation, vector).getSquaredDistance(); response.getWriter().write(Double.toString(distance)); }
From source file:com.cloudera.oryx.ml.SimpleMLUpdateIT.java
@Test public void testMLUpdate() throws Exception { Path tempDir = getTempDir();/* ww w .ja v a 2 s . c o m*/ Path dataDir = tempDir.resolve("data"); Path modelDir = tempDir.resolve("model"); Map<String, String> overlayConfig = new HashMap<>(); overlayConfig.put("oryx.batch.update-class", MockMLUpdate.class.getName()); ConfigUtils.set(overlayConfig, "oryx.batch.storage.data-dir", dataDir); ConfigUtils.set(overlayConfig, "oryx.batch.storage.model-dir", modelDir); overlayConfig.put("oryx.batch.generation-interval-sec", Integer.toString(GEN_INTERVAL_SEC)); overlayConfig.put("oryx.batch.block-interval-sec", Integer.toString(BLOCK_INTERVAL_SEC)); overlayConfig.put("oryx.ml.eval.test-fraction", Double.toString(TEST_FRACTION)); Config config = ConfigUtils.overlayOn(overlayConfig, getConfig()); startMessaging(); List<Integer> trainCounts = new ArrayList<>(); List<Integer> testCounts = new ArrayList<>(); MockMLUpdate.setCountHolders(trainCounts, testCounts); startServerProduceConsumeTopics(config, DATA_TO_WRITE, WRITE_INTERVAL_MSEC); // If lists are unequal at this point, there must have been an empty test set // which yielded no call to evaluate(). Fill in the blank while (trainCounts.size() > testCounts.size()) { testCounts.add(0); } log.info("trainCounts = {}", trainCounts); log.info("testCounts = {}", testCounts); checkOutputData(dataDir, DATA_TO_WRITE); checkIntervals(trainCounts.size(), DATA_TO_WRITE, WRITE_INTERVAL_MSEC, GEN_INTERVAL_SEC); assertEquals(testCounts.size(), trainCounts.size()); RandomGenerator random = RandomManager.getRandom(); int lastTotalTrainCount = 0; int lastTestCount = 0; for (int i = 0; i < testCounts.size(); i++) { int totalTrainCount = trainCounts.get(i); int testCount = testCounts.get(i); int newTrainInGen = totalTrainCount - (lastTotalTrainCount + lastTestCount); if (newTrainInGen == 0) { continue; } lastTotalTrainCount = totalTrainCount; lastTestCount = testCount; int totalNew = testCount + newTrainInGen; IntegerDistribution dist = new BinomialDistribution(random, totalNew, TEST_FRACTION); double probability; if (testCount < dist.getNumericalMean()) { probability = dist.cumulativeProbability(testCount); } else { probability = 1.0 - dist.cumulativeProbability(testCount); } log.info("Probability of observing {} as {} sample of {}: {}", testCount, TEST_FRACTION, totalNew, probability); assertTrue(probability >= 0.001); } }
From source file:io.druid.query.aggregation.datasketches.tuple.GenerateTestData.java
private static void writeBucketTestRecord(BufferedWriter out, String label, int id, double parameter) throws Exception { out.write("20170101"); out.write("\t"); out.write(label);// w w w . j a v a 2s . c om out.write("\t"); out.write(Integer.toString(id)); out.write("\t"); out.write(Double.toString(parameter)); out.newLine(); }
From source file:org.csware.ee.utils.Tools.java
public static double add(double v1, double v2) { BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.add(b2).doubleValue(); }
From source file:ml.shifu.shifu.core.binning.EqualPopulationBinningTest.java
@Test public void tesGussiantBinning() { Random rd = new Random(System.currentTimeMillis()); EqualPopulationBinning binning = new EqualPopulationBinning(10); for (int i = 0; i < 10000; i++) { binning.addData(Double.toString(rd.nextGaussian() % 1000)); }/*from w ww. j a v a 2 s. c o m*/ System.out.println(binning.getDataBin()); }
From source file:com.cloudera.oryx.common.math.DoubleWeightedMean.java
@Override public String toString() { return Double.toString(mean); }
From source file:ar.com.zauber.garfio.modules.mantis.model.actions.NumberUpdateCustomFieldAction.java
/** @see UpdateCustomFieldAction#getValue(String) */ @Override//from ww w . j a v a2 s. c om public String getValue(String currentValue) { String ret; boolean isANumber = true; try { Double.parseDouble(currentValue); } catch (final Throwable e) { isANumber = false; } if (isANumber || StringUtils.isEmpty(currentValue)) { if (StringUtils.isEmpty(currentValue)) { currentValue = "0"; } final String value = super.getValue(currentValue); isANumber = true; try { Double.parseDouble(value); } catch (final Throwable e) { isANumber = false; } if (isANumber) { if (reDelta.matcher(value).matches()) { ret = Double.toString(Double.parseDouble(currentValue) + Double.parseDouble(value)); } else { ret = Double.toString(Double.parseDouble(value)); } } else { throw new IllegalArgumentException("`" + value + "' " + "should be a number."); } } else { ret = currentValue; } return ret; }
From source file:TemperatureConverterJFace.java
/** * Performs conversion when one of the text fields changes. * // w w w. java 2 s. co m * @param text * the event source */ public void valueChanged(Text text) { if (!text.isFocusControl()) return; if (text == fahrenheitValue) { try { double fValue = Double.parseDouble(text.getText()); double cValue = (fValue - 32) / 1.8; celsiusValue.setText(Double.toString(cValue)); System.out.println("F -> C: " + cValue); setStatus("Conversion performed successfully."); } catch (NumberFormatException e) { celsiusValue.setText(""); setStatus("Invalid number format: " + text.getText()); } } else { try { double cValue = Double.parseDouble(text.getText()); double fValue = cValue * 1.8 + 32; fahrenheitValue.setText(Double.toString(fValue)); System.out.println("C -> F: " + fValue); setStatus("Conversion performed successfully."); } catch (NumberFormatException e) { fahrenheitValue.setText(""); setStatus("Invalid number format: " + text.getText()); } } }