List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:org.jfree.data.WaferMapDataset.java
/** * Creates a new dataset.// w ww . j a v a 2 s .co m * * @param maxChipX * the wafer x-dimension. * @param maxChipY * the wafer y-dimension. * @param chipSpace * the space between chips. */ public WaferMapDataset(final int maxChipX, final int maxChipY, final Number chipSpace) { this.maxValue = new Double(Double.NEGATIVE_INFINITY); this.minValue = new Double(Double.POSITIVE_INFINITY); this.data = new DefaultKeyedValues2D(); this.maxChipX = maxChipX; this.maxChipY = maxChipY; if (chipSpace == null) { this.chipSpace = DEFAULT_CHIP_SPACE; } else { this.chipSpace = chipSpace.doubleValue(); } }
From source file:org.jfree.experimental.chart.plot.dial.DialPlot.java
/** * Returns the value from the specified dataset. * /*from ww w. j av a 2s.c o m*/ * @param datasetIndex the dataset index. * * @return The data value. */ public double getValue(int datasetIndex) { double result = Double.NaN; ValueDataset dataset = getDataset(datasetIndex); if (dataset != null) { Number n = dataset.getValue(); if (n != null) { result = n.doubleValue(); } } return result; }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert/* www .ja va 2 s. c o m*/ * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class<?> targetClass) throws IllegalArgumentException { // Assert.notNull(number, "Number must not be null"); // Assert.notNull(targetClass, "Target class must not be null"); if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java
private void drawOutliers(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, ValueAxis rangeAxis, int row, int column, BoxAndWhiskerCategoryDataset bawDataset, double xx, double aRadius, RectangleEdge location, double maxAxisValue, double minAxisValue) { double yyOutlier; double oRadius = state.getBarWidth() / this.outlierRadiusDenominator; // outlier radius List<Outlier> outliers = new ArrayList<Outlier>(); OutlierListCollection outlierListCollection = new OutlierListCollection(); List<Number> yOutliers = (List<Number>) bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { double outlier = yOutliers.get(i).doubleValue(); Number minOutlier = bawDataset.getMinOutlier(row, column); Number maxOutlier = bawDataset.getMaxOutlier(row, column); Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); if (outlier > maxOutlier.doubleValue()) { outlierListCollection.setHighFarOut(true); } else if (outlier < minOutlier.doubleValue()) { outlierListCollection.setLowFarOut(true); } else if (outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } else if (outlier < minRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); }/*w w w. j a v a 2s . c o m*/ Collections.sort(outliers); } if (!displayAllOutliers) { for (int i = 0; i < yOutliers.size(); i++) { Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); double outlier = ((Number) yOutliers.get(i)).doubleValue(); if (outlier < minRegular.doubleValue() || outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } } for (Iterator<Outlier> iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = iterator.next(); outlierListCollection.add(outlier); } for (Iterator<OutlierList> iterator = outlierListCollection.iterator(); iterator.hasNext();) { OutlierList list = iterator.next(); Outlier outlier = list.getAveragedOutlier(); Point2D point = outlier.getPoint(); if (list.isMultiple()) { drawMultipleEllipse(point, state.getBarWidth(), oRadius, g2); } else { drawEllipse(point, oRadius, g2); } } if (outlierListCollection.isHighFarOut()) { drawHighFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, maxAxisValue); } if (outlierListCollection.isLowFarOut()) { drawLowFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, minAxisValue); } } else { drawCoinOutliers(g2, state, dataArea, rangeAxis, row, column, bawDataset, xx, location, oRadius, outliers, yOutliers); } } }
From source file:dk.statsbiblioteket.netark.dvenabler.wrapper.NumericDocValuesWrapper.java
@Override public long get(int docID) { tracker.ping(docID);//from ww w. ja v a2 s.c o m try { IndexableField iField = reader.document(docID, FIELDS).getField(dvConfig.getName()); if (iField == null) { log.warn("No stored value for field '" + dvConfig.getName() + "' in doc " + docID + ". Returning -1"); // This should have been handled by {@link DVAtomicReader#getDocsWithField} return -1; } Number number = iField.numericValue(); if (number == null) { throw new RuntimeException("No numeric value '" + iField.stringValue() + "' for field '" + dvConfig.getName() + "' in doc " + docID + ". This looks like a non-numeric field!"); } // TODO: Determine correct method to call from field info switch (dvConfig.getNumericType()) { case LONG: return number.longValue(); case INT: return number.intValue(); case DOUBLE: return Double.doubleToLongBits(number.doubleValue()); case FLOAT: return Float.floatToIntBits(number.longValue()); default: throw new IllegalStateException( "Unknown NumericType " + dvConfig.getNumericType() + " for field " + dvConfig.getName()); } } catch (IOException e) { throw new RuntimeException("Unable to get field '" + dvConfig.getName() + "' from docID " + docID, e); } }
From source file:de.huxhorn.sulky.plist.impl.PropertyListWriter.java
private void writeValue(XMLStreamWriter writer, Object value) throws XMLStreamException { if (value == null) { return;//from w ww . j a v a 2 s . c o m } if (value instanceof String) { StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, (String) value); return; } if (value instanceof Boolean) { Boolean bool = (Boolean) value; if (bool) { StaxUtilities.writeEmptyElement(writer, null, null, TRUE_NODE); } else { StaxUtilities.writeEmptyElement(writer, null, null, FALSE_NODE); } return; } if (value instanceof Character) { StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, value.toString()); return; } if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { Number number = (Number) value; StaxUtilities.writeSimpleTextNode(writer, null, null, INTEGER_NODE, Long.toString(number.longValue())); return; } if (value instanceof Float || value instanceof Double) { Number number = (Number) value; StaxUtilities.writeSimpleTextNode(writer, null, null, REAL_NODE, Double.toString(number.doubleValue())); return; } if (value instanceof byte[]) { byte[] data = (byte[]) value; writeData(writer, data); return; } if (value instanceof Date) { Date date = (Date) value; writeDate(writer, date); return; } if (value instanceof Map) { Map map = (Map) value; writeDict(writer, map); return; } if (value instanceof Collection) { Collection collection = (Collection) value; writeArray(writer, collection); return; } Class valueClass = value.getClass(); if (valueClass.isArray()) { List<?> list; // we handled byte[] already if (value instanceof short[]) { short[] array = (short[]) value; ArrayList<Short> arrayList = new ArrayList<Short>(array.length); for (short v : array) { arrayList.add(v); } list = arrayList; } else if (valueClass == int[].class) { int[] array = (int[]) value; ArrayList<Integer> arrayList = new ArrayList<Integer>(array.length); for (int v : array) { arrayList.add(v); } list = arrayList; } else if (valueClass == long[].class) { long[] array = (long[]) value; ArrayList<Long> arrayList = new ArrayList<Long>(array.length); for (long v : array) { arrayList.add(v); } list = arrayList; } else if (valueClass == float[].class) { float[] array = (float[]) value; ArrayList<Float> arrayList = new ArrayList<Float>(array.length); for (float v : array) { arrayList.add(v); } list = arrayList; } else if (valueClass == double[].class) { double[] array = (double[]) value; ArrayList<Double> arrayList = new ArrayList<Double>(array.length); for (double v : array) { arrayList.add(v); } list = arrayList; } else if (valueClass == boolean[].class) { boolean[] array = (boolean[]) value; ArrayList<Boolean> arrayList = new ArrayList<Boolean>(array.length); for (boolean v : array) { arrayList.add(v); } list = arrayList; } else if (valueClass == char[].class) { char[] array = (char[]) value; String s = new String(array); StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, s); return; } else { list = Arrays.asList((Object[]) value); // special handling of container Object[] } writeArray(writer, list); return; } if (logger.isDebugEnabled()) logger.debug("No suitable conversion found for {}. Will save it as string.", valueClass.getName()); StaxUtilities.writeSimpleTextNode(writer, null, null, STRING_NODE, value.toString()); }
From source file:net.solarnetwork.node.dao.jdbc.power.JdbcPowerDatumDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<PowerDatum> getDatumNotUploaded(String destination) { return findDatumNotUploaded(new RowMapper<PowerDatum>() { @Override// ww w . ja v a 2 s. com public PowerDatum mapRow(ResultSet rs, int rowNum) throws SQLException { if (log.isTraceEnabled()) { log.trace("Handling result row " + rowNum); } PowerDatum datum = new PowerDatum(); int col = 1; datum.setCreated(rs.getTimestamp(col++)); datum.setSourceId(rs.getString(col++)); Number val = (Number) rs.getObject(col++); datum.setLocationId(val == null ? null : val.longValue()); val = (Number) rs.getObject(col++); datum.setWatts(val == null ? null : val.intValue()); val = (Number) rs.getObject(col++); datum.setBatteryVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setBatteryAmpHours(val == null ? null : val.doubleValue()); val = (Number) rs.getObject(col++); datum.setDcOutputVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setDcOutputAmps(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setAcOutputVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setAcOutputAmps(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setWattHourReading(val == null ? null : val.longValue()); val = (Number) rs.getObject(col++); datum.setAmpHourReading(val == null ? null : val.doubleValue()); return datum; } }); }
From source file:io.coala.time.AbstractInstant.java
/** @see Instant#plus(Number, TimeUnit) */ @Override/* w w w.j av a 2 s .c om*/ public THIS plus(final Number value, final TimeUnit unit) { Number delta = 0; try { delta = getUnit().convertFrom(value, unit); } catch (final CoalaRuntimeException e) { LOG.warn("Problem adding " + value + unit, e); } return plus(delta.doubleValue()); }
From source file:fr.gael.dhus.server.http.valve.processings.ProcessingValve.java
boolean checkParameter(Number param) { return !((param == null) || param.doubleValue() < 0); }
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java
/** * Calculates the stacked value of the all series up to, but not including <code>series</code> for the specified * category, <code>category</code>. It returns 0.0 if <code>series</code> is the first series, i.e. 0. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series./* w ww .j a v a 2s. co m*/ * @param category the category. * @return double returns a cumulative value for all series' values up to but excluding <code>series</code> for Object * <code>category</code>. * @deprecated As of 1.0.13, as the method is never used internally. */ protected double getPreviousHeight(final CategoryDataset dataset, final int series, final int category) { double result = 0.0; Number n; double total = 0.0; if (this.renderAsPercentages) { total = DataUtilities.calculateColumnTotal(dataset, category); } for (int i = 0; i < series; i++) { n = dataset.getValue(i, category); if (n != null) { double v = n.doubleValue(); if (this.renderAsPercentages) { v = v / total; } result += v; } } return result; }