List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols
public DecimalFormatSymbols(Locale locale)
From source file:logdruid.util.DataMiner.java
public static FileMineResult fileMine(FileRecord fileRecord, Repository repo, Source source, boolean stats, boolean timings) { ExtendedTimeSeries ts = null;//from w w w . j a va 2s .co m PatternCache patternCache = new PatternCache(); Date startDate = null; Date endDate = null; DecimalFormat decimalFormat = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.US)); FastDateFormat fastDateFormat = null; FileReader flstr = null; BufferedReader buf1st; Matcher matcher; Matcher matcher2; FixedMillisecond fMS = null; Boolean successMatch = false; DateFormat df = null; int statHit = 0; int statMatch = 0; int eventHit = 0; int eventMatch = 0; long[] arrayBefore; Map<Recording, String> recMatch = new HashMap<Recording, String>(); Map<String, ExtendedTimeSeries> statMap = new HashMap<String, ExtendedTimeSeries>(); Map<String, ExtendedTimeSeries> eventMap = new HashMap<String, ExtendedTimeSeries>(); Map<String, Map<Date, FileLine>> RIFileLineDateMap = new HashMap<String, Map<Date, FileLine>>(); Map<String, long[]> matchTimings = new HashMap<String, long[]>(); long recordingMatchStart = 0; long recordingMatchEnd = 0; try { if (logger.isDebugEnabled()) { logger.debug("++file: " + repo.getBaseSourcePath() + " + " + (String) fileRecord.getCompletePath().toString()); } flstr = new FileReader(fileRecord.getCompletePath()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } buf1st = new BufferedReader(flstr); String line; try { recMatch = getRegexp(repo, source); int lineCount = 1; while ((line = buf1st.readLine()) != null) { // check against one Recording pattern at a tim // if (logger.isDebugEnabled()) { // logger.debug("line " + line); // } Iterator recMatchIte = recMatch.entrySet().iterator(); while (recMatchIte.hasNext()) { if (timings) { recordingMatchStart = ManagementFactory.getThreadMXBean() .getThreadCpuTime(Thread.currentThread().getId()); } Map.Entry me = (Map.Entry) recMatchIte.next(); Recording rec = (Recording) me.getKey(); matcher = patternCache.getPattern((String) (rec.getRegexp())).matcher(line); if (matcher.find()) { Boolean isStatRecording = rec.getClass().equals(StatRecording.class); if (stats) { if (isStatRecording) { statMatch++; } else { eventMatch++; } } // logger.info("1**** matched: " + line); ArrayList<RecordingItem> recordingItem = ((Recording) rec).getRecordingItem(); int cnt = 0; matcher2 = patternCache.getPattern((String) me.getValue()).matcher(line); successMatch = false; if (matcher2.find()) { if (stats) { if (isStatRecording) { statHit++; } else { eventHit++; } } int count = 1; Date date1 = null; // handling capture for each recording item Iterator<RecordingItem> recItemIte2 = recordingItem.iterator(); while (recItemIte2.hasNext()) { RecordingItem recItem2 = recItemIte2.next(); // logger.info("3A**** " + // recItem2.getType()); if (recItem2.getType().equals("date")) { try { df = repo.getDateFormat(rec.getDateFormatID()); if (logger.isDebugEnabled()) logger.debug("4**** rec name" + rec.getName() + " df: " + df.getId()); fastDateFormat = FastDateFormat.getInstance(df.getDateFormat()); date1 = fastDateFormat.parse(matcher2.group(count)); if (logger.isDebugEnabled()) logger.debug( "4b**** " + df.getDateFormat() + " date: " + date1.toString()); // logger.info("4**** " + // date1.toString()); } catch (ParseException e) { // TODO Auto-generated catch // block e.printStackTrace(); } } else if (date1 != null) { if (recItem2.isSelected()) { if (logger.isDebugEnabled()) { logger.debug("FileRecord: " + fileRecord.getFile().getName() + ", Source: " + source.getSourceName() + ", " + recItem2.getName() + ", " + fileRecord.getFile().getName() + ", " + lineCount); } // recording line of match in file in map RIFileLineDateMap - note the FileLine object use an int to identify the files to save memory Map<Date, FileLine> dateFileLineMap = null; if (RIFileLineDateMap.containsKey(recItem2.getName())) { dateFileLineMap = RIFileLineDateMap.get(recItem2.getName()); } else { dateFileLineMap = new HashMap<Date, FileLine>(); } dateFileLineMap.put(date1, new FileLine(fileRecord.getId(), lineCount)); if (logger.isDebugEnabled()) { logger.debug(fileRecord.getFile().getName() + " dateFileLineMap put: " + date1 + "fileLine: " + new FileLine(fileRecord.getId(), lineCount)); logger.debug(fileRecord.getFile().getName() + " FileRecord: " + fileRecord.getFile().getName() + ", RIFileLineDateMap.put: " + recItem2.getName() + ", line: " + lineCount + " RIFileLineDateMap size: " + RIFileLineDateMap.size() + " dateFileLineMap size: " + dateFileLineMap.size()); } RIFileLineDateMap.put(recItem2.getName(), dateFileLineMap); if (startDate == null) { startDate = date1; } if (endDate == null) { endDate = date1; } if (date1.after(startDate)) { endDate = date1; } else if (date1.before(startDate)) { startDate = date1; } if (isStatRecording) { if (statMap.containsKey(recItem2.getName())) { ts = statMap.get(recItem2.getName()); } else { ts = new ExtendedTimeSeries(recItem2.getName(), FixedMillisecond.class); if (logger.isDebugEnabled()) logger.debug( "5**** Adding record to Map: " + recItem2.getName()); } fMS = new FixedMillisecond(date1); if (matcher2.group(count) == null) { logger.info("null in match on " + recItem2.getName() + " at " + fileRecord.getFile().getName() + " line cnt:" + lineCount); logger.info("line : " + line); } try { if (recItem2.getType().equals("long")) { ts.getTimeSeries().addOrUpdate((new TimeSeriesDataItem(fMS, Long.valueOf((String) matcher2.group(count))))); } else { ts.getTimeSeries().addOrUpdate((new TimeSeriesDataItem(fMS, Double.parseDouble(String.valueOf(decimalFormat .parse((String) matcher2.group(count))))))); } } catch (ParseException e) { // TODO Auto-generated catch // block e.printStackTrace(); } if (stats) { //int[] array = { statMatch, statHit }; int[] array = ts.getStat(); array[1] = array[1] + 1; array[0] = array[0] + 1; ts.setStat(array); if (logger.isDebugEnabled()) logger.debug("stats " + array[0] + " " + array[1]); } statMap.put(recItem2.getName(), ts); // performance: add the // TmeSeriesDataItem to the // TimeSeries instead of updating // the TimeSeries in the Map } else { // rec.getClass().equals(EventRecording.class) if (eventMap.containsKey(recItem2.getName())) { ts = eventMap.get(recItem2.getName()); } else { ts = new ExtendedTimeSeries(recItem2.getName(), FixedMillisecond.class); if (logger.isDebugEnabled()) logger.debug( "5**** Adding record to Map: " + recItem2.getName()); } fMS = new FixedMillisecond(date1); if (((RecordingItem) recItem2).getProcessingType() .equals("occurrences")) { TimeSeriesDataItem t = ts.getTimeSeries().getDataItem(fMS); if (t != null) { ts.getTimeSeries() .addOrUpdate((new TimeSeriesDataItem(fMS, 101))); // + // (double)t.getValue() // need some way to show several occurrences } else { ts.getTimeSeries().add((new TimeSeriesDataItem(fMS, 100))); } } else if (((RecordingItem) recItem2).getProcessingType() .equals("sum")) { TimeSeriesDataItem t = ts.getTimeSeries().getDataItem(fMS); if (t != null) { if (!recItem2.getType().equals("date")) { try { ts.getTimeSeries().addOrUpdate((new TimeSeriesDataItem( fMS, Double.parseDouble(String .valueOf(decimalFormat .parse(matcher2.group(count))) + ts.getTimeSeries().getDataItem(fMS) .getValue())))); logger.info( ts.getTimeSeries().getDataItem(fMS).getValue()); } catch (ParseException e) { // TODO // Auto-generated // catch block e.printStackTrace(); } } } else { try { ts.getTimeSeries() .add((new TimeSeriesDataItem(fMS, Double .parseDouble(String.valueOf(decimalFormat .parse(matcher2.group(count))))))); } catch (ParseException e) { // TODO Auto-generated // catch block e.printStackTrace(); } } } else if (((RecordingItem) recItem2).getProcessingType() .equals("capture")) { } else { if (!recItem2.getType().equals("date")) { try { ts.getTimeSeries() .addOrUpdate((new TimeSeriesDataItem(fMS, Double .parseDouble(String.valueOf(decimalFormat .parse(matcher2.group(count))))))); } catch (ParseException e) { // TODO Auto-generated // catch block e.printStackTrace(); } } // ts.addOrUpdate((new // TimeSeriesDataItem(fMS, // 100))); } // logger.debug(recItem2.getName() + // " " + // Double.parseDouble((matcher2.group(count)))); if (stats) { int[] array = ts.getStat(); array[1] = array[1] + 1; array[0] = array[0] + 1; ts.setStat(array); if (logger.isDebugEnabled()) logger.debug("stats " + array[0] + " " + array[1]); } eventMap.put(recItem2.getName(), ts); } } } count++; // logger.info("event statistics: "+eventMatch + // " and " +eventHit + // " ; stat statistics: "+statMatch + " and " // +statHit); } } if (timings) { recordingMatchEnd = ManagementFactory.getThreadMXBean() .getThreadCpuTime(Thread.currentThread().getId()); if (matchTimings.containsKey(rec.getName())) { arrayBefore = matchTimings.get(rec.getName()); // logger.info(file.getName() + " contains " + // arrayBefore); // 0-> sum of time for success matching of given // recording ; 1-> sum of time for failed // matching ; 2-> count of match attempts, // 3->count of success attempts long[] array = { arrayBefore[0] + recordingMatchEnd - recordingMatchStart, arrayBefore[1], arrayBefore[2] + 1, arrayBefore[3] + 1 }; // logger.info(file.getName() + // " add success to" + rec.getName() + " 0: "+ // array[0] + " 1: "+ array[1]+ " 2: "+ array[2] // +" 3: "+ array[3]); matchTimings.put(rec.getName(), array); } else { long[] array = { recordingMatchEnd - recordingMatchStart, 0, 1, 1 }; matchTimings.put(rec.getName(), array); // logger.info(file.getName() + " first success" // + rec.getName() + " 0: "+ array[0] + " 1: "+ // array[1]+ " 2: "+ array[2] +" 3: "+ // array[3]); } } } else { if (timings) { recordingMatchEnd = ManagementFactory.getThreadMXBean() .getThreadCpuTime(Thread.currentThread().getId()); if (matchTimings.containsKey(rec.getName())) { arrayBefore = matchTimings.get(rec.getName()); // 0-> sum of time for success matching of given // recording ; 1-> sum of time for failed // matching ; 2-> count of match attempts, // 3->count of success attempts long[] array = { arrayBefore[0], arrayBefore[1] + recordingMatchEnd - recordingMatchStart, arrayBefore[2] + 1, arrayBefore[3] }; matchTimings.put(rec.getName(), array); } else { long[] array = { 0, recordingMatchEnd - recordingMatchStart, 1, 0 }; matchTimings.put(rec.getName(), array); } } } } lineCount++; // timing } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { buf1st.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /* * if (logger.isInfoEnabled()) { Iterator Ite = * matchTimings.entrySet().iterator(); long successTotalTime=0; long * failedTotalTime=0; // 0-> sum of time for success matching of given * // recording ; 1-> sum of time for failed // matching ; 2-> count of * match attempts, // 3->count of success attempts // long[] array; * while (Ite.hasNext()) { Map.Entry pairs = (Map.Entry) Ite.next(); * long[] array = (long[]) pairs.getValue(); logger.info(file.getName() * + " - "+ pairs.getKey() + " / success all time: " + array[0] + * " failed all time: " + array[1] + " attempt count: " + array[2] + * " success count: " + array[3] + " failed count:" * +(array[2]-array[3])); successTotalTime=successTotalTime+array[0]; * failedTotalTime=failedTotalTime+array[1]; } logger.info("success: " * +successTotalTime + " failed: " + failedTotalTime); Ite = * matchTimings.entrySet().iterator(); while (Ite.hasNext()) { Map.Entry * pairs = (Map.Entry) Ite.next(); long[] array = (long[]) * pairs.getValue(); logger.info(file.getName() + " percents - "+ * pairs.getKey() + " / % success time: " + (( successTotalTime!=0) ? * ((double)((double)array[0] / successTotalTime)*100) : 0 ) + * " % failed time: " + (( failedTotalTime!=0) ?((double)array[1]/ * failedTotalTime)*100 :0) + " attempt cost: " + ((array[2]!=0) ? * ((double)successTotalTime + failedTotalTime ) /array[2]:0 )+ * " success cost: " + ((array[3]!=0) ? ((double)successTotalTime ) * /array[3] : 0) + " failed cost:" + ((array[2]-array[3]!=0) ? * ((double)failedTotalTime/(array[2]-array[3])) : 0) ); } } */ return new FileMineResult(fileRecord, statMap, eventMap, matchTimings, RIFileLineDateMap, startDate, endDate); }
From source file:com.mgmtp.perfload.perfalyzer.PerfAlyzerModule.java
@Provides @FloatFormat//w w w . j a v a2s . c o m NumberFormat provideFloatFormat(final Locale locale) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); NumberFormat nf = new DecimalFormat("0.00", dfs); nf.setGroupingUsed(false); nf.setRoundingMode(RoundingMode.HALF_UP); return nf; }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
public static String summarizeDetailedOccupancyStats(Map<Id<Vehicle>, double[]> vehicleDistances, String del, int maxcap) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1);/* w ww .j av a 2s . com*/ format.setMaximumFractionDigits(2); format.setGroupingUsed(false); double[] sum = new double[maxcap + 1]; for (double[] dist : vehicleDistances.values()) { double emptyD = dist[0] - dist[2]; sum[0] += emptyD; for (int i = 3; i < maxcap + 3; i++) { sum[i - 2] += dist[i]; } } String result = ""; for (int i = 0; i <= maxcap; i++) { result = result + ";" + format.format(sum[i]); } return result; }
From source file:javadz.beanutils.converters.NumberConverter.java
/** * Return a NumberFormat to use for Conversion. * * @return The NumberFormat./*from w w w. ja va 2 s . c o m*/ */ private NumberFormat getFormat() { NumberFormat format = null; if (pattern != null) { if (locale == null) { if (log().isDebugEnabled()) { log().debug(" Using pattern '" + pattern + "'"); } format = new DecimalFormat(pattern); } else { if (log().isDebugEnabled()) { log().debug(" Using pattern '" + pattern + "'" + " with Locale[" + locale + "]"); } DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); format = new DecimalFormat(pattern, symbols); } } else { if (locale == null) { if (log().isDebugEnabled()) { log().debug(" Using default Locale format"); } format = NumberFormat.getInstance(); } else { if (log().isDebugEnabled()) { log().debug(" Using Locale[" + locale + "] format"); } format = NumberFormat.getInstance(locale); } } if (!allowDecimals) { format.setParseIntegerOnly(true); } return format; }
From source file:fr.amap.lidar.RxpScanConversion.java
public void toTxt(SimpleScan scan, File outputDirectory, boolean exportReflectance, boolean exportAmplitude, boolean exportDeviation, boolean exportTime) throws IOException, Exception { /***Convert rxp to txt***/ File outputTxtFile = new File( outputDirectory.getAbsolutePath() + File.separator + scan.file.getName() + ".txt"); try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputTxtFile))) { RxpExtraction extraction = new RxpExtraction(); extraction.openRxpFile(scan.file, RxpExtraction.AMPLITUDE, RxpExtraction.DEVIATION, RxpExtraction.REFLECTANCE, RxpExtraction.TIME); Iterator<Shot> iterator = extraction.iterator(); /**Transformation**/ Mat4D popMatrix = scan.popMatrix; Mat4D sopMatrix = scan.sopMatrix; Mat4D transfMatrix = Mat4D.multiply(sopMatrix, popMatrix); Mat3D rotation = new Mat3D(); rotation.mat = new double[] { transfMatrix.mat[0], transfMatrix.mat[1], transfMatrix.mat[2], transfMatrix.mat[4], transfMatrix.mat[5], transfMatrix.mat[6], transfMatrix.mat[8], transfMatrix.mat[9], transfMatrix.mat[10] }; DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); otherSymbols.setDecimalSeparator('.'); otherSymbols.setGroupingSeparator('.'); DecimalFormat strictFormat = new DecimalFormat("###.##", otherSymbols); String header = "shotID x y z directionX directionY directionZ distance nbEchos rangEcho"; if (exportReflectance) { header += " reflectance"; }/*w w w . j a v a 2 s . c om*/ if (exportAmplitude) { header += " amplitude"; } if (exportDeviation) { header += " deviation"; } if (exportTime) { header += " time"; } header += "\n"; writer.write(header); int shotID = 0; while (iterator.hasNext()) { Shot shot = iterator.next(); Vec4D origin = Mat4D.multiply(transfMatrix, new Vec4D(shot.origin.x, shot.origin.y, shot.origin.z, 1.0d)); Vec3D direction = Mat3D.multiply(rotation, new Vec3D(shot.direction.x, shot.direction.y, shot.direction.z)); direction = Vec3D.normalize(direction); SphericalCoordinates sc = new SphericalCoordinates(); sc.toSpherical(new Vector3d(direction.x, direction.y, direction.z)); for (int i = 0; i < shot.nbEchos; i++) { double x = origin.x + direction.x * shot.ranges[i]; double y = origin.y + direction.y * shot.ranges[i]; double z = origin.z + direction.z * shot.ranges[i]; String echo = shotID + " " + x + " " + y + " " + z + " " + direction.x + " " + direction.y + " " + direction.z + " " + shot.ranges[i] + " " + shot.nbEchos + " " + i; if (exportReflectance) { echo += " " + strictFormat.format(shot.reflectances[i]); } if (exportAmplitude) { echo += " " + strictFormat.format(shot.amplitudes[i]); } if (exportDeviation) { echo += " " + strictFormat.format(shot.deviations[i]); } if (exportTime) { echo += " " + shot.times[i]; } echo += "\n"; writer.write(echo); } shotID++; } extraction.close(); } }
From source file:org.deidentifier.arx.gui.view.SWTUtil.java
/** * Returns a pretty string representing the given double * @param value/*from w w w . j av a 2 s . c om*/ * @return */ public static String getPrettyString(double value) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); if (value == LN2) { return "ln(2)"; } else if (value == LN3) { return "ln(3)"; } else if (value == 0) { return "0"; } else if (Math.abs(value) < 0.00001) { return new DecimalFormat("#.#####E0", symbols).format(value).replace('E', 'e'); } else if (Math.abs(value) < 1) { return new DecimalFormat("#.#####", symbols).format(value); } else if (Math.abs(value) < 100000) { return new DecimalFormat("######.#####", symbols).format(value); } else { return String.valueOf(value).replace('E', 'e'); } }
From source file:py.una.pol.karaku.util.FormatProvider.java
/** * @return/*from w w w.j ava 2 s. co m*/ */ private DecimalFormatSymbols getDFS() { if (this.dfs == null) { this.dfs = new DecimalFormatSymbols(Locale.getDefault()); this.dfs.setDecimalSeparator(','); this.dfs.setGroupingSeparator('.'); } return this.dfs; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final XYPlot plot = chart.getXYPlot(); final XYItemRenderer renderer = plot.getRenderer(); if (StringUtils.isEmpty(getTooltipFormula()) == false) { renderer.setBaseToolTipGenerator(new FormulaXYZTooltipGenerator(getRuntime(), getTooltipFormula())); }/* w w w .ja va 2s . co m*/ if (StringUtils.isEmpty(getUrlFormula()) == false) { renderer.setURLGenerator(new FormulaXYZURLGenerator(getRuntime(), getUrlFormula())); } renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible())); if (getItemLabelFont() != null) { renderer.setBaseItemLabelFont(getItemLabelFont()); } plot.setOrientation(computePlotOrientation()); // May be an axis that supports dates final ValueAxis domainAxis = plot.getDomainAxis(); if (domainAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) domainAxis; numberAxis.setAutoRangeIncludesZero(isDomainIncludesZero()); numberAxis.setAutoRangeStickyZero(isDomainStickyZero()); if (getDomainPeriodCount() > 0) { if (getDomainTickFormat() != null) { numberAxis.setTickUnit(new NumberTickUnit(getDomainPeriodCount(), getDomainTickFormat())); } else if (getDomainTickFormatString() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getDomainTickFormatString(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount())); } } else { if (getDomainTickFormat() != null) { numberAxis.setNumberFormatOverride(getDomainTickFormat()); } else if (getDomainTickFormatString() != null) { final DecimalFormat formatter = new DecimalFormat(getDomainTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (domainAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) domainAxis; if (getDomainPeriodCount() > 0 && getDomainTimePeriod() != null) { if (getDomainTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getDomainTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()), (int) getDomainPeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()), (int) getDomainPeriodCount())); } } } if (domainAxis != null) { domainAxis.setLabel(getDomainTitle()); if (getDomainTitleFont() != null) { domainAxis.setLabelFont(getDomainTitleFont()); } domainAxis.setVerticalTickLabels(isDomainVerticalTickLabels()); if (getDomainTickFont() != null) { domainAxis.setTickLabelFont(getDomainTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getDomainMinimum() != 0) { domainAxis.setLowerBound(getDomainMinimum()); } if (getDomainMaximum() != 1) { domainAxis.setUpperBound(getDomainMaximum()); } if (getDomainMinimum() == 0 && getDomainMaximum() == 0) { domainAxis.setLowerBound(0); domainAxis.setUpperBound(1); domainAxis.setAutoRange(true); } } else { domainAxis.setLowerBound(getDomainMinimum()); domainAxis.setUpperBound(getDomainMaximum()); domainAxis.setAutoRange(isDomainAxisAutoRange()); } } final ValueAxis rangeAxis = plot.getRangeAxis(); if (rangeAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero()); numberAxis.setAutoRangeStickyZero(isRangeStickyZero()); if (getRangePeriodCount() > 0) { if (getRangeTickFormat() != null) { numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat())); } else if (getRangeTickFormatString() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount())); } } else { if (getRangeTickFormat() != null) { numberAxis.setNumberFormatOverride(getRangeTickFormat()); } else if (getRangeTickFormatString() != null) { final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); standardTickUnitsApplyFormat(numberAxis, formatter); } } } else if (rangeAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) rangeAxis; if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) { if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit( new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount())); } } else { if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } } if (rangeAxis != null) { rangeAxis.setLabel(getRangeTitle()); if (getRangeTitleFont() != null) { rangeAxis.setLabelFont(getRangeTitleFont()); } if (getRangeTickFont() != null) { rangeAxis.setTickLabelFont(getRangeTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { rangeAxis.setLowerBound(getRangeMinimum()); } if (getRangeMaximum() != 1) { rangeAxis.setUpperBound(getRangeMaximum()); } if (getRangeMinimum() == 0 && getRangeMaximum() == 0) { rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(1); rangeAxis.setAutoRange(true); } } else { rangeAxis.setLowerBound(getRangeMinimum()); rangeAxis.setUpperBound(getRangeMaximum()); rangeAxis.setAutoRange(isRangeAxisAutoRange()); } } final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, parseColorFromString(colors[i])); } }
From source file:PrintfFormat.java
/** * Constructs an array of control specifications possibly preceded, * separated, or followed by ordinary strings. Control strings begin with * unpaired percent signs. A pair of successive percent signs designates a * single percent sign in the format.//from w w w . j a v a2s .com * * @param fmtArg * Control string. * @exception IllegalArgumentException * if the control string is null, zero length, or otherwise * malformed. */ public PrintfFormat(Locale locale, String fmtArg) throws IllegalArgumentException { dfs = new DecimalFormatSymbols(locale); int ePos = 0; ConversionSpecification sFmt = null; String unCS = this.nonControl(fmtArg, 0); if (unCS != null) { sFmt = new ConversionSpecification(); sFmt.setLiteral(unCS); vFmt.addElement(sFmt); } while (cPos != -1 && cPos < fmtArg.length()) { for (ePos = cPos + 1; ePos < fmtArg.length(); ePos++) { char c = 0; c = fmtArg.charAt(ePos); if (c == 'i') break; if (c == 'd') break; if (c == 'f') break; if (c == 'g') break; if (c == 'G') break; if (c == 'o') break; if (c == 'x') break; if (c == 'X') break; if (c == 'e') break; if (c == 'E') break; if (c == 'c') break; if (c == 's') break; if (c == '%') break; } ePos = Math.min(ePos + 1, fmtArg.length()); sFmt = new ConversionSpecification(fmtArg.substring(cPos, ePos)); vFmt.addElement(sFmt); unCS = this.nonControl(fmtArg, ePos); if (unCS != null) { sFmt = new ConversionSpecification(); sFmt.setLiteral(unCS); vFmt.addElement(sFmt); } } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java
protected void configureRangeAxis(final CategoryPlot cpl, final Font labelFont) { final ValueAxis rangeAxis = cpl.getRangeAxis(); if (rangeAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) rangeAxis; numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero()); numberAxis.setAutoRangeStickyZero(isRangeStickyZero()); if (getRangePeriodCount() > 0) { if (getRangeTickFormat() != null) { numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat())); } else if (getRangeTickFormatString() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount())); }//from ww w. jav a 2 s. c o m } else { if (getRangeTickFormat() != null) { numberAxis.setNumberFormatOverride(getRangeTickFormat()); } else if (getRangeTickFormatString() != null) { final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); standardTickUnitsApplyFormat(numberAxis, formatter); } } } else if (rangeAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) rangeAxis; if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) { if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount(), formatter)); } else { numberAxis.setTickUnit( new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (rangeAxis != null) { rangeAxis.setLabelFont(labelFont); rangeAxis.setTickLabelFont(labelFont); if (getRangeTitleFont() != null) { rangeAxis.setLabelFont(getRangeTitleFont()); } if (getRangeTickFont() != null) { rangeAxis.setTickLabelFont(getRangeTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { rangeAxis.setLowerBound(getRangeMinimum()); } if (getRangeMaximum() != 1) { rangeAxis.setUpperBound(getRangeMaximum()); } if (getRangeMinimum() == 0 && getRangeMaximum() == 0) { rangeAxis.setAutoRange(true); } } else { if (isAutoRange()) { rangeAxis.setAutoRange(isAutoRange()); } else { double factor = getScaleFactor(); if (factor > DEFAULT_SCALE_FACTOR) { // PRD-5340 hack // this method is invoked after all series were populated // hence the axis already has the graph's max and min values; double lower = rangeAxis.getLowerBound(); if (lower < 0) { lower *= factor; } else if (lower > 0) { lower /= factor; } double upper = rangeAxis.getUpperBound(); if (upper > 0) { upper *= factor; } else if (upper < 0) { upper /= factor; } rangeAxis.setRange(lower, upper); } else { // the 'scaleFactor' property is left intact or has an incorrect value rangeAxis.setUpperBound(getRangeMaximum()); rangeAxis.setLowerBound(getRangeMinimum()); } } } } }