List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols
public DecimalFormatSymbols(Locale locale)
From source file:org.unitime.timetable.solver.curricula.students.CurModel.java
public void saveAsXml(Element root, Assignment<CurVariable, CurValue> assignment) { List<Long> courses = new ArrayList<Long>(); DecimalFormat df = new DecimalFormat("0.##########", new DecimalFormatSymbols(Locale.US)); for (CurCourse course : getCourses()) { Element courseElement = root.addElement("course"); courseElement.addAttribute("id", course.getCourseId().toString()); courseElement.addAttribute("name", course.getCourseName()); courseElement.addAttribute("limit", df.format(course.getOriginalMaxSize())); if (course.getPriority() != null) courseElement.addAttribute("priority", course.getPriority().toString()); if (!courses.isEmpty()) { String share = ""; for (Long other : courses) { share += (share.isEmpty() ? "" : ",") + df.format(course.getTargetShare(other)); }/*from w ww .j a v a2 s. com*/ courseElement.addAttribute("share", share); } courses.add(course.getCourseId()); } for (CurStudent student : getStudents()) { Element studentElement = root.addElement("student"); studentElement.addAttribute("id", student.getStudentId().toString()); if (student.getWeight() != 1.0) studentElement.addAttribute("weight", df.format(student.getWeight())); String courseIds = ""; for (CurCourse course : student.getCourses(assignment)) { courseIds += (courseIds.isEmpty() ? "" : ",") + course.getCourseId(); } studentElement.setText(courseIds); } }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
/** * @param vehicleDistances//from w w w . j a va2s . c o m * @param iterationFilename */ public static void writeVehicleDistances(Map<Id<Vehicle>, double[]> vehicleDistances, String iterationFilename) { String header = "vehicleId;drivenDistance_m;occupiedDistance_m;emptyDistance_m;revenueDistance_pm"; BufferedWriter bw = IOUtils.getBufferedWriter(iterationFilename); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); try { bw.write(header); for (Entry<Id<Vehicle>, double[]> e : vehicleDistances.entrySet()) { double drivenDistance = e.getValue()[0]; double revenueDistance = e.getValue()[1]; double occDistance = e.getValue()[2]; double emptyDistance = drivenDistance - occDistance; bw.newLine(); bw.write(e.getKey().toString() + ";" + format.format(drivenDistance) + ";" + format.format(occDistance) + ";" + format.format(emptyDistance) + ";" + format.format(revenueDistance)); } bw.flush(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.mitre.ccv.mapred.CalculateCosineDistanceMatrix.java
/** * Outputs the distance matrix (DenseVectors) in Phylip Square format. Names/labels are limited to 10-characters! * * @param jobConf/*from w w w. ja va 2 s . c om*/ * @param input input directory name containing DenseVectors (as generated by this class). * @param output output file name * @param fractionDigits number of digits after decimal point * @throws IOException */ public static void printPhylipSquare(JobConf jobConf, String input, String output, int fractionDigits) throws IOException { JobConf conf = new JobConf(jobConf, CalculateCosineDistanceMatrix.class); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(fractionDigits); //format.setMinimumFractionDigits(fractionDigits); format.setGroupingUsed(false); final Path inputPath = new Path(input); final FileSystem fs = inputPath.getFileSystem(conf); final Path qInputPath = fs.makeQualified(inputPath); final Path outputPath = new Path(output); Path[] paths = FileUtils.ls(conf, qInputPath.toString() + Path.SEPARATOR + "part-*"); FSDataOutputStream fos = fs.create(outputPath, true); // throws nothing! Writer writer = new OutputStreamWriter(fos); Text key = new Text(); DenseVectorWritable value = new DenseVectorWritable(); Boolean wroteHeader = false; for (int idx = 0; idx < paths.length; idx++) { SequenceFile.Reader reader = new SequenceFile.Reader(fs, paths[idx], conf); boolean hasNext = reader.next(key, value); while (hasNext) { final DenseVector vector = value.get(); if (!wroteHeader) { writer.write(String.format("\t%d\n", vector.getCardinality())); wroteHeader = true; } final StringBuilder sb = new StringBuilder(); final String name = key.toString(); sb.append(name.substring(0, (name.length() > 10 ? 10 : name.length()))); final int padding = Math.max(1, 10 - name.length()); for (int k = 0; k < padding; k++) { sb.append(' '); } sb.append(' '); for (int i = 0; i < vector.getCardinality(); i++) { final String s = format.format(vector.get(i)); // format the number sb.append(s); sb.append(' '); } sb.append("\n"); writer.write(sb.toString()); hasNext = reader.next(key, value); } try { writer.flush(); reader.close(); } catch (IOException ioe) { // closing the SequenceFile.Reader will throw an exception if the file is over some unknown size LOG.debug("Probably caused by closing the SequenceFile.Reader. All is well", ioe); } } try { writer.close(); fos.flush(); fos.close(); } catch (IOException ioe) { LOG.debug("Caused by distributed cache output stream.", ioe); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.BarLineChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final CategoryPlot plot = chart.getCategoryPlot(); if (isSharedRangeAxis() == false) { final ValueAxis linesAxis = plot.getRangeAxis(1); if (linesAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) linesAxis; numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero()); numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero()); if (getLinePeriodCount() > 0) { if (getLineTicksLabelFormat() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount())); }//from w ww .j a v a2 s . co m } else { if (getLineTicksLabelFormat() != null) { final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (linesAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) linesAxis; if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) { if (getLineTicksLabelFormat() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (linesAxis != null) { final Font labelFont = Font.decode(getLabelFont()); linesAxis.setLabelFont(labelFont); linesAxis.setTickLabelFont(labelFont); if (getLineTitleFont() != null) { linesAxis.setLabelFont(getLineTitleFont()); } if (getLineTickFont() != null) { linesAxis.setTickLabelFont(getLineTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { linesAxis.setLowerBound(getLineRangeMinimum()); } if (getRangeMaximum() != 1) { linesAxis.setUpperBound(getLineRangeMaximum()); } if (getLineRangeMinimum() == 0 && getLineRangeMaximum() == 1) { linesAxis.setLowerBound(0); linesAxis.setUpperBound(1); linesAxis.setAutoRange(true); } } else { linesAxis.setLowerBound(getLineRangeMinimum()); linesAxis.setUpperBound(getLineRangeMaximum()); linesAxis.setAutoRange(isLineAxisAutoRange()); } } } final LineAndShapeRenderer linesRenderer = (LineAndShapeRenderer) plot.getRenderer(1); if (linesRenderer != null) { //set stroke with line width linesRenderer.setStroke(translateLineStyle(lineWidth, lineStyle)); //hide shapes on line linesRenderer.setShapesVisible(isMarkersVisible()); linesRenderer.setBaseShapesFilled(isMarkersVisible()); //set colors for each line for (int i = 0; i < lineSeriesColor.size(); i++) { final String s = (String) lineSeriesColor.get(i); linesRenderer.setSeriesPaint(i, parseColorFromString(s)); } } }
From source file:com.moviejukebox.plugin.MovieListingPluginCustomCsv.java
/** * Generate the listing file// w w w. j a v a 2s . co m * * @param jukebox * @param library */ @Override public void generate(Jukebox jukebox, Library library) { initialize(jukebox); initFields(PropertiesUtil.getProperty("mjb.listing.csv.fields", DEFAULT_FIELDS)); mDelimiter = PropertiesUtil.getProperty("mjb.listing.csv.delimiter", ","); mSecondDelimiter = PropertiesUtil.getProperty("mjb.listing.csv.secondDelimiter", "|"); String dateFormat = PropertiesUtil.getProperty("mjb.listing.csv.dateFormat", ""); String ratingFactor = PropertiesUtil.getProperty("mjb.listing.csv.ratingFactor", "1.00"); DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.US); mRatingFormatter = new DecimalFormat("#0.00", decimalFormatSymbols); limitCast = PropertiesUtil.getIntProperty("mjb.listing.csv.limitCast", 100); limitGenres = PropertiesUtil.getIntProperty("mjb.listing.csv.limitGenres", 100); mRatingFactor = new Double(ratingFactor); if (dateFormat.length() > 1) { mDateFormatter = new SimpleDateFormat(dateFormat); } String filename = getBaseFilename() + ".csv"; File csvFile = new File(jukebox.getJukeboxTempLocation(), filename); List<String> alTypes = getSelectedTypes(); try { CSVWriter writer = new CSVWriter(csvFile); LOG.debug(" Writing CSV to: {}", csvFile.getAbsolutePath()); // write header line writer.line(headerLine()); if (!isGroupByType()) { for (Movie movie : library.values()) { LOG.debug(movie.toString()); String sType; if (movie.isExtra()) { sType = VideoType.EXTRA.getType(); } else if (movie.isTVShow()) { sType = VideoType.TV_SHOW.getType(); } else { sType = VideoType.MOVIE.getType(); } if (null != sType && alTypes.contains(sType)) { writer.line(toCSV(sType, movie)); } } // for movie } else { for (String thisType : alTypes) { for (Movie movie : library.values()) { String sType; if (movie.isExtra()) { sType = VideoType.EXTRA.getType(); } else if (movie.isTVShow()) { sType = VideoType.TV_SHOW.getType(); } else { sType = VideoType.MOVIE.getType(); } if (null != sType && thisType.equalsIgnoreCase(sType)) { writer.line(toCSV(sType, movie)); } } } } writer.close(); } catch (IOException error) { LOG.error(SystemTools.getStackTrace(error)); } // move to configured (default) location copyListingFile(csvFile, filename); }
From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java
private void updateSummary(Iterable<File> iterable) { Validate.notNull(iterable, "The give iterable is null"); int files = 0, folders = 0; long totalSize = 0; for (File file : iterable) { if (file.isFile()) { files++;/*from w w w .j a v a 2 s . com*/ totalSize += file.length(); } else { folders++; } } final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); symbols.setGroupingSeparator(' '); final DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setDecimalFormatSymbols(symbols); // Set the summary if (files > 0) { if (folders > 0) { summary.setText(String.format("%d folder(s) and %d file(s) [%s Kb]", folders, files, decimalFormat.format(totalSize / 1024))); } else { summary.setText(String.format("%d file(s) [%s Kb]", files, decimalFormat.format(totalSize / 1024))); } } else { if (folders > 0) { summary.setText(String.format("%d folder(s)", folders)); } else { summary.setText(" "); } } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final CategoryPlot cpl = chart.getCategoryPlot(); final CategoryItemRenderer renderer = cpl.getRenderer(); if (StringUtils.isEmpty(getTooltipFormula()) == false) { renderer.setBaseToolTipGenerator( new FormulaCategoryTooltipGenerator(getRuntime(), getTooltipFormula())); }/*from ww w .j a v a 2s . c om*/ if (StringUtils.isEmpty(getUrlFormula()) == false) { renderer.setBaseItemURLGenerator(new FormulaCategoryURLGenerator(getRuntime(), getUrlFormula())); } if (this.categoricalLabelFormat != null) { final StandardCategoryItemLabelGenerator scilg; if (categoricalLabelDecimalFormat != null) { final DecimalFormat numFormat = new DecimalFormat(categoricalLabelDecimalFormat, new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale())); numFormat.setRoundingMode(RoundingMode.HALF_UP); scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, numFormat); } else if (categoricalLabelDateFormat != null) { scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, new SimpleDateFormat( categoricalLabelDateFormat, getRuntime().getResourceBundleFactory().getLocale())); } else { final DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols( new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale())); scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, formatter); } renderer.setBaseItemLabelGenerator(scilg); } renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible())); if (getItemLabelFont() != null) { renderer.setBaseItemLabelFont(getItemLabelFont()); } if (categoricalItemLabelRotation != null) { final ItemLabelPosition orgPosItemLabelPos = renderer.getBasePositiveItemLabelPosition(); if (orgPosItemLabelPos == null) { final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue()); renderer.setBasePositiveItemLabelPosition(pos2); } else { final ItemLabelPosition pos2 = new ItemLabelPosition(orgPosItemLabelPos.getItemLabelAnchor(), orgPosItemLabelPos.getTextAnchor(), orgPosItemLabelPos.getRotationAnchor(), categoricalItemLabelRotation.doubleValue()); renderer.setBasePositiveItemLabelPosition(pos2); } final ItemLabelPosition orgNegItemLabelPos = renderer.getBaseNegativeItemLabelPosition(); if (orgNegItemLabelPos == null) { final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue()); renderer.setBaseNegativeItemLabelPosition(pos2); } else { final ItemLabelPosition neg2 = new ItemLabelPosition(orgNegItemLabelPos.getItemLabelAnchor(), orgNegItemLabelPos.getTextAnchor(), orgNegItemLabelPos.getRotationAnchor(), categoricalItemLabelRotation.doubleValue()); renderer.setBaseNegativeItemLabelPosition(neg2); } } final Font labelFont = Font.decode(getLabelFont()); final CategoryAxis categoryAxis = cpl.getDomainAxis(); categoryAxis.setLabelFont(labelFont); categoryAxis.setTickLabelFont(labelFont); if (getCategoryTitleFont() != null) { categoryAxis.setLabelFont(getCategoryTitleFont()); } if (getCategoryTickFont() != null) { categoryAxis.setTickLabelFont(getCategoryTickFont()); } if (maxCategoryLabelWidthRatio != null) { categoryAxis.setMaximumCategoryLabelWidthRatio(maxCategoryLabelWidthRatio.floatValue()); } cpl.setDomainGridlinesVisible(showGridlines); if (labelRotation != null) { double angle = labelRotation.doubleValue(); CategoryLabelPosition top = createUpRotationCategoryLabelPosition(PlaneDirection.TOP, angle); CategoryLabelPosition bottom = createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, angle); CategoryLabelPosition left = createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, angle); CategoryLabelPosition right = createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, angle); CategoryLabelPositions rotationLabelPositions = new CategoryLabelPositions(top, bottom, left, right); categoryAxis.setCategoryLabelPositions(rotationLabelPositions); } final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, parseColorFromString(colors[i])); } if (lowerMargin != null) { categoryAxis.setLowerMargin(lowerMargin.doubleValue()); } if (upperMargin != null) { categoryAxis.setUpperMargin(upperMargin.doubleValue()); } if (categoryMargin != null) { categoryAxis.setCategoryMargin(categoryMargin.doubleValue()); } configureRangeAxis(cpl, labelFont); }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
/** * @param vehicleDistances/* ww w .j a v a 2 s . c o m*/ * @param string * @return */ public static String summarizeVehicles(Map<Id<Vehicle>, double[]> vehicleDistances, String del) { DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); DescriptiveStatistics driven = new DescriptiveStatistics(); DescriptiveStatistics revenue = new DescriptiveStatistics(); DescriptiveStatistics occupied = new DescriptiveStatistics(); DescriptiveStatistics empty = new DescriptiveStatistics(); for (double[] dist : vehicleDistances.values()) { driven.addValue(dist[0]); revenue.addValue(dist[1]); occupied.addValue(dist[2]); double emptyD = dist[0] - dist[2]; empty.addValue(emptyD); } double d_r_d_t = revenue.getSum() / driven.getSum(); // bw.write("iteration;vehicles;totalDistance;totalEmptyDistance;emptyRatio;totalRevenueDistance;averageDrivenDistance;averageEmptyDistance;averageRevenueDistance"); String result = vehicleDistances.size() + del + format.format(driven.getSum()) + del + format.format(empty.getSum()) + del + format.format(empty.getSum() / driven.getSum()) + del + format.format(revenue.getSum()) + del + format.format(driven.getMean()) + del + format.format(empty.getMean()) + del + format.format(revenue.getMean()) + del + format.format(d_r_d_t); return result; }
From source file:org.revager.tools.GUITools.java
/** * Formats the given spinner.//from w w w . j av a 2s . c o m * * @param sp * the spinner */ public static void formatSpinner(JSpinner sp, boolean hideBorder) { JSpinner.DefaultEditor defEditor = (JSpinner.DefaultEditor) sp.getEditor(); JFormattedTextField ftf = defEditor.getTextField(); ftf.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); InternationalFormatter intFormatter = (InternationalFormatter) ftf.getFormatter(); DecimalFormat decimalFormat = (DecimalFormat) intFormatter.getFormat(); decimalFormat.applyPattern("00"); DecimalFormatSymbols geSymbols = new DecimalFormatSymbols(Data.getInstance().getLocale()); decimalFormat.setDecimalFormatSymbols(geSymbols); if (hideBorder) { sp.setBorder(null); } }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Return a NumberFormat to use for Conversion. * * @return The NumberFormat.//w ww .ja va 2s . co m */ private NumberFormat getFormat() { NumberFormat format = null; if (pattern != null) { if (locale == null) { format = new DecimalFormat(pattern); } else { DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); format = new DecimalFormat(pattern, symbols); } } else { if (locale == null) { format = NumberFormat.getInstance(); } else { format = NumberFormat.getInstance(locale); } } if (!allowDecimals) { format.setParseIntegerOnly(true); } return format; }