List of usage examples for java.text NumberFormat getInstance
public static NumberFormat getInstance(Locale inLocale)
From source file:de.betterform.xml.xforms.ui.AbstractFormControl.java
private BigDecimal strictParse(String value, Locale locale) throws ParseException { DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale); format.setParseBigDecimal(true);/*from www .j ava2s. c o m*/ value = value.trim(); ParsePosition pos = new ParsePosition(0); BigDecimal number = (BigDecimal) format.parse(value, pos); boolean okay = pos.getIndex() == value.length() && pos.getErrorIndex() == -1; if (!okay) throw new ParseException("Could not parse '" + value + "' as a number", pos.getErrorIndex()); return number; }
From source file:org.drools.planner.benchmark.core.statistic.BenchmarkReport.java
private void writeScalabilitySummaryChart() { NumberAxis xAxis = new NumberAxis("Problem scale"); xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); NumberAxis yAxis = new NumberAxis("Time spend"); yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale(); long timeMillisSpend = singleBenchmark.getTimeMillisSpend(); series.add((Long) problemScale, (Long) timeMillisSpend); }/*from ww w .j a v a2 s. c om*/ } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); // Use dashed line renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); scalabilitySummaryChartFile = writeChartToImageFile(chart, "scalabilitySummary"); }
From source file:dbs_project.storage.performance.StorageTest.java
private/* static */void outputTime(String testCaseName, int scale, long nanoTime) { String timeString = NumberFormat.getInstance(Locale.US).format(nanoTime / 1000d / 1000d / 1000d); Utils.getOut().println("\tTime: " + timeString + " seconds"); scaleResults.add("<measurement><name>" + testCaseName + "</name>" + "<scale>" + scale + "</scale>" + "<value>" + timeString + "</value></measurement>"); }
From source file:org.optaplanner.benchmark.impl.report.BenchmarkReport.java
private void writeWinningScoreDifferenceSummaryChart() { // 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.getWinningScoreDifference()); for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) { if (i >= datasetList.size()) { datasetList.add(new DefaultCategoryDataset()); }/*ww w. jav a2s. c o m*/ datasetList.get(i).addValue(levelValues[i], solverLabel, planningProblemLabel); } } } } winningScoreDifferenceSummaryChartFileList = new ArrayList<File>(datasetList.size()); int scoreLevelIndex = 0; for (DefaultCategoryDataset dataset : datasetList) { CategoryPlot plot = createBarChartPlot(dataset, "Winning score difference level " + scoreLevelIndex, NumberFormat.getInstance(locale)); JFreeChart chart = new JFreeChart( "Winning score difference level " + scoreLevelIndex + " summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); winningScoreDifferenceSummaryChartFileList .add(writeChartToImageFile(chart, "winningScoreDifferenceSummaryLevel" + scoreLevelIndex)); scoreLevelIndex++; } }
From source file:dk.dma.msinm.legacy.nm.NmPdfExtractor.java
/** * Reads and updates the locations from the line * @param locLine the line containing the locations * @param lang the language/* www . jav a 2 s . c o m*/ * @param notice the notice to update */ void readLocation(String locLine, String lang, Message notice) { NumberFormat format = NumberFormat.getInstance(Locale.FRANCE); String posPattern = "(\\d+)I?\\s+(\\d+,?\\d+)J?\\s+(N|S)\\s+(\\d+)I?\\s+(\\d+,?\\d+)J?\\s+(E|W),?(.*)"; Pattern p1 = Pattern.compile(posPattern); Pattern p2 = Pattern.compile("(\\d+)\\)\\s+" + posPattern); Location location = new Location(); String[] lines = locLine.split("\n"); for (int x = 0; x < lines.length; x++) { String line = lines[x].trim(); if (line.endsWith(".")) { line = line.substring(0, line.length() - 1); } Matcher m1 = p1.matcher(line); Matcher m2 = p2.matcher(line); if (m1.matches() || m2.matches()) { Point pt = new Point(); pt.setLocation(location); try { int i = 1; Matcher m; if (m1.matches()) { m = m1; pt.setIndex(x + 1); } else { m = m2; pt.setIndex(Integer.valueOf(m.group(i++))); } pt.setLat(parsePos(Integer.parseInt(m.group(i++)), format.parse(m.group(i++)).doubleValue(), m.group(i++))); pt.setLon(parsePos(Integer.parseInt(m.group(i++)), format.parse(m.group(i++)).doubleValue(), m.group(i++))); String desc = m.group(i).trim(); if (StringUtils.isNotBlank(desc)) { pt.checkCreateDesc(lang).setDescription(desc); } } catch (ParseException e) { e.printStackTrace(); } location.getPoints().add(pt); } else { log.warn("No match " + lines[x]); } } if (location.getPoints().size() > 0) { location.setType(location.getPoints().size() == 1 ? Location.LocationType.POINT : (location.getPoints().size() == 2 ? Location.LocationType.POLYLINE : Location.LocationType.POLYGON)); notice.getLocations().add(location); } }
From source file:org.drools.planner.benchmark.core.statistic.BenchmarkReport.java
private void writeAverageCalculateCountPerSecondSummaryChart() { NumberAxis xAxis = new NumberAxis("Problem scale"); xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); NumberAxis yAxis = new NumberAxis("Average calculate count per second"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); int seriesIndex = 0; for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { String solverLabel = solverBenchmark.getNameWithFavoriteSuffix(); XYSeries series = new XYSeries(solverLabel); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale(); long averageCalculateCountPerSecond = singleBenchmark.getAverageCalculateCountPerSecond(); series.add((Long) problemScale, (Long) averageCalculateCountPerSecond); }//from w w w . j av a 2s .c o m } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series); plot.setDataset(seriesIndex, seriesCollection); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES); // Use dashed line renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); plot.setRenderer(seriesIndex, renderer); seriesIndex++; } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Average calculate count summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); averageCalculateCountSummaryChartFile = writeChartToImageFile(chart, "averageCalculateCountSummary"); }
From source file:com.bdaum.zoom.gps.naming.geonaming.internal.GeoNamesService.java
@Override public double getElevation(double lat, double lon) throws UnknownHostException, HttpException, IOException { NumberFormat usformat = NumberFormat.getInstance(Locale.US); usformat.setMaximumFractionDigits(5); usformat.setGroupingUsed(false);/* ww w .j a v a 2 s.c o m*/ InputStream in = openGeonamesService(NLS.bind("http://api.geonames.org/srtm3?lat={0}&lng={1}", //$NON-NLS-1$ usformat.format(lat), usformat.format(lon))); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String readLine = reader.readLine(); if (readLine == null) return Double.NaN; try { double v = Double.parseDouble(readLine); return (v < -32000) ? Double.NaN : v; } catch (NumberFormatException e) { return Double.NaN; } } }
From source file:com.silverpeas.util.StringUtil.java
/** * Parse a String into a float using the specified locale. */* w w w .j a v a2s .co m*/ * @param value the string to be parsed into a float * @param language the language for defining the locale * @return the float value. * @throws ParseException */ public static float floatValue(String value, String language) throws ParseException { String lang = language; if (!StringUtil.isDefined(language)) { lang = I18NHelper.defaultLanguage; } NumberFormat numberFormat = NumberFormat.getInstance(new Locale(lang)); return numberFormat.parse(value).floatValue(); }
From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java
@Override protected JFreeChart createMeterChart() throws JRException { // Start by creating the plot that will hold the meter MeterPlot chartPlot = new MeterPlot((ValueDataset) getDataset()); JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // Set the shape MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.DIAL : jrPlot.getShapeValue(); switch (shape) { case CHORD:/*from ww w . j a v a 2s .c om*/ chartPlot.setDialShape(DialShape.CHORD); break; case PIE: chartPlot.setDialShape(DialShape.PIE); break; case CIRCLE: chartPlot.setDialShape(DialShape.CIRCLE); break; case DIAL: default: return createDialChart(); } chartPlot.setDialOutlinePaint(Color.BLACK); int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger(); // Set the size of the meter chartPlot.setMeterAngle(meterAngle); // Set the spacing between ticks. I hate the name "tickSize" since to me it // implies I am changing the size of the tick, not the spacing between them. double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble(); chartPlot.setTickSize(tickInterval); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); chartPlot.setTickLabelFont(themeTickLabelFont); // localizing the default format, can be overridden by display.getMask() chartPlot.setTickLabelFormat(NumberFormat.getInstance(getLocale())); Color tickColor = jrPlot.getTickColor() == null ? Color.BLACK : jrPlot.getTickColor(); chartPlot.setTickPaint(tickColor); int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { // Set the meter's range chartPlot.setRange(range); double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); if ((range.getLowerBound() == (int) range.getLowerBound() && range.getUpperBound() == (int) range.getUpperBound() && tickInterval == (int) tickInterval) || dialUnitScale > 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale == 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale <= 0) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale()))); } } chartPlot.setTickLabelsVisible(true); // Set all the colors we support Paint backgroundPaint = jrPlot.getOwnBackcolor() == null ? ChartThemesConstants.TRANSPARENT_PAINT : jrPlot.getOwnBackcolor(); chartPlot.setBackgroundPaint(backgroundPaint); GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false); if (jrPlot.getMeterBackgroundColor() != null) { chartPlot.setDialBackgroundPaint(jrPlot.getMeterBackgroundColor()); } else { chartPlot.setDialBackgroundPaint(gp); } //chartPlot.setForegroundAlpha(1f); Paint needlePaint = jrPlot.getNeedleColor() == null ? new Color(191, 48, 0) : jrPlot.getNeedleColor(); chartPlot.setNeedlePaint(needlePaint); JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { Color valueColor = display.getColor() == null ? Color.BLACK : display.getColor(); chartPlot.setValuePaint(valueColor); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) chartPlot.setTickLabelFormat( new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); JRFont displayFont = display.getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); if (themeDisplayFont != null) { chartPlot.setValueFont(themeDisplayFont); } } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); } // Set the units - this is just a string that will be shown next to the // value String units = jrPlot.getUnits() == null ? label : jrPlot.getUnits(); if (units != null && units.length() > 0) chartPlot.setUnits(units); chartPlot.setTickPaint(Color.BLACK); // Now define all of the intervals, setting their range and color List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); interval.setBackgroundColor(color); interval.setAlpha(1.0d); chartPlot.addInterval(convertInterval(interval)); } } // Actually create the chart around the plot JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java
private Object doConvertToNumber(Map<String, Object> context, Object value, Class toType) { if (value instanceof String) { if (toType == BigDecimal.class) { return new BigDecimal((String) value); } else if (toType == BigInteger.class) { return new BigInteger((String) value); } else if (toType.isPrimitive()) { Object convertedValue = super.convertValue(context, value, toType); String stringValue = (String) value; if (!isInRange((Number) convertedValue, stringValue, toType)) throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + convertedValue.getClass().getName()); return convertedValue; } else {// w w w . jav a 2 s . c om String stringValue = (String) value; if (!toType.isPrimitive() && (stringValue == null || stringValue.length() == 0)) { return null; } NumberFormat numFormat = NumberFormat.getInstance(getLocale(context)); ParsePosition parsePos = new ParsePosition(0); if (isIntegerType(toType)) { numFormat.setParseIntegerOnly(true); } numFormat.setGroupingUsed(true); Number number = numFormat.parse(stringValue, parsePos); if (parsePos.getIndex() != stringValue.length()) { throw new XWorkException( "Unparseable number: \"" + stringValue + "\" at position " + parsePos.getIndex()); } else { if (!isInRange(number, stringValue, toType)) throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + number.getClass().getName()); value = super.convertValue(context, number, toType); } } } else if (value instanceof Object[]) { Object[] objArray = (Object[]) value; if (objArray.length == 1) { return doConvertToNumber(context, objArray[0], toType); } } // pass it through DefaultTypeConverter return super.convertValue(context, value, toType); }