List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:net.imglib2.script.analysis.Histogram.java
/** Return the JFreeChart with this histogram, and as a side effect, show it in a JFrame * that provides the means to edit the dimensions and also the plot properties via a popup menu. */ public JFreeChart asChart(final boolean show) { double[] d = new double[this.size()]; int i = 0;/*w ww .j a v a 2 s.com*/ for (Number num : this.values()) d[i++] = num.doubleValue(); HistogramDataset hd = new HistogramDataset(); hd.setType(HistogramType.RELATIVE_FREQUENCY); String title = "Histogram"; hd.addSeries(title, d, d.length); JFreeChart chart = ChartFactory.createHistogram(title, "", "", hd, PlotOrientation.VERTICAL, false, false, false); setTheme(chart); if (show) { JFrame frame = new JFrame(title); frame.getContentPane().add(new ChartPanel(chart)); frame.pack(); frame.setVisible(true); } return chart; }
From source file:com.glaf.core.util.GetterUtils.java
public static double get(Object value, double defaultValue) { if (value == null) { return defaultValue; }/*from w w w .j av a2 s . c o m*/ if (value instanceof String) { return get((String) value, defaultValue); } Class<?> clazz = value.getClass(); if (Double.class.isAssignableFrom(clazz)) { return (Double) value; } if (value instanceof Number) { Number number = (Number) value; return number.doubleValue(); } return defaultValue; }
From source file:com.adobe.acs.commons.mcp.impl.GenericReportExcelServlet.java
@SuppressWarnings("squid:S3776") private Workbook createSpreadsheet(GenericReport report) { Workbook wb = new XSSFWorkbook(); String name = report.getName(); for (char ch : new char[] { '\\', '/', '*', '[', ']', ':', '?' }) { name = StringUtils.remove(name, ch); }/* w ww.j av a 2s. c o m*/ Sheet sheet = wb.createSheet(name); sheet.createFreezePane(0, 1, 0, 1); Row headerRow = sheet.createRow(0); CellStyle headerStyle = createHeaderStyle(wb); for (int c = 0; c < report.getColumnNames().size(); c++) { Cell headerCell = headerRow.createCell(c); headerCell.setCellValue(report.getColumnNames().get(c)); headerCell.setCellStyle(headerStyle); } List<ValueMap> rows = report.getRows(); //make rows, don't forget the header row for (int r = 0; r < rows.size(); r++) { Row row = sheet.createRow(r + 1); //make columns for (int c = 0; c < report.getColumns().size(); c++) { String col = report.getColumns().get(c); Cell cell = row.createCell(c); if (rows.get(r).containsKey(col)) { Object val = rows.get(r).get(col); if (val instanceof Number) { Number n = (Number) val; cell.setCellValue(n.doubleValue()); } else { String sval = String.valueOf(val); if (sval.startsWith("=")) { cell.setCellFormula(sval.substring(1)); } else { cell.setCellValue(sval); } } } } } int lastColumnIndex = report.getColumnNames().size(); autosize(sheet, lastColumnIndex); sheet.setAutoFilter(new CellRangeAddress(0, 1 + rows.size(), 0, lastColumnIndex - 1)); return wb; }
From source file:edu.emory.library.tast.database.graphs.GraphTypeXY.java
public JFreeChart createChart(Object[] data) { CategoryTableXYDataset dataset = new CategoryTableXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);//from w w w . jav a 2 s . co m Format formatter = getSelectedIndependentVariable().getFormat(); XYPlot plot = chart.getXYPlot(); if (formatter != null) ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride((NumberFormat) formatter); chart.setBackgroundPaint(Color.white); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; Number x = (Number) row[0]; Number y = (Number) row[j + 1]; if (x != null && y != null) dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel); } } LegendItemCollection legendItems = chart.getPlot().getLegendItems(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem legendItem = legendItems.get(i); DataSeries dataSearies = (DataSeries) allDataSeries.get(i); if (legendItem.getFillPaint() instanceof Color) { dataSearies.setColor(((Color) legendItem.getFillPaint())); } } return chart; }
From source file:com.microsoft.azure.management.datalake.store.uploader.UploadMetadataGeneratorTests.java
@Test public void UploadMetadataGenerator_AlignSegmentsToRecordBoundaries() throws IOException, UploadFailedException, InvalidMetadataException { //We keep creating a file, by appending a number of bytes to it (taken from FileLengthsInMB). //At each iteration, we append a new blob of data, and then run the whole test on the entire file Random rnd = new Random(0); File folderPath = new File(MessageFormat.format("{0}\\uploadtest", new File(".").getAbsoluteFile())); File filePath = new File(folderPath, "verifymetadata.txt"); try {/*from w w w . ja v a 2s . com*/ if (!folderPath.exists()) { folderPath.mkdirs(); } if (filePath.exists()) { filePath.delete(); } for (Number lengthMB : FileLengthsMB) { int appendLength = (int) (lengthMB.doubleValue() * 1024 * 1024); AppendToFile(filePath.getAbsolutePath(), appendLength, rnd, 0, MaxAppendLength); String metadataFilePath = filePath + ".metadata.txt"; UploadParameters up = new UploadParameters(filePath.getAbsolutePath(), filePath.getAbsolutePath(), null, 1, false, false, false, 4 * 1024 * 1024, null); UploadMetadataGenerator mg = new UploadMetadataGenerator(up, MaxAppendLength); UploadMetadata metadata = mg.createNewMetadata(metadataFilePath); VerifySegmentsAreOnRecordBoundaries(metadata, filePath.getAbsolutePath()); } } finally { if (folderPath.exists()) { FileUtils.deleteQuietly(folderPath); } } }
From source file:org.netxilia.api.impl.value.NumberParser.java
@Override public IGenericValue parse(String text) { String input = preprocess(text); ParsePosition pp = new ParsePosition(0); for (NumberFormat format : this.formats) { pp.setIndex(0);/* www. ja v a2s . c o m*/ Number number = format.parse(input, pp); if (number != null && input.length() == pp.getIndex()) { return new NumberValue(number.doubleValue()); } } return null; }
From source file:com.anrisoftware.sscontrol.security.spamassassin.SpamassassinServiceImpl.java
@Override public Double getSpamScore() { Number value = (Number) statementsMap.mapValue(SPAM_KEY, SCORE_KEY); if (value != null) { return value.doubleValue(); } else {/* w ww.java 2s . c o m*/ return null; } }
From source file:com.qcadoo.model.internal.validators.RangeValidator.java
private boolean validateNumberRange(final FieldDefinition fieldDefinition, final Number value, final Entity validatedEntity) { if (from != null && ((!inclusively && value.doubleValue() <= ((Number) from).doubleValue()) || (inclusively && value.doubleValue() < ((Number) from).doubleValue()))) { addToSmallError(fieldDefinition, validatedEntity); return false; }//from w w w . ja va 2s .c om if (to != null && ((!inclusively && value.doubleValue() >= ((Number) to).doubleValue()) || (inclusively && value.doubleValue() > ((Number) to).doubleValue()))) { addToLargeError(fieldDefinition, validatedEntity); return false; } return true; }
From source file:net.sf.dynamicreports.report.builder.condition.AbstractBetweenValueExpression.java
public AbstractBetweenValueExpression(DRIValue<T> value, Number min, Number max) { Validate.notNull(value, "value must not be null"); Validate.notNull(min, "min must not be null"); Validate.notNull(max, "min must not be null"); Validate.isTrue(min.doubleValue() < max.doubleValue(), "min < max"); this.value = value; this.min = min; this.max = max; }
From source file:org.immutables.gson.stream.JsonGeneratorWriter.java
@Override public JsonWriter value(Number value) throws IOException { if (value == null) { return nullValue(); }/*from w w w . j a v a 2 s . c o m*/ double d = value.doubleValue(); if (!isLenient()) { if (Double.isNaN(d) || Double.isInfinite(d)) { throw new IllegalArgumentException("JSON forbids NaN and infinities: " + value); } } generator.writeNumber(d); return this; }