List of usage examples for java.text NumberFormat getInstance
public static NumberFormat getInstance(Locale inLocale)
From source file:org.netxilia.api.impl.value.NumberParser.java
/** * Fetches one or more NumberFormat instances that can be used to parse numbers for the current locale. The default * implementation returns two instances, one regular NumberFormat and a currency instance of NumberFormat. * /*from ww w .ja va 2s . c o m*/ * @return one or more NumberFormats to use in parsing numbers */ protected NumberFormat[] getNumberFormats() { return new NumberFormat[] { NumberFormat.getInstance(this.locale) }; }
From source file:com.nextgis.glviewer.MapFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivity = (MainActivity) getActivity(); mMapGlView = new MapGlView(mActivity); mMapGlView.setId(R.id.gl_map_view);//from w w w.j ava 2 s.co m NumberFormat f = NumberFormat.getInstance(Locale.getDefault()); mTimeFormat = null; if (f instanceof DecimalFormat) { mTimeFormat = (DecimalFormat) f; mTimeFormat.setGroupingUsed(true); mTimeFormat.setDecimalSeparatorAlwaysShown(true); mTimeFormat.setMinimumFractionDigits(3); mTimeFormat.setMaximumFractionDigits(3); } f = NumberFormat.getInstance(Locale.getDefault()); mCountFormat = null; if (f instanceof DecimalFormat) { mCountFormat = (DecimalFormat) f; mCountFormat.setGroupingUsed(true); mCountFormat.setDecimalSeparatorAlwaysShown(false); } }
From source file:org.openmrs.notification.web.controller.AlertFormController.java
/** * Allows for Integers to be used as values in input tags. Normally, only strings and lists are * expected//from w w w . j a v a 2 s.co m * * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest, * org.springframework.web.bind.ServletRequestDataBinder) */ protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); Locale locale = Context.getLocale(); NumberFormat nf = NumberFormat.getInstance(locale); // NumberFormat nf = NumberFormat.getInstance(new Locale("en_US")); binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true)); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10)); }
From source file:org.openmrs.module.hr.web.controller.JobTitleController.java
@InitBinder public void initBinder(WebDataBinder binder) { NumberFormat nf = NumberFormat.getInstance(Context.getLocale()); binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true)); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10)); binder.registerCustomEditor(org.openmrs.Concept.class, new ConceptEditor()); binder.registerCustomEditor(Location.class, new LocationEditor()); }
From source file:com.payu.sdk.helper.SignatureHelper.java
/** * The message the signature will use/*from w ww . ja va 2 s .com*/ * * @param order The order that will have the signature * @param merchantId The merchantId into the signature * @param key The apiKey of the merchant * @param valueFormat The format to use for decimal values * @return the message that will go into the signature */ private static String buildMessage(Order order, Integer merchantId, String key, String valueFormat) { validateOrder(order, merchantId); DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US); df.applyPattern(valueFormat); StringBuilder message = new StringBuilder(); message.append(key); message.append("~"); message.append(merchantId); message.append("~"); message.append(order.getReferenceCode()); message.append("~"); message.append(df.format(order.getAdditionalValue(TX_VALUE).getValue().doubleValue())); message.append("~"); message.append(order.getAdditionalValue(TX_VALUE).getCurrency().toString()); return message.toString(); }
From source file:au.com.onegeek.lambda.core.provider.WebDriverBackedSeleniumProvider.java
public void sleep(String wait) throws InterruptedException, ParseException { NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); Number number = format.parse(wait); this.sleep(number.intValue()); }
From source file:org.optaplanner.benchmark.impl.statistic.memoryuse.MemoryUseProblemStatistic.java
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Memory"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { XYSeries usedSeries = new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " used"); // TODO enable max memory, but in the same color as used memory, but with a dotted line instead // XYSeries maxSeries = new XYSeries( // singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " max"); XYItemRenderer renderer = new XYLineAndShapeRenderer(); if (singleBenchmarkResult.isSuccess()) { MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (MemoryUseStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement(); usedSeries.add(timeMillisSpent, memoryUseMeasurement.getUsedMemory()); // maxSeries.add(timeMillisSpent, memoryUseMeasurement.getMaxMemory()); }/* w w w. ja v a 2 s.c o m*/ } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(usedSeries); // seriesCollection.addSeries(maxSeries); plot.setDataset(seriesIndex, seriesCollection); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); // renderer.setSeriesStroke(1, new BasicStroke(2.0f)); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " memory use statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MemoryUseStatistic"); }
From source file:org.optaplanner.benchmark.impl.statistic.calculatecount.CalculateCountProblemStatistic.java
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Calculate count per second"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { XYSeries series = new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix()); XYItemRenderer renderer = new XYLineAndShapeRenderer(); if (singleBenchmarkResult.isSuccess()) { CalculateCountSingleStatistic singleStatistic = (CalculateCountSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (CalculateCountStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); long calculateCountPerSecond = point.getCalculateCountPerSecond(); series.add(timeMillisSpent, calculateCountPerSecond); }//from w w w. j a v a 2s.c o m } plot.setDataset(seriesIndex, new XYSeriesCollection(series)); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " calculate count statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "CalculateCountStatistic"); }
From source file:org.optaplanner.benchmark.impl.statistic.bestsolutionmutation.BestSolutionMutationProblemStatistic.java
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Best solution mutation count"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(true); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { XYSeries series = new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix()); XYItemRenderer renderer = new XYLineAndShapeRenderer(); if (singleBenchmarkResult.isSuccess()) { BestSolutionMutationSingleStatistic singleStatistic = (BestSolutionMutationSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (BestSolutionMutationStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); long mutationCount = point.getMutationCount(); series.add(timeMillisSpent, mutationCount); }/*ww w . j av a 2 s .co m*/ } plot.setDataset(seriesIndex, new XYSeriesCollection(series)); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " best solution mutation statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "BestSolutionMutationStatistic"); }
From source file:org.ng200.openolympus.controller.api.VerdictJSONController.java
@RequestMapping("/api/verdict") public @ResponseBody Map<String, Object> showVerdict(@RequestParam(value = "id") final Verdict verdict, final Locale locale) { if (this.contestService.getRunningContest() != null && !verdict.isViewableWhenContestRunning()) { throw new ForbiddenException("security.contest.cantAccessDuringContest"); }/* w ww.ja v a2 s . c om*/ Assertions.resourceExists(verdict); final HashMap<String, Object> response = new HashMap<>(); response.put("id", Long.toString(verdict.getId())); response.put("score", verdict.getScore().toString()); response.put("maximumScore", verdict.getMaximumScore().toString()); response.put("cpuTime", verdict.getCpuTime() >= 0 ? Long.toString(verdict.getCpuTime()) : "-"); response.put("realTime", verdict.getRealTime() >= 0 ? Long.toString(verdict.getRealTime()) : "-"); response.put("memoryPeak", verdict.getMemoryPeak() >= 0 ? NumberFormat.getInstance(locale).format(verdict.getMemoryPeak()) : "-"); response.put("message", this.messageSource.getMessage(verdict.getMessage(), new Object[] { verdict.getAdditionalInformation(), verdict.getUnauthorisedSyscall() }, "TRANSLATION ERROR", locale)); response.put("tested", Boolean.toString(verdict.isTested())); response.put("success", Boolean.toString(verdict.getScore().signum() > 0)); return response; }