List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
/**<!====== drawItem ======================================================> Draws a 3D bar to represent one data item. <! Name Description> @param g2 the graphics device. @param state the renderer state. @param dataArea the area for plotting the data. @param plot the plot./*w w w. j a v a 2 s . c o m*/ @param domainAxis the domain axis. @param rangeAxis the range axis. @param dataset the dataset. @param row the row index (zero-based). @param column the column index (zero-based). @param pass the pass index. <!=======================================================================>*/ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } g2.setStroke(new BasicStroke(1)); double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof Color) { Color endColor = getFrontDark((Color) itemPaint); Color startColor = (Color) itemPaint; Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor, (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor); g2.setPaint(paint); } g2.fill(bar); double x0 = bar.getMinX(); // left double x1 = x0 + getXOffset(); // offset left double x2 = bar.getMaxX(); // right double x3 = x2 + getXOffset(); // offset right double y0 = bar.getMinY() - getYOffset(); // offset top double y1 = bar.getMinY(); // bar top double y2 = bar.getMaxY() - getYOffset(); // offset bottom double y3 = bar.getMaxY(); // bottom //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight()); Line2D.Double line = new Line2D.Double(x2, y1, x2, y3); g2.draw(line); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; g2.setPaint(itemPaint); // Draw the right side if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { Color startColor = getSideLight((Color) itemPaint); Color endColor = getSideDark((Color) itemPaint); Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3, endColor); g2.setPaint(paint); } g2.fill(bar3dRight); } // Draw the top bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); // bottom left bar3dTop.lineTo((float) x1, (float) y0); // top left bar3dTop.lineTo((float) x3, (float) y0); // top right bar3dTop.lineTo((float) x2, (float) y1); // bottom right bar3dTop.closePath(); if (itemPaint instanceof Color) { Color endColor = getTopDark((Color) itemPaint); Color startColor = getTopLight((Color) itemPaint); //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor); Point2D.Double topRight = new Point2D.Double(x3, y0); Point2D.Double bottomLeft = new Point2D.Double(x0, y1); //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2))); Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2))); Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor, (float) darkEnd.getX(), (float) darkEnd.getY(), endColor); g2.setPaint(paint); //drawMarker(topRight, g2, startColor); } g2.fill(bar3dTop); g2.setPaint(itemPaint); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java
public void validateLessThanNumber(Object propertyValidator) { BindingComponent inputComponent = ((PropertyValidator) propertyValidator).getBindingComponent(); Number max = (Number) ((PropertyValidator) propertyValidator).getMaxValue(); PropertyResults propertyResults = null; logger.info("validation " + inputComponent.getFieldName() + ": is lessThan"); Number valorCampo = (Number) inputComponent.getValue(); if (valorCampo != null) { if (!(max.doubleValue() >= valorCampo.doubleValue())) { throw new AWValidationException("sw.error.validate.lessThan", new Object[] { max.toString() }, Arrays.asList(new Object[] { inputComponent })); }/*from w w w . ja v a2 s .co m*/ } }
From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java
/** * Returns true if the specified item is the last positive value for that * category./*from w w w.j av a2 s. c o m*/ * * @param dataset the dataset. * @param row the row (series). * @param column the column (category). * * @return a boolean. */ private boolean isLastPositiveItem(CategoryDataset dataset, int row, int column) { boolean result = true; Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return false; // value is null } for (int r = row + 1; r < dataset.getRowCount(); r++) { dataValue = dataset.getValue(r, column); if (dataValue != null) { result = result && (dataValue.doubleValue() <= 0.0); } } return result; }
From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java
/** * Returns true if the specified item is the last negative value for that * category./*ww w . ja v a 2 s. c o m*/ * * @param dataset the dataset. * @param row the row (series). * @param column the column (category). * * @return a boolean. */ private boolean isLastNegativeItem(CategoryDataset dataset, int row, int column) { boolean result = true; Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return false; // value is null } for (int r = row + 1; r < dataset.getRowCount(); r++) { dataValue = dataset.getValue(r, column); if (dataValue != null) { result = result && (dataValue.doubleValue() >= 0.0); } } return result; }
From source file:org.jfree.data.DefaultMeterDataset.java
/** * Sets the range for the dataset. Registered listeners are notified of the change. * /* w w w. j a v a2 s . c o m*/ * @param min * the new minimum. * @param max * the new maximum. */ public void setRange(Number min, Number max) { if (min == null || max == null) { throw new IllegalArgumentException("Min/Max should not be null"); } // swap min and max if necessary... if (min.doubleValue() > max.doubleValue()) { final Number temp = min; min = max; max = temp; } if (this.value != null) { if (min.doubleValue() == max.doubleValue()) { min = new Double(this.value.doubleValue() - DEFAULT_ADJ); max = new Double(this.value.doubleValue() + DEFAULT_ADJ); } } this.min = min; this.max = max; fireDatasetChanged(); }
From source file:nz.co.senanque.rules.OperationsImpl.java
@InternalFunction(operator = "/", precedence = 21) public Number div(Number value, Number value2) { Number ret = null;/*from w w w .j av a 2s . c om*/ if (value == null || value2 == null) { return new Long(0L); } if (value.doubleValue() == 0.0) { String message = new MessageSourceAccessor(m_messageSource) .getMessage("nz.co.senanque.rules.divide.by.zero"); throw new InferenceException(message); } ret = value2.doubleValue() / value.doubleValue(); return ret; }
From source file:com.clican.pluto.dataprocess.dpl.function.impl.MatchPriceAndWeight.java
@SuppressWarnings("unchecked") public Object calculate(List<Map<String, Object>> rowSet) throws CalculationException, PrefixAndSuffixException { Map<String, Object> mapRow = new HashMap<String, Object>(); boolean clear = true; Date date = null;//from ww w .j a v a2 s. c om for (Map<String, Object> row : rowSet) { date = datePas.getValue(row); String weightCode = weightCodePas.getValue(row); Number weight = weightPas.getValue(row); if (StringUtils.isNotEmpty(weightCode) && clear) { previousWeightMap.clear(); previousResetDuration = resetDurationPas.getValue(row); previousDate = datePas.getValue(row); clear = false; } if (StringUtils.isNotEmpty(weightCode)) { previousWeightMap.put(weightCode, weight.doubleValue()); } } // ??? boolean changeWeight = !clear; if (changeWeight) { for (String code : allCodes) { if (!previousWeightMap.containsKey(code)) { previousWeightMap.put(code, 0d); } } weightMap = new HashMap<String, Double>(previousWeightMap); } else { if (StringUtils.isNotEmpty(previousResetDuration)) { if (previousResetDuration.equals("1D")) { weightMap = new HashMap<String, Double>(previousWeightMap); } else if (previousResetDuration.equals("1W")) { if (!ToChar.toYearAndWeek(previousDate).equals(ToChar.toYearAndWeek(date))) { previousDate = date; weightMap = new HashMap<String, Double>(previousWeightMap); } } else if (previousResetDuration.equals("1M")) { Date temp = DateUtils.addMonths(previousDate, 1); if (temp.compareTo(date) <= 0) { previousDate = date; weightMap = new HashMap<String, Double>(previousWeightMap); } } else if (previousResetDuration.equals("3M")) { Date temp = DateUtils.addMonths(previousDate, 3); if (temp.compareTo(date) <= 0) { previousDate = date; weightMap = new HashMap<String, Double>(previousWeightMap); } } } } Set<String> populatePriceSet = new HashSet<String>(); for (Map<String, Object> row : rowSet) { mapRow.put("date", date); // ??? if (weightMap.size() == 0) { break; } String priceCode = priceCodePas.getValue(row); if (weightMap.containsKey(priceCode)) { populatePriceSet.add(priceCode); } } mapRow.put("date", date); if (populatePriceSet.size() == weightMap.size()) { for (Map<String, Object> row : rowSet) { String priceCode = priceCodePas.getValue(row); Number price = pricePas.getValue(row); if (StringUtils.isNotEmpty(priceCode) && weightMap.containsKey(priceCode)) { if (!mapRow.containsKey("priceMap")) { mapRow.put("priceMap", new HashMap<String, Double>()); } ((Map) mapRow.get("priceMap")).put(priceCode, price.doubleValue()); if (!mapRow.containsKey("weightMap")) { mapRow.put("weightMap", new HashMap<String, Double>()); } if (!((Map) mapRow.get("weightMap")).containsKey(priceCode)) { ((Map) mapRow.get("weightMap")).put(priceCode, weightMap.get(priceCode)); } if (previousResetDuration.equals("1W") || previousResetDuration.equals("1M") || previousResetDuration.equals("3M")) { // ????? weightMap.put(priceCode, null); } } } } return mapRow; }
From source file:com.pureinfo.srm.reports.table.data.institute.Index3Statitistic.java
private void addDouble(Object[] _line, int _nIdx, Number _oValue) { if (_oValue == null) return;/*from w w w . ja v a2s. com*/ if (_line[_nIdx] == null || null == _line[_nIdx]) { _line[_nIdx] = _oValue; } else { Number num = (Number) _line[_nIdx]; _line[_nIdx] = new Double(_oValue.doubleValue() + num.doubleValue()); } }
From source file:com.diversityarrays.kdxplore.stats.DoubleSimpleStatistics.java
public DoubleSimpleStatistics(String statsName, List<KdxSample> sampleMeasurements, Integer nStdDevForOutlier, NumericTraitValidationProcessor tvp) { super(statsName, Double.class); String stringFormat = tvp.getStringNumberFormat(); if (tvp.validationRule.isIntegralRange()) { throw new IllegalStateException("ValidationRule is for an integralRange: " + tvp.validationRule); }//w ww. j a v a 2s . c om decimalFormat = tvp.validationRule.getDecimalFormat(); nSampleMeasurements = sampleMeasurements.size(); double sum = 0; @SuppressWarnings("unused") double ssq = 0; Bag<String> svalues = new HashBag<String>(); List<Double> values = new ArrayList<>(nSampleMeasurements); for (KdxSample sm : sampleMeasurements) { String traitValue = sm.getTraitValue(); switch (TraitValue.classify(traitValue)) { case NA: ++nNA; break; case SET: Either<TraitValueType, Number> either = tvp.isTraitValueValid(traitValue); if (either.isRight()) { try { Number number = either.right(); if (number == null) { ++nMissing; } else { double d = number.doubleValue(); sum += d; ssq += d * d; values.add(d); if (stringFormat == null) { svalues.add(traitValue); } else { svalues.add(String.format(stringFormat, d)); } } } 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); mode = mean.toString(); median = mean; minValue = mean; maxValue = mean; variance = null; stddev = null; nOutliers = null; stderr = null; break; default: mean = sum / nValidValues; if (USE_TWO_PASS) { double s2 = 0; for (Double d : values) { s2 += (d - mean) * (d - 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); maxValue = values.get(values.size() - 1); median = StatsUtil.computeDoubleMedian(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(String.format(numberFormat, number.doubleValue())); } } else { sb.append(s); } } sep = " , "; } mode = sb.toString(); double q1 = BoxAndWhiskerCalculator.calculateQ1(values); double q3 = BoxAndWhiskerCalculator.calculateQ3(values); quartile1 = q1; quartile3 = 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:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java
private void drawCoinOutliers(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, ValueAxis rangeAxis, int row, int column, BoxAndWhiskerCategoryDataset bawDataset, double xx, RectangleEdge location, double oRadius, List<Outlier> outliers, List<Number> yOutliers) { double yyOutlier; 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)); }/*w w w. ja v a2s . com*/ } Collections.sort(outliers); for (Iterator<Outlier> iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = iterator.next(); Point2D point = outlier.getPoint(); drawEllipse(point, oRadius, g2); } }