List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:com.hello2morrow.sonarplugin.SonargraphSensor.java
private void analyse(IProject project, XsdAttributeRoot xsdBuildUnit, String buildUnitName, ReportContext report) {/*from w w w .j a v a2 s. c om*/ LOG.info("Adding measures for " + project.getName()); readAttributes(xsdBuildUnit); Number internalPackages = getBuildUnitMetric(INTERNAL_PACKAGES); if (internalPackages.intValue() == 0) { LOG.warn("No packages found in project " + project.getName()); return; } saveMeasure(ACD, SonargraphMetrics.ACD, 1); saveMeasure(NCCD, SonargraphMetrics.NCCD, 1); saveMeasure(INSTRUCTIONS, SonargraphMetrics.INSTRUCTIONS, 0); saveMeasure(JAVA_FILES, SonargraphMetrics.JAVA_FILES, 0); saveMeasure(TYPE_DEPENDENCIES, SonargraphMetrics.TYPE_DEPENDENCIES, 0); saveMeasure(EROSION_REFS, SonargraphMetrics.EROSION_REFS, 0); saveMeasure(EROSION_TYPES, SonargraphMetrics.EROSION_TYPES, 0); Number structuralDebtIndex = saveMeasure(STUCTURAL_DEBT_INDEX, SonargraphMetrics.EROSION_INDEX, 0) .getValue(); if (indexCost > 0) { double structuralDebtCost = structuralDebtIndex.doubleValue() * indexCost; saveMeasure(SonargraphMetrics.EROSION_COST, structuralDebtCost, 0); } analyseCycleGroups(report, internalPackages, buildUnitName); if (hasBuildUnitMetric(UNASSIGNED_TYPES)) { LOG.info("Adding architecture measures for " + project.getName()); addArchitectureMeasures(report, buildUnitName); } AlertDecorator.setAlertLevels(new SensorProjectContext(sensorContext)); }
From source file:com.hello2morrow.sonarplugin.SonarJSensor.java
private void analyse(IProject project, XsdAttributeRoot xsdBuildUnit, String buildUnitName, ReportContext report, boolean isMultiModuleProject) { LOG.info("Adding measures for " + project.getName()); projectMetrics = readAttributes(xsdBuildUnit); Number internalPackages = projectMetrics.get(INTERNAL_PACKAGES); if (internalPackages.intValue() == 0) { LOG.warn("No classes found in project " + project.getName()); return;/*from ww w . j ava2s . c o m*/ } double acd = projectMetrics.get(ACD).doubleValue(); double nccd = projectMetrics.get(NCCD).doubleValue(); saveMeasure(ACD, SonarJMetrics.ACD, 1); saveMeasure(NCCD, SonarJMetrics.NCCD, 1); saveMeasure(INSTRUCTIONS, SonarJMetrics.INSTRUCTIONS, 0); saveMeasure(JAVA_FILES, SonarJMetrics.JAVA_FILES, 0); saveMeasure(TYPE_DEPENDENCIES, SonarJMetrics.TYPE_DEPENDENCIES, 0); saveMeasure(EROSION_REFS, SonarJMetrics.EROSION_REFS, 0); saveMeasure(EROSION_TYPES, SonarJMetrics.EROSION_TYPES, 0); Number structuralDebtIndex = saveMeasure(STUCTURAL_DEBT_INDEX, SonarJMetrics.EROSION_INDEX, 0).getValue(); if (indexCost > 0) { double structuralDebtCost = structuralDebtIndex.doubleValue() * indexCost; saveMeasure(SonarJMetrics.EROSION_COST, structuralDebtCost, 0); } analyseCycleGroups(report, internalPackages, buildUnitName); if (projectMetrics.get(UNASSIGNED_TYPES) != null) { LOG.info("Adding architecture measures for " + project.getName()); addArchitectureMeasures(report, buildUnitName); } AlertDecorator.setAlertLevels(new SensorProjectContext(sensorContext)); }
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex, PieDataset data) {// w w w . ja v a 2 s . c o m // adjust the plot area by the interior spacing value double gapHorizontal = plotArea.getWidth() * this.interiorGap; double gapVertical = plotArea.getHeight() * this.interiorGap; double radarX = plotArea.getX() + gapHorizontal / 2; double radarY = plotArea.getY() + gapVertical / 2; double radarW = plotArea.getWidth() - gapHorizontal; double radarH = plotArea.getHeight() - gapVertical; // make the radar area a square if the radar chart is to be circular... // NOTE that non-circular radar charts are not currently supported. if (true) { //circular) { double min = Math.min(radarW, radarH) / 2; radarX = (radarX + radarX + radarW) / 2 - min; radarY = (radarY + radarY + radarH) / 2 - min; radarW = 2 * min; radarH = 2 * min; } double radius = radarW / 2; double centerX = radarX + radarW / 2; double centerY = radarY + radarH / 2; Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH); // plot the data (unless the dataset is null)... if ((data != null) && (data.getKeys().size() > 0)) { // get a list of categories... List keys = data.getKeys(); int numAxes = keys.size(); // draw each of the axes on the radar chart, and register // the shape of the radar line. double multiplier = 1.0; GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); int axisNumber = -1; Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable currentKey = (Comparable) iterator.next(); axisNumber++; Number dataValue = data.getValue(currentKey); double value = (dataValue != null ? dataValue.doubleValue() : 0); if (value > 1 || Double.isNaN(value) || Double.isInfinite(value)) value = 1.0; if (value < 0) value = 0.0; multiplier *= value; double angle = 2 * Math.PI * axisNumber / numAxes; double deltaX = Math.sin(angle) * radius; double deltaY = -Math.cos(angle) * radius; // draw the spoke g2.setPaint(axisPaint); g2.setStroke(axisStroke); Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY); g2.draw(line); // register the grid line and the shape line if (axisNumber == 0) { gridShape.moveTo((float) deltaX, (float) deltaY); lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value)); } else { gridShape.lineTo((float) deltaX, (float) deltaY); lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value)); } if (showAxisLabels) { // draw the label double labelX = centerX + deltaX * (1 + axisLabelGap); double labelY = centerY + deltaY * (1 + axisLabelGap); String label = currentKey.toString(); drawLabel(g2, radarArea, label, axisNumber, labelX, labelY); } } gridShape.closePath(); lineShape.closePath(); // draw five gray concentric gridlines g2.translate(centerX, centerY); g2.setPaint(gridLinePaint); g2.setStroke(gridLineStroke); for (int i = 5; i > 0; i--) { Shape scaledGrid = gridShape .createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0)); g2.draw(scaledGrid); } // get the color for the plot shape. Paint dataPaint = plotLinePaint; if (dataPaint == ADAPTIVE_COLORING) { //multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes); dataPaint = getMultiplierColor((float) multiplier); } // compute a slightly transparent version of the plot color for // the fill. Paint dataFill = null; if (dataPaint instanceof Color && getForegroundAlpha() != 1.0) dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f, ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha()); else dataFill = dataPaint; // draw the plot shape. First fill with a parially // transparent color, then stroke with the opaque color. g2.setPaint(dataFill); g2.fill(lineShape); g2.setPaint(dataPaint); g2.setStroke(plotLineStroke); g2.draw(lineShape); // cleanup the graphics context. g2.translate(-centerX, -centerY); } }
From source file:gov.nasa.jpf.constraints.solvers.cw.CWSolver.java
/** * Returns a point {@code r} where the linear function {@code f} with * {@code f(p) = valueAtP} and {@code f(q) = valueAtQ} is zero, that is, * {@code f(r) = 0}./*from w w w .j a va2 s.com*/ * * <p> * NOTE: The returned point does not necessarily lie within the polytope. * * <p> * This is the BisectionStep function that appears in the paper. */ private RealVector linearlyEstimateZero(RealVector p, Number valueAtP, RealVector q, Number valueAtQ, NumericComparator comparator) { double vP = valueAtP.doubleValue(); double vQ = valueAtQ.doubleValue(); double t0 = (vP != vQ) ? -vP / (vQ - vP) : random.nextGaussian(); if (comparator != NumericComparator.EQ) { t0 *= (1.0 + (random.nextInt(250) * 0.01)); if (t0 == 0) { t0 = random.nextGaussian(); } } return RealVector.plus(RealVector.times(t0, RealVector.minus(q, p)), p); }
From source file:net.java.javamoney.examples.tradingapp.web.PortfolioController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); String m = null;//from w ww .j a v a2 s .c o m Object o; Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { o = e.nextElement(); //logger.info("Param: " + o); if (String.valueOf(o).equals(MODEL)) { o = request.getParameter(MODEL); if (o instanceof Map) { //logger.info("It's a Map"); model = (Map) o; } } else if (String.valueOf(o).equals(MARKET)) { m = request.getParameter(MARKET); } } if (m != null && m.length() > 0) { String mDetails = this.market.getKnownMarkets().get(m); logger.info("Market: " + m + "=" + mDetails); market.setSymbol(m); //model.put(MARKET, m); String cSymbol = null; String mName = null; StringTokenizer st = new StringTokenizer(mDetails, ";"); while (st.hasMoreElements()) { if (mName == null) { mName = st.nextToken(); } else { if (cSymbol == null) { cSymbol = st.nextToken(); } } } if (mName != null) { market.setName(mName); } if (cSymbol != null) { Currency curr = new Currency(cSymbol); // TODO retrieve this from Yahoo Service similar to quotes, or 354 style ExchangeRateProvider Object oRate = market.getCurrencyExchangeRates().get(cSymbol); if (oRate != null) { Number exchangeRate; if (oRate instanceof Number) { exchangeRate = (Number) oRate; } else { try { exchangeRate = Double.parseDouble(String.valueOf(oRate)); } catch (NumberFormatException nfe) { logger.warn("Error during currency conversion", nfe); exchangeRate = 0; } } logger.info(exchangeRate); curr.setExchangeRate(exchangeRate.doubleValue()); } else { logger.warn("Could not find exchange rate for " + curr); curr.setExchangeRate(0); // TODO kind of dodgy, should throw exception or something? } //curr.setExchangeRate(1.4); labelCurrency(cSymbol, curr); //Currency.setReferenceCurrency(curr); portfolio.setCurrency(curr); // TODO portfolio should directly store market! market.setCurrency(curr); } } List<PortfolioItemBean> portfolioItems = getPortfolioItems(); model.put(MARKET, market); model.put("currency", portfolio.getCurrency()); model.put("cash", portfolio.getCash() + ""); model.put("amount", portfolio.getAmount()); model.put("amountLocal", portfolio.getAmount().to(portfolio.getCurrency())); model.put("portfolioItems", portfolioItems); return new ModelAndView(PORTFOLIO, MODEL, model); }
From source file:de.xirp.ui.widgets.panels.LiveChartComposite.java
/** * Adds the given value to the chart.//from w w w . j a v a 2 s . co m * * @param key * The key. * @param number * The value. * @param timestamp * The time stamp. */ private void addValueToChart(final String key, final Number number, final long timestamp) { SWTUtil.asyncExec(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { if (!isDisposed()) { try { keySeriesMap.get(key).addOrUpdate(new Millisecond(new Date(timestamp)), number.doubleValue()); } catch (NullPointerException e) { logClass.trace("Trace: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } } } }); }
From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java
public Integer convertToInteger(final String numericalValueFormatted, final String parameterName, final Locale clientApplicationLocale) { if (clientApplicationLocale == null) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final String defaultMessage = new StringBuilder( "The parameter '" + parameterName + "' requires a 'locale' parameter to be passed with it.") .toString();/* w w w .j a v a2 s . c o m*/ final ApiParameterError error = ApiParameterError .parameterError("validation.msg.missing.locale.parameter", defaultMessage, parameterName); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } try { Integer number = null; if (StringUtils.isNotBlank(numericalValueFormatted)) { String source = numericalValueFormatted.trim(); final NumberFormat format = NumberFormat.getInstance(clientApplicationLocale); final DecimalFormat df = (DecimalFormat) format; final DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); df.setParseBigDecimal(true); // http://bugs.sun.com/view_bug.do?bug_id=4510618 final char groupingSeparator = symbols.getGroupingSeparator(); if (groupingSeparator == '\u00a0') { source = source.replaceAll(" ", Character.toString('\u00a0')); } final Number parsedNumber = df.parse(source); final double parsedNumberDouble = parsedNumber.doubleValue(); final int parsedNumberInteger = parsedNumber.intValue(); if (source.contains(Character.toString(symbols.getDecimalSeparator()))) { throw new ParseException(source, 0); } if (!Double.valueOf(parsedNumberDouble) .equals(Double.valueOf(Integer.valueOf(parsedNumberInteger)))) { throw new ParseException(source, 0); } number = parsedNumber.intValue(); } return number; } catch (final ParseException e) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final ApiParameterError error = ApiParameterError.parameterError( "validation.msg.invalid.integer.format", "The parameter " + parameterName + " has value: " + numericalValueFormatted + " which is invalid integer value for provided locale of [" + clientApplicationLocale.toString() + "].", parameterName, numericalValueFormatted, clientApplicationLocale); error.setValue(numericalValueFormatted); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } }
From source file:it.geosolutions.geobatch.destination.ingestion.OriginalArcsIngestionProcess.java
private void preloadIncidentalita() throws IOException { incidentalitaStandard.clear();/*from ww w .j a va 2s . co m*/ FeatureReader<SimpleFeatureType, SimpleFeature> featureReader = dataStore .getFeatureReader(new Query(INCIDENTALITA_FEATURE), Transaction.AUTO_COMMIT); try { while (featureReader.hasNext()) { SimpleFeature feature = featureReader.next(); String provincia = (String) feature.getAttribute("cod_provincia"); Integer patrimonialita = ((Number) feature.getAttribute("id_patrimonialita")).intValue(); Integer anno = ((Number) feature.getAttribute("anno")).intValue(); Number incidenti = (Number) feature.getAttribute("nr_incidenti"); if (incidenti != null) { if (cumulativeData.containsKey(provincia + "." + patrimonialita)) { incidenti = incidenti.doubleValue() / cumulativeData.get(provincia + "." + patrimonialita); } incidentalitaStandard.put(provincia + "." + patrimonialita + "." + anno, incidenti.doubleValue()); } } } finally { featureReader.close(); } }
From source file:org.eobjects.datacleaner.widgets.result.NumberAnalyzerResultSwingRenderer.java
@Override protected void decorate(NumberAnalyzerResult result, DCTable table, final DisplayChartCallback displayChartCallback) { // find the std. deviation row number. int rowNumber = -1; {// w w w . j a v a 2 s . c om for (int i = 0; i < table.getRowCount(); i++) { Object value = table.getValueAt(i, 0); if (NumberAnalyzer.MEASURE_STANDARD_DEVIATION.equals(value)) { rowNumber = i; break; } } if (rowNumber == -1) { throw new IllegalStateException("Could not determine Std. deviation row number!"); } } Crosstab<?> crosstab = result.getCrosstab(); final InputColumn<? extends Number>[] columns = result.getColumns(); int columnNumber = 1; for (final InputColumn<? extends Number> column : columns) { final CrosstabNavigator<?> nav = crosstab.where(NumberAnalyzer.DIMENSION_COLUMN, column.getName()); final Number numRows = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_ROW_COUNT).get(); if (numRows.intValue() > 0) { final Number standardDeviation = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_STANDARD_DEVIATION).get(); if (standardDeviation != null) { ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Number mean = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_MEAN).get(); final Number min = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_LOWEST_VALUE) .get(); final Number max = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_HIGHEST_VALUE) .get(); final NormalDistributionFunction2D normalDistributionFunction = new NormalDistributionFunction2D( mean.doubleValue(), standardDeviation.doubleValue()); final XYDataset dataset = DatasetUtilities.sampleFunction2D(normalDistributionFunction, min.doubleValue(), max.doubleValue(), 100, "Normal"); final JFreeChart chart = ChartFactory.createXYLineChart( "Normal distribution of " + column.getName(), column.getName(), "", dataset, PlotOrientation.VERTICAL, false, true, false); ChartUtils.applyStyles(chart); Marker meanMarker = new ValueMarker(mean.doubleValue(), WidgetUtils.BG_COLOR_BLUE_DARK, new BasicStroke(2f)); meanMarker.setLabel("Mean"); meanMarker.setLabelOffset(new RectangleInsets(70d, 25d, 0d, 0d)); meanMarker.setLabelFont(WidgetUtils.FONT_SMALL); chart.getXYPlot().addDomainMarker(meanMarker); final ChartPanel chartPanel = new ChartPanel(chart); displayChartCallback.displayChart(chartPanel); } }; DCPanel panel = AbstractCrosstabResultSwingRenderer.createActionableValuePanel( standardDeviation, Alignment.RIGHT, action, "images/chart-types/line.png"); table.setValueAt(panel, rowNumber, columnNumber); } } columnNumber++; } super.decorate(result, table, displayChartCallback); }
From source file:org.datacleaner.widgets.result.NumberAnalyzerResultSwingRenderer.java
@Override protected void decorate(NumberAnalyzerResult result, DCTable table, final DisplayChartCallback displayChartCallback) { // find the std. deviation row number. int rowNumber = -1; {//from w w w . j av a 2s .co m for (int i = 0; i < table.getRowCount(); i++) { Object value = table.getValueAt(i, 0); if (NumberAnalyzer.MEASURE_STANDARD_DEVIATION.equals(value)) { rowNumber = i; break; } } if (rowNumber == -1) { throw new IllegalStateException("Could not determine Std. deviation row number!"); } } Crosstab<?> crosstab = result.getCrosstab(); final InputColumn<? extends Number>[] columns = result.getColumns(); int columnNumber = 1; for (final InputColumn<? extends Number> column : columns) { final CrosstabNavigator<?> nav = crosstab.where(NumberAnalyzer.DIMENSION_COLUMN, column.getName()); final Number numRows = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_ROW_COUNT).get(); if (numRows.intValue() > 0) { final Number standardDeviation = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_STANDARD_DEVIATION).get(); if (standardDeviation != null) { ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Number mean = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_MEAN).get(); final Number min = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_LOWEST_VALUE) .get(); final Number max = (Number) nav .where(NumberAnalyzer.DIMENSION_MEASURE, NumberAnalyzer.MEASURE_HIGHEST_VALUE) .get(); final NormalDistributionFunction2D normalDistributionFunction = new NormalDistributionFunction2D( mean.doubleValue(), standardDeviation.doubleValue()); final XYDataset dataset = DatasetUtilities.sampleFunction2D(normalDistributionFunction, min.doubleValue(), max.doubleValue(), 100, "Normal"); final JFreeChart chart = ChartFactory.createXYLineChart( "Normal distribution of " + column.getName(), column.getName(), "", dataset, PlotOrientation.VERTICAL, false, true, false); ChartUtils.applyStyles(chart); Marker meanMarker = new ValueMarker(mean.doubleValue(), WidgetUtils.BG_COLOR_BLUE_DARK, new BasicStroke(2f)); meanMarker.setLabel("Mean"); meanMarker.setLabelOffset(new RectangleInsets(70d, 25d, 0d, 0d)); meanMarker.setLabelFont(WidgetUtils.FONT_SMALL); chart.getXYPlot().addDomainMarker(meanMarker); final ChartPanel chartPanel = ChartUtils.createPanel(chart, true); displayChartCallback.displayChart(chartPanel); } }; DCPanel panel = AbstractCrosstabResultSwingRenderer.createActionableValuePanel( standardDeviation, Alignment.RIGHT, action, IconUtils.CHART_LINE); table.setValueAt(panel, rowNumber, columnNumber); } } columnNumber++; } super.decorate(result, table, displayChartCallback); }