List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:com.erudika.para.i18n.OXRCurrencyConverter.java
@Override public Double convertCurrency(Number amount, String from, String to) { if (amount == null || StringUtils.isBlank(from) || StringUtils.isBlank(to)) { return 0.0; }//from w ww .java2 s . com Sysprop s = dao.read(FXRATES_KEY); if (s == null) { s = fetchFxRatesJSON(); } else if ((Utils.timestamp() - s.getTimestamp()) > REFRESH_AFTER) { // lazy refresh fx rates Para.asyncExecute(new Runnable() { public void run() { fetchFxRatesJSON(); } }); } double ratio = 1.0; if (s.hasProperty(from) && s.hasProperty(to)) { Double f = NumberUtils.toDouble(s.getProperty(from).toString(), 1.0); Double t = NumberUtils.toDouble(s.getProperty(to).toString(), 1.0); ratio = t / f; } return amount.doubleValue() * ratio; }
From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java
/** * Returns a shape used to represent a data item. * <p/>/*from w w w . ja va 2s . c om*/ * The default implementation passes control to the getSeriesShape method. * You can override this method if you require different behaviour. * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). * @return The shape (never <code>null</code>). */ @Override public Shape getItemShape(int row, int column) { Number x = dataset.getX(row, column); Number y = dataset.getY(row, column); Number z = dataset.getZ(row, column); if (x == null || y == null) { return new Ellipse2D.Double(0, 0, 0, 0); } if (z == null) { z = 1.0; } double dx = x.doubleValue(); double dy = y.doubleValue(); double dz = z.doubleValue(); return new Ellipse2D.Double(dx - dz / 2.0, dy - dz / 2.0, dz, dz); }
From source file:com.krawler.br.nodes.Activity.java
/** * converts the given object value to the given primitive type's wrapper class * if possible (if it is a <tt>Number</tt>) * * @param type the premitive type name, may be: * <ul>/*from ww w . j ava 2 s.c o m*/ * <li><tt>byte</tt> * <li><tt>char</tt> * <li><tt>short</tt> * <li><tt>int</tt> * <li><tt>long</tt> * <li><tt>float</tt> * <li><tt>double</tt> * </ul> * @param value the original value * @return the converted value */ private Object convert(String type, Object value) { Object val = value; if (value instanceof Number) { Number num = (Number) value; if (Byte.class.getCanonicalName().equals(type)) val = new Byte(num.byteValue()); else if (Character.class.getCanonicalName().equals(type)) val = new Character((char) num.intValue()); else if (Short.class.getCanonicalName().equals(type)) val = new Short(num.shortValue()); else if (Integer.class.getCanonicalName().equals(type)) val = new Integer(num.intValue()); else if (Long.class.getCanonicalName().equals(type)) val = new Long(num.longValue()); else if (Float.class.getCanonicalName().equals(type)) val = new Float(num.floatValue()); else if (Double.class.getCanonicalName().equals(type)) val = new Double(num.doubleValue()); } return val; }
From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java
private void processAreaAndLine(Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataSet, LineFillItemRendererState rendererState, int row, int column, double currentValue, double currentItemXPoint, double currentItemYPoint, int visibleRow) { int totalColumns = dataSet.getColumnCount(); int lastColumnIndex = totalColumns - 1; boolean isFirstItem = column == 0; boolean isLastItem = (column == lastColumnIndex); if (isFirstItem) { initializeRendererState(rendererState); }//from www.j a v a 2s. com int previousItemIndex = Math.max(column - 1, 0); Number previousItemValue = dataSet.getValue(row, previousItemIndex); int visibleSeriesCount = rendererState.getVisibleSeriesCount(); double previousItemXPoint = (previousItemValue != null) ? calculateItemXPoint(plot, dataSet, domainAxis, dataArea, previousItemIndex, visibleRow, visibleSeriesCount) : currentItemXPoint; double previousItemYPoint = (previousItemValue != null) ? calculateItemYPoint(plot, rangeAxis, dataArea, previousItemValue.doubleValue()) : currentItemYPoint; processCategoryArea(dataArea, plot, domainAxis, rangeAxis, dataSet, rendererState, row, column, currentValue, currentItemYPoint, totalColumns, isFirstItem, isLastItem); if (getItemLineVisible(row, column) && !isFirstItem) { addItemLine(plot, rendererState.getLines(), previousItemXPoint, previousItemYPoint, currentItemXPoint, currentItemYPoint); } }
From source file:org.jfree.data.contour.DefaultContourDataset.java
/** * Initialises the dataset.// www . j av a 2 s . co m * * @param xData the x values. * @param yData the y values. * @param zData the z values. */ public void initialize(Object[] xData, Object[] yData, Object[] zData) { this.xValues = new Double[xData.length]; this.yValues = new Double[yData.length]; this.zValues = new Double[zData.length]; // We organise the data with the following assumption: // 1) the data are sorted by x then y // 2) that the data will be represented by a rectangle formed by // using x[i+1], x, y[j+1], and y. // 3) we march along the y-axis at the same value of x until a new // value x is found at which point we will flag the index // where x[i+1]<>x[i] Vector tmpVector = new Vector(); //create a temporary vector double x = 1.123452e31; // set x to some arbitary value (used below) for (int k = 0; k < this.xValues.length; k++) { if (xData[k] != null) { Number xNumber; if (xData[k] instanceof Number) { xNumber = (Number) xData[k]; } else if (xData[k] instanceof Date) { this.dateAxis[0] = true; Date xDate = (Date) xData[k]; xNumber = new Long(xDate.getTime()); //store data as Long } else { xNumber = new Integer(0); } this.xValues[k] = new Double(xNumber.doubleValue()); // store Number as Double // check if starting new column if (x != this.xValues[k].doubleValue()) { tmpVector.add(new Integer(k)); //store index where new //column starts x = this.xValues[k].doubleValue(); // set x to most recent value } } } Object[] inttmp = tmpVector.toArray(); this.xIndex = new int[inttmp.length]; // create array xIndex to hold // new column indices for (int i = 0; i < inttmp.length; i++) { this.xIndex[i] = ((Integer) inttmp[i]).intValue(); } for (int k = 0; k < this.yValues.length; k++) { // store y and z axes // as Doubles this.yValues[k] = (Double) yData[k]; if (zData[k] != null) { this.zValues[k] = (Double) zData[k]; } } }
From source file:com.blacklocus.metrics.CloudWatchReporter.java
void reportGauge(Map.Entry<String, Gauge> gaugeEntry, String typeDimValue, List<MetricDatum> data) { Gauge gauge = gaugeEntry.getValue(); Object valueObj = gauge.getValue(); if (valueObj == null) { return;// www . ja va2 s .c o m } String valueStr = valueObj.toString(); if (NumberUtils.isNumber(valueStr)) { final Number value = NumberUtils.createNumber(valueStr); DemuxedKey key = new DemuxedKey(appendGlobalDimensions(gaugeEntry.getKey())); Iterables.addAll(data, key.newDatums(typeDimName, typeDimValue, new Function<MetricDatum, MetricDatum>() { @Override public MetricDatum apply(MetricDatum datum) { return datum.withValue(value.doubleValue()); } })); } }
From source file:IntRange.java
/** * <p>Tests whether the specified <code>Number</code> occurs within * this range using <code>double</code> comparison..</p> * //from w ww . j ava2s . co m * <p><code>null</code> is handled and returns <code>false</code>.</p> * * <p>This implementation forwards to the {@link #containsDouble(double)} method.</p> * * @param value the double to test, may be <code>null</code> * @return <code>true</code> if the specified number occurs within this * range by <code>double</code> comparison */ public boolean containsDouble(Number value) { if (value == null) { return false; } return containsDouble(value.doubleValue()); }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset.java
/** * Resets the cached bounds, by iterating over the entire dataset to find * the current bounds.//from ww w.j a v a2 s.c om */ private void updateBounds() { this.minimumRangeValue = Double.NaN; this.minimumRangeValueRow = -1; this.minimumRangeValueColumn = -1; this.maximumRangeValue = Double.NaN; this.maximumRangeValueRow = -1; this.maximumRangeValueColumn = -1; int rowCount = getRowCount(); int columnCount = getColumnCount(); for (int r = 0; r < rowCount; r++) { for (int c = 0; c < columnCount; c++) { BoxAndWhiskerItem item = getItem(r, c); if (item != null) { Number min = item.getMinOutlier(); if (min != null) { double minv = min.doubleValue(); if (!Double.isNaN(minv)) { if (minv < this.minimumRangeValue || Double.isNaN(this.minimumRangeValue)) { this.minimumRangeValue = minv; this.minimumRangeValueRow = r; this.minimumRangeValueColumn = c; } } } Number max = item.getMaxOutlier(); if (max != null) { double maxv = max.doubleValue(); if (!Double.isNaN(maxv)) { if (maxv > this.maximumRangeValue || Double.isNaN(this.maximumRangeValue)) { this.maximumRangeValue = maxv; this.maximumRangeValueRow = r; this.maximumRangeValueColumn = c; } } } } } } }
From source file:org.jfree.data.statistics.DefaultStatisticalCategoryDataset.java
/** * Adds a mean and standard deviation to the table. * * @param mean the mean.//from w ww. jav a2 s .c o m * @param standardDeviation the standard deviation. * @param rowKey the row key. * @param columnKey the column key. */ public void add(Number mean, Number standardDeviation, Comparable rowKey, Comparable columnKey) { MeanAndStandardDeviation item = new MeanAndStandardDeviation(mean, standardDeviation); this.data.addObject(item, rowKey, columnKey); double m = Double.NaN; double sd = Double.NaN; if (mean != null) { m = mean.doubleValue(); } if (standardDeviation != null) { sd = standardDeviation.doubleValue(); } // update cached range values int r = this.data.getColumnIndex(columnKey); int c = this.data.getRowIndex(rowKey); if ((r == this.maximumRangeValueRow && c == this.maximumRangeValueColumn) || (r == this.maximumRangeValueIncStdDevRow && c == this.maximumRangeValueIncStdDevColumn) || (r == this.minimumRangeValueRow && c == this.minimumRangeValueColumn) || (r == this.minimumRangeValueIncStdDevRow && c == this.minimumRangeValueIncStdDevColumn)) { // iterate over all data items and update mins and maxes updateBounds(); } else { if (!Double.isNaN(m)) { if (Double.isNaN(this.maximumRangeValue) || m > this.maximumRangeValue) { this.maximumRangeValue = m; this.maximumRangeValueRow = r; this.maximumRangeValueColumn = c; } } if (!Double.isNaN(m + sd)) { if (Double.isNaN(this.maximumRangeValueIncStdDev) || (m + sd) > this.maximumRangeValueIncStdDev) { this.maximumRangeValueIncStdDev = m + sd; this.maximumRangeValueIncStdDevRow = r; this.maximumRangeValueIncStdDevColumn = c; } } if (!Double.isNaN(m)) { if (Double.isNaN(this.minimumRangeValue) || m < this.minimumRangeValue) { this.minimumRangeValue = m; this.minimumRangeValueRow = r; this.minimumRangeValueColumn = c; } } if (!Double.isNaN(m - sd)) { if (Double.isNaN(this.minimumRangeValueIncStdDev) || (m - sd) < this.minimumRangeValueIncStdDev) { this.minimumRangeValueIncStdDev = m - sd; this.minimumRangeValueIncStdDevRow = r; this.minimumRangeValueIncStdDevColumn = c; } } } fireDatasetChanged(); }