List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:org.jfree.data.KeyedValueComparator.java
/** * Compares two {@link KeyedValue} instances and returns an * <code>int</code> that indicates the relative order of the two objects. * * @param o1 object 1./*from w w w . ja v a2 s. c o m*/ * @param o2 object 2. * * @return An int indicating the relative order of the objects. */ @Override public int compare(Object o1, Object o2) { if (o2 == null) { return -1; } if (o1 == null) { return 1; } int result; KeyedValue kv1 = (KeyedValue) o1; KeyedValue kv2 = (KeyedValue) o2; if (this.type == KeyedValueComparatorType.BY_KEY) { if (this.order.equals(SortOrder.ASCENDING)) { result = kv1.getKey().compareTo(kv2.getKey()); } else if (this.order.equals(SortOrder.DESCENDING)) { result = kv2.getKey().compareTo(kv1.getKey()); } else { throw new IllegalArgumentException("Unrecognised sort order."); } } else if (this.type == KeyedValueComparatorType.BY_VALUE) { Number n1 = kv1.getValue(); Number n2 = kv2.getValue(); if (n2 == null) { return -1; } if (n1 == null) { return 1; } double d1 = n1.doubleValue(); double d2 = n2.doubleValue(); if (this.order.equals(SortOrder.ASCENDING)) { if (d1 > d2) { result = 1; } else if (d1 < d2) { result = -1; } else { result = 0; } } else if (this.order.equals(SortOrder.DESCENDING)) { if (d1 > d2) { result = -1; } else if (d1 < d2) { result = 1; } else { result = 0; } } else { throw new IllegalArgumentException("Unrecognised sort order."); } } else { throw new IllegalArgumentException("Unrecognised type."); } return result; }
From source file:org.jfree.data.xy.DefaultOHLCDataset.java
/** * Returns the volume-value (as a double primitive) for an item within a * series.// w ww . j a va 2 s . com * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The volume-value. */ @Override public double getVolumeValue(int series, int item) { double result = Double.NaN; Number volume = getVolume(series, item); if (volume != null) { result = volume.doubleValue(); } return result; }
From source file:mavn.network.view.JUNGPanelAdapter.java
public void fireNodes(final double[] result) { Transformer<Number, Paint> vertexPaint = new Transformer<Number, Paint>() { private final Color[] palette = { new Color(51, 181, 229), Color.BLACK, new Color(255, 68, 68) }; @Override//from w w w . j av a 2 s . c o m public Paint transform(Number i) { if (i.doubleValue() == inputX || i.doubleValue() == inputY) { if (result[inputX] == 1) { return palette[0]; } if (result[inputY] == -1) { return palette[0]; } } if (i.doubleValue() >= andMin && i.doubleValue() <= andMax) { if (result[i.intValue()] == 1) { return palette[0]; } if (result[i.intValue()] == -1) { return palette[1]; } } if (i.doubleValue() >= orMin && i.doubleValue() <= orMax) { if (result[i.intValue()] == 1) { return palette[0]; } if (result[i.intValue()] == -1) { return palette[1]; } } if (i.doubleValue() == output) { if (result[output] == 1) { return palette[0]; } if (result[output] == -1) { return palette[1]; } } return palette[2]; } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); }
From source file:ListProperties.java
public int compareRowsByColumn(int row1, int row2, int column) { Class type = model.getColumnClass(column); TableModel data = model;//from www.j a v a2 s . c om // Check for nulls Object o1 = data.getValueAt(row1, column); Object o2 = data.getValueAt(row2, column); // If both values are null return 0 if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { // Define null less than everything. return -1; } else if (o2 == null) { return 1; } if (type.getSuperclass() == Number.class) { Number n1 = (Number) data.getValueAt(row1, column); double d1 = n1.doubleValue(); Number n2 = (Number) data.getValueAt(row2, column); double d2 = n2.doubleValue(); if (d1 < d2) return -1; else if (d1 > d2) return 1; else return 0; } else if (type == String.class) { String s1 = (String) data.getValueAt(row1, column); String s2 = (String) data.getValueAt(row2, column); int result = s1.compareTo(s2); if (result < 0) return -1; else if (result > 0) return 1; else return 0; } else if (type == java.util.Date.class) { Date d1 = (Date) data.getValueAt(row1, column); long n1 = d1.getTime(); Date d2 = (Date) data.getValueAt(row2, column); long n2 = d2.getTime(); if (n1 < n2) return -1; else if (n1 > n2) return 1; else return 0; } else if (type == Boolean.class) { Boolean bool1 = (Boolean) data.getValueAt(row1, column); boolean b1 = bool1.booleanValue(); Boolean bool2 = (Boolean) data.getValueAt(row2, column); boolean b2 = bool2.booleanValue(); if (b1 == b2) return 0; else if (b1) // Define false < true return 1; else return -1; } else { Object v1 = data.getValueAt(row1, column); String s1 = v1.toString(); Object v2 = data.getValueAt(row2, column); String s2 = v2.toString(); int result = s1.compareTo(s2); if (result < 0) return -1; else if (result > 0) return 1; else return 0; } }
From source file:com.diversityarrays.kdxplore.stats.IntegerSimpleStatistics.java
public IntegerSimpleStatistics(String statsName, List<KdxSample> sampleMeasurements, Integer nStdDevForOutlier, NumericTraitValidationProcessor tvp) { super(statsName, Integer.class); nSampleMeasurements = sampleMeasurements.size(); long sum = 0; @SuppressWarnings("unused") double ssq = 0; Bag<String> svalues = new HashBag<String>(); List<Integer> values = new ArrayList<>(nSampleMeasurements); for (KdxSample sm : sampleMeasurements) { String traitValue = sm.getTraitValue(); switch (TraitValue.classify(traitValue)) { case NA://from ww w. j av a2s. com ++nNA; break; case SET: Either<TraitValueType, Number> either = tvp.isTraitValueValid(traitValue); if (either.isRight()) { try { Number number = either.right(); if (number == null) { ++nMissing; } else { int i = number.intValue(); sum += i; ssq += i * 1.0 * i; values.add(i); svalues.add(String.valueOf(i)); } } catch (NumberFormatException e) { ++nInvalid; } } else { ++nInvalid; } break; case MISSING: case UNSET: default: ++nMissing; break; } } nValidValues = values.size(); switch (nValidValues) { case 0: mean = null; mode = null; median = null; minValue = null; maxValue = null; variance = null; stddev = null; nOutliers = null; stderr = null; break; case 1: mean = values.get(0).intValue(); mode = mean.toString(); median = mean; minValue = mean; maxValue = mean; variance = null; stddev = null; nOutliers = null; stderr = null; break; default: mean = (int) sum / nValidValues; if (USE_TWO_PASS) { double s2 = 0; for (Number n : values) { double i = n.doubleValue(); s2 += (i - mean) * (i - mean); } variance = s2 / (nValidValues - 1); } else { variance = (ssq - (sum * sum) / nValidValues) / (nValidValues - 1); } stddev = Math.sqrt(variance); stderr = stddev / Math.sqrt(nValidValues); Collections.sort(values); minValue = values.get(0).intValue(); maxValue = values.get(values.size() - 1).intValue(); median = StatsUtil.computeIntegerMedian(values); List<String> modes = StatsUtil.computeMode(svalues, tvp); String numberFormat = tvp == null ? null : tvp.getStringNumberFormat(); StringBuilder sb = new StringBuilder(); String sep = ""; for (String s : modes) { sb.append(sep); if (tvp == null) { sb.append(s); } else { Either<TraitValueType, Number> either = tvp.isTraitValueValid(s); if (either.isRight()) { Number number = either.right(); if (Integer.class.isAssignableFrom(tvp.getNumberClass())) { sb.append(number.intValue()); } else if (numberFormat == null) { sb.append(s); } else { sb.append(number.intValue()); } } else { sb.append(s); } } sep = " , "; } mode = sb.toString(); double q1 = BoxAndWhiskerCalculator.calculateQ1(values); double q3 = BoxAndWhiskerCalculator.calculateQ3(values); quartile1 = (int) Math.round(q1); quartile3 = (int) Math.round(q3); if (nStdDevForOutlier == null) { double interQuartileRange = q3 - q1; double lowerOutlierThreshold = q1 - (interQuartileRange * 1.5); double upperOutlierThreshold = q3 + (interQuartileRange * 1.5); collectOutliers(values, lowerOutlierThreshold, upperOutlierThreshold); } else { double lowerOutlierThreshold = mean - (nStdDevForOutlier * stddev); double upperOutlierThreshold = mean + (nStdDevForOutlier * stddev); collectOutliers(values, lowerOutlierThreshold, upperOutlierThreshold); } break; } }
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
/** * Draws the visual representation of a single wind arrow. *///from w w w . j a va2 s . c o m @Override public void drawItem(Graphics2D g2d, XYItemRendererState state, Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { resizeArrowByPlotHeight((int) plotArea.getHeight()); // Needs a new graphics object to use translate() and rotate() Graphics2D g2 = (Graphics2D) g2d.create(); g2.setRenderingHints(renderHints); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); double middleY = plotArea.getCenterY(); WindDataset windData = (WindDataset) dataset; Number x = windData.getX(series, item); Number windDir = windData.getWindDirection(series, item); Number wforce = windData.getWindForce(series, item); double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, domainAxisLocation); g2.translate((int) middleX, (int) middleY); g2.setColor(Color.BLACK); if (wforce.doubleValue() <= zeroWindLimit) { drawCircle(g2); } else { g2.rotate(Math.toRadians(windDir.doubleValue() - 180)); drawArrow(g2, wforce.doubleValue()); if (useArrowHead) { g2.fill(getPolygonHead(arrowHeadSize, arrowHeight)); } else { g2.draw(getCircleHead(arrowHeadSize, arrowHeight)); } } }
From source file:se.six.jmeter.visualizer.statagg.StatAggVisualizer.java
private void resample(ArrayList items, TimeSeries ts) { int cursor = _resampleIdx; // To prevent the timeseries history to be resamped // each time, we restart the resampling from where the last // ended.//from w w w.ja v a2s . com System.out.println("Resample, items size: " + items.size() + ", Cursor: " + cursor); if (cursor >= _maxChartItemCount) { // we have now reach the end of the timeseries, // now restart the sampling from the root. cursor = 0; System.out.println("Resetting cursor!"); } // Just copy those items less than cursor index to timeseries for (int i = 0; i < cursor; i++) { TimeSeriesDataItem item = (TimeSeriesDataItem) items.get(i); addValue(ts, item); } double sampleValue = 0; int sampleCount = 0; for (int i = cursor; i < items.size(); i++) { TimeSeriesDataItem item = (TimeSeriesDataItem) items.get(i); RegularTimePeriod period = item.getPeriod(); Number value = item.getValue(); sampleValue += value.doubleValue(); sampleCount++; if (((i + 1) % _resampleFactor) == 0) { sampleValue /= sampleCount; addValue(ts, period, sampleValue); sampleValue = sampleCount = 0; } } }
From source file:com.adr.mimame.PlatformList.java
public Image getCachedImage(String url) { if (url == null) { return null; } else if (!"http".equalsIgnoreCase(url.substring(0, 4)) && !"ftp".equalsIgnoreCase(url.substring(0, 3))) { // a local image return new Image(url, true); } else {//from w w w. ja va 2s . co m // a remote image try { File cachedir = new File(mimamememuhome, "IMGCACHE"); FileUtils.forceMkdir(cachedir); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(url.getBytes("UTF-8")); String cachefilename = Base64.getUrlEncoder().encodeToString(md.digest()); File cachefile = new File(cachedir, cachefilename + ".png"); File cachefilenull = new File(cachedir, cachefilename + ".null"); if (cachefilenull.exists()) { return null; } else if (cachefile.exists()) { return new Image(cachefile.toURI().toURL().toString(), true); } else { Image img = new Image(url, true); img.progressProperty().addListener( (ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> { if (newValue.doubleValue() == 1.0) { exec.execute(() -> { try { if (img.isError()) { cachefilenull.createNewFile(); } else { ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png", cachefile); } } catch (IOException ex) { logger.log(Level.SEVERE, "Cannot save image cache.", ex); } }); } }); return img; } } catch (IOException | NoSuchAlgorithmException ex) { logger.log(Level.SEVERE, "Cannot create image cache.", ex); return new Image(url); } } }
From source file:com.github.lpezet.antiope.metrics.aws.spi.PredefinedMetricTransformer.java
protected List<MetricDatum> metricOfCount(APIRequestMetrics pMetricType, Request<?> pReq, Object pResp) { IMetrics m = pReq.getMetrics();/*from w ww . j av a2s.c o m*/ TimingInfo ti = m.getTimingInfo(); Number oCounter = ti.getCounter(pMetricType.name()); if (oCounter == null) { return Collections.emptyList(); } final double oCount = oCounter.doubleValue(); if (oCount < 1) { return Collections.emptyList(); } else { return Collections.singletonList(new MetricDatum().withMetricName(pReq.getServiceName()) .withDimensions( new Dimension().withName(Dimensions.MetricType.name()).withValue(pMetricType.name())) .withUnit(StandardUnit.Count).withValue(Double.valueOf(oCount)) .withTimestamp(endTimestamp(ti))); } }
From source file:org.jfree.chart.demo.ExtendedStackedBarRenderer.java
/** * Calculates the sum of the positive values within a category. * //from ww w . j a v a 2 s. com * @param dataset the dataset. * @param column the column (category). * * @return the sum of the positive values. */ private double calculateSumOfPositiveValuesForCategory(final CategoryDataset dataset, final int column) { double result = 0.0; for (int r = 0; r < dataset.getRowCount(); r++) { final Number dataValue = dataset.getValue(r, column); if (dataValue != null) { final double v = dataValue.doubleValue(); if (v > 0.0) { result = result + v; } } } return result; }