List of usage examples for java.text NumberFormat getInstance
public static NumberFormat getInstance(Locale inLocale)
From source file:easyJ.common.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a double primitive. * // w ww. j a va 2s . c o m * @param value * The value validation is being performed on. * @param locale * The locale to use to parse the number (system default if * null) * @return the converted Double value. */ public static Double formatDouble(String value, Locale locale) { Double result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getInstance(locale); } else { formatter = NumberFormat.getInstance(Locale.getDefault()); } ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= (Double.MAX_VALUE * -1) && num.doubleValue() <= Double.MAX_VALUE) { result = new Double(num.doubleValue()); } } } return result; }
From source file:org.optaplanner.benchmark.impl.statistic.single.constraintmatchtotalbestscore.ConstraintMatchTotalBestScoreSingleStatistic.java
private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Constraint match total weight level " + scoreLevelIndex); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); return plot;//from w w w .jav a2 s . co m }
From source file:com.lloydtorres.stately.helpers.SparkleHelper.java
/** * Returns a number formatted like so: ###,###.## (i.e. US formatting). * @param i number to format (can be int, double or long) * @return The properly-formatted number as a string. */// w w w . java 2 s.com public static String getPrettifiedNumber(int i) { return NumberFormat.getInstance(Locale.US).format(i); }
From source file:com.lloydtorres.stately.helpers.SparkleHelper.java
public static String getPrettifiedNumber(double d) { return NumberFormat.getInstance(Locale.US).format(d); }
From source file:com.lloydtorres.stately.helpers.SparkleHelper.java
public static String getPrettifiedNumber(long l) { return NumberFormat.getInstance(Locale.US).format(l); }
From source file:org.optaplanner.benchmark.impl.report.BenchmarkReport.java
private void writeBestScoreSummaryCharts() { // Each scoreLevel has it's own dataset and chartFile List<DefaultCategoryDataset> datasetList = new ArrayList<DefaultCategoryDataset>(CHARTED_SCORE_LEVEL_SIZE); for (SolverBenchmarkResult solverBenchmarkResult : plannerBenchmarkResult.getSolverBenchmarkResultList()) { String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix(); for (SingleBenchmarkResult singleBenchmarkResult : solverBenchmarkResult .getSingleBenchmarkResultList()) { String planningProblemLabel = singleBenchmarkResult.getProblemBenchmarkResult().getName(); if (singleBenchmarkResult.isSuccess()) { double[] levelValues = ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getScore()); for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= datasetList.size()) { datasetList.add(new DefaultCategoryDataset()); }/*from www . j av a 2 s .c om*/ datasetList.get(i).addValue(levelValues[i], solverLabel, planningProblemLabel); } } } } bestScoreSummaryChartFileList = new ArrayList<File>(datasetList.size()); int scoreLevelIndex = 0; for (DefaultCategoryDataset dataset : datasetList) { CategoryPlot plot = createBarChartPlot(dataset, "Score level " + scoreLevelIndex, NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart("Best score level " + scoreLevelIndex + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); bestScoreSummaryChartFileList .add(writeChartToImageFile(chart, "bestScoreSummaryLevel" + scoreLevelIndex)); scoreLevelIndex++; } }
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * Build a JPanel with a histogram plot of a desmoJ histogramAccumulate dataset * In the case histogram.getShowTimeSpansInReport() the data values are interpreted as * a timespan in a appropriate time unit. * @param histogram desmoJ histogramAccumulate dataset * @return// www. j av a 2s. c o m */ private JPanel getHistogramAccumulatePlot(HistogramAccumulate histogram) { JFreeChart chart; NumberFormat formatter = NumberFormat.getInstance(locale); HistogramDataSetAdapter dataSet = new HistogramDataSetAdapter(histogram, locale); String title = histogram.getName(); if (histogram.getDescription() != null) title = histogram.getDescription(); String xLabel = dataSet.getCategoryAxisLabel(); String yLabel = dataSet.getObservationAxisLabel(); chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataSet, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setBaseItemLabelsVisible(true); StandardCategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", formatter); barrenderer.setBaseItemLabelGenerator(generator); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setMaximumCategoryLabelLines(4); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setNumberFormatOverride(formatter); return new ChartPanel(chart); }
From source file:com.skubit.satoshidice.placebet.PlaceBetFragment.java
private void updatePayoutField() { String text = mPayoutEdit.getText().toString(); String payoutStr = text.isEmpty() ? "64290" : text.toString(); NumberFormat format = NumberFormat.getInstance(Locale.getDefault()); Number number;/*from w w w . j ava 2 s . c om*/ try { number = format.parse(payoutStr); } catch (ParseException e) { e.printStackTrace(); return; } BetParameters bp = BetParameters.calculateWithPayoutMultiple(number.doubleValue()); mSeekbar.setProgress(bp.getNumberToRollUnder()); setTextFields(bp); }
From source file:de.dekarlab.moneybuilder.view.AnalyticsView.java
/** * Create pie chart.//from w ww . j a va 2 s . c o m * * @param dataset * @param title * @return */ protected JFreeChart createBarChart(final CategoryDataset dataset, final String title) { final JFreeChart chart = ChartFactory.createBarChart("", // chart title App.getGuiProp("report.period.lbl"), // domain axis label App.getGuiProp("report.value.lbl"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls ); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setNoDataMessage(App.getGuiProp("report.nodata.msg")); plot.setBackgroundPaint(Color.white); ((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(false); ((CategoryAxis) plot.getDomainAxis()).setMaximumCategoryLabelLines(10); ((CategoryAxis) plot.getDomainAxis()).setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlinesVisible(true); plot.setRangeZeroBaselinePaint(Color.black); plot.setRangeZeroBaselineVisible(true); int color = 0; ((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter()); CategoryItemRenderer renderer = plot.getRenderer(); for (int ser = 0; ser < dataset.getColumnCount(); ser++) { renderer.setSeriesPaint(ser, COLORS[color]); renderer.setSeriesItemLabelGenerator(ser, new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance(Locale.GERMAN))); renderer.setSeriesItemLabelsVisible(ser, true); color++; if (COLORS.length == color) { color = 0; } } return chart; }
From source file:org.drools.planner.benchmark.core.report.BenchmarkReport.java
private void writeBestScoreScalabilitySummaryChart() { // Each scoreLevel has it's own dataset and chartFile List<List<XYSeries>> seriesListList = new ArrayList<List<XYSeries>>(CHARTED_SCORE_LEVEL_SIZE); int solverBenchmarkIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getNameWithFavoriteSuffix(); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale(); double[] levelValues = singleBenchmark.getScore().toDoubleLevels(); for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= seriesListList.size()) { seriesListList//from ww w . j ava 2s .com .add(new ArrayList<XYSeries>(plannerBenchmark.getSolverBenchmarkList().size())); } List<XYSeries> seriesList = seriesListList.get(i); if (solverBenchmarkIndex >= seriesList.size()) { seriesList.add(new XYSeries(solverLabel)); } seriesList.get(solverBenchmarkIndex).add((double) problemScale, levelValues[i]); } } } solverBenchmarkIndex++; } bestScoreScalabilitySummaryChartFileList = new ArrayList<File>(seriesListList.size()); int scoreLevelIndex = 0; for (List<XYSeries> seriesList : seriesListList) { XYPlot plot = createScalabilityPlot(seriesList, "Score level " + scoreLevelIndex, NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart( "Best score scalability level " + scoreLevelIndex + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); bestScoreScalabilitySummaryChartFileList .add(writeChartToImageFile(chart, "bestScoreScalabilitySummaryLevel" + scoreLevelIndex)); scoreLevelIndex++; } }