List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:com.gisgraphy.util.CurrencyConverter.java
/** * Convert a String to a Double and a Double to a String * /*from ww w. ja v a2 s . c om*/ * @param type * the class type to output * @param value * the object to convert * @return object the converted object (Double or String) */ @SuppressWarnings("unchecked") public final Object convert(final Class type, final Object value) { // for a null value, return null if (value == null) { return null; } else { if (value instanceof String) { if (log.isDebugEnabled()) { log.debug("value (" + value + ") instance of String"); } try { if (StringUtils.isBlank(String.valueOf(value))) { return null; } if (log.isDebugEnabled()) { log.debug("converting '" + value + "' to a decimal"); } // formatter.setDecimalSeparatorAlwaysShown(true); Number num = formatter.parse(String.valueOf(value)); return num.doubleValue(); } catch (ParseException pe) { } } else if (value instanceof Double) { if (log.isDebugEnabled()) { log.debug("value (" + value + ") instance of Double"); log.debug("returning double: " + formatter.format(value)); } return formatter.format(value); } } throw new ConversionException("Could not convert " + value + " to " + type.getName() + "!"); }
From source file:com.agloco.util.StringUtil.java
private static String format(Number n, String format) { if (n == null) return ""; NumberFormat f = new DecimalFormat(format); return f.format(n.doubleValue()); }
From source file:org.jfree.data.xy.AbstractXYDataset.java
/** * Returns the x-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value.//from www . j a v a 2s . co m */ public double getXValue(int series, int item) { double result = Double.NaN; Number x = getX(series, item); if (x != null) { result = x.doubleValue(); } return result; }
From source file:org.jfree.data.xy.AbstractXYDataset.java
/** * Returns the y-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value./*from w ww . j a v a 2 s .c o m*/ */ public double getYValue(int series, int item) { double result = Double.NaN; Number y = getY(series, item); if (y != null) { result = y.doubleValue(); } return result; }
From source file:net.sf.zekr.common.util.VelocityUtils.java
public Integer round(Object num) { Number n = toDouble(num); return new Integer((int) Math.rint(n.doubleValue())); }
From source file:edu.uci.ics.jung.io.TestGraphMLWriter.java
public void testMixedGraph() throws IOException, ParserConfigurationException, SAXException { Graph<String, Number> g = TestGraphs.getSmallGraph(); GraphMLWriter<String, Number> gmlw = new GraphMLWriter<String, Number>(); Transformer<Number, String> edge_weight = new Transformer<Number, String>() { public String transform(Number n) { return String.valueOf(n.doubleValue()); }// w w w . ja v a 2s. c om }; gmlw.addEdgeData("weight", "integer value for the edge", Integer.toString(-1), edge_weight); gmlw.setEdgeIDs(edge_weight); gmlw.save(g, new FileWriter("src/test/resources/testmixedgraph.graphml")); // TODO: now read it back in and compare the graph connectivity // and other metadata with what's in TestGraphs, etc. GraphMLReader<Graph<String, Object>, String, Object> gmlr = new GraphMLReader<Graph<String, Object>, String, Object>(); Graph<String, Object> g2 = new SparseMultigraph<String, Object>(); gmlr.load("src/test/resources/testmixedgraph.graphml", g2); Map<String, GraphMLMetadata<Object>> edge_metadata = gmlr.getEdgeMetadata(); Transformer<Object, String> edge_weight2 = edge_metadata.get("weight").transformer; validateTopology(g, g2, edge_weight, edge_weight2); // TODO: delete graph file when done File f = new File("src/test/resources/testmixedgraph.graphml"); f.delete(); }
From source file:com.att.aro.ui.view.overviewtab.PercentLabelGenerator.java
/** * Returns a percentage label string using the data in the specified row and * column of the dataset./* www . j a v a 2 s . com*/ * * @param dataset * The dataset containing the data for the chart. * * @param row * The row of data in the dataset. * * @param column * The column of data in the dataset. * * @return A string that is the percentage label. */ @Override public String generateLabel(CategoryDataset dataset, int row, int column) { Number value = dataset.getValue(row, column); String gLabel = ""; if (CommonHelper.isNotNull(value)) { gLabel = formatter.format(value.doubleValue()); } return gLabel; }
From source file:com.bstek.dorado.data.variant.DefaultVariantConvertor.java
public double toDouble(Object object) { Number n = (Number) doubleDateType.convertFromObject(object); return n.doubleValue(); }
From source file:com.espertech.esperio.representation.axiom.AxiomXPathPropertyGetter.java
public Object get(EventBean eventBean) throws PropertyAccessException { Object und = eventBean.getUnderlying(); if (und == null) { throw new PropertyAccessException( "Unexpected null underlying event encountered, expecting org.w3c.dom.Node instance as underlying"); }// w w w . j a v a2 s. c om if (!(und instanceof OMNode)) { throw new PropertyAccessException("Unexpected underlying event of type '" + und.getClass() + "' encountered, expecting org.w3c.dom.Node as underlying"); } try { // if there is no parser, return xpath expression type if (optionalCastToType == null) { if (resultType.equals(XPathConstants.BOOLEAN)) { return expression.booleanValueOf(und); } else if (resultType.equals(XPathConstants.NUMBER)) { Number n = expression.numberValueOf(und); return n.doubleValue(); } else { String result = expression.stringValueOf(und); return result; } } // obtain result as string and parse String result = expression.stringValueOf(und); if (result == null) { return null; } try { return simpleTypeParser.parse(result.toString()); } catch (RuntimeException ex) { log.warn("Error parsing XPath property named '" + property + "' expression result '" + result + " as type " + optionalCastToType.getName()); return null; } } catch (JaxenException e) { throw new PropertyAccessException("Error getting property '" + property + "' : " + e.getMessage(), e); } }
From source file:gobblin.util.limiter.stressTest.RateComputingLimiterContainer.java
private @Nullable DescriptiveStatistics getNormalizedStatistics(String key, Collection<? extends Number> values) { long now = System.currentTimeMillis(); long deltaTime = 0; if (this.lastReportTimes.containsKey(key)) { deltaTime = now - this.lastReportTimes.get(key); }/* w w w.j a v a 2s. co m*/ this.lastReportTimes.put(key, now); if (deltaTime == 0) { return null; } double[] normalizedValues = new double[values.size()]; int i = 0; for (Number value : values) { normalizedValues[i++] = 1000 * value.doubleValue() / deltaTime; } return new DescriptiveStatistics(normalizedValues); }