List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:escuela.AlumnoDaoTest.java
/** * Test of lista method, of class AlumnoDao. *//*from ww w . j av a 2s.c o m*/ @Test public void debieraObtenerListaDeAlumnos() { log.debug("lista"); NumberFormat nf = DecimalFormat.getInstance(); NumberFormat nf2 = DecimalFormat.getInstance(); nf.setMinimumIntegerDigits(4); nf.setGroupingUsed(false); nf2.setMinimumIntegerDigits(2); for (int i = 1; i <= 10; i++) { StringBuilder sb = new StringBuilder(); sb.append("Alumno").append(nf2.format(i)); Alumno alumno = new Alumno(nf.format(i), sb.toString(), sb.toString()); instance.crea(alumno); } List<Alumno> result = instance.lista(); assertNotNull(result); assertEquals(10, result.size()); }
From source file:org.gephi.statistics.plugin.dynamic.DynamicClusteringCoefficient.java
public String getReport() { //Transform to Map Map<Double, Double> map = new HashMap<Double, Double>(); for (Interval<Double> interval : averages.getIntervals()) { map.put(interval.getLow(), interval.getValue()); }// w w w . j a v a 2 s .c om //Time series XYSeries dSeries = ChartUtils.createXYSeries(map, "Clustering Coefficient Time Series"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(dSeries); JFreeChart chart = ChartFactory.createXYLineChart("Clustering Coefficient", "Time", "Average Clustering Coefficient", dataset, PlotOrientation.VERTICAL, true, false, false); chart.removeLegend(); ChartUtils.decorateChart(chart); ChartUtils.scaleChart(chart, dSeries, false); String coefficientImageFile = ChartUtils.renderChart(chart, "coefficient-ts.png"); NumberFormat f = new DecimalFormat("#0.000000"); String report = "<HTML> <BODY> <h1>Dynamic Clustering Coefficient Report </h1> " + "<hr>" + "<br> Bounds: from " + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window + "<br> Tick: " + tick + "<br><br><h2> Average clustering cloefficient over time: </h2>" + "<br /><br />" + coefficientImageFile; /*for (Interval<Double> average : averages) { report += average.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />"; }*/ report += "<br /><br /></BODY></HTML>"; return report; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
public static String getFieldValue(WikiPDFContext context, CustomFormField field) { // Return output based on type switch (field.getType()) { case CustomFormField.TEXTAREA: return StringUtils.replace(field.getValue(), "^", CRLF); case CustomFormField.SELECT: return field.getValue(); case CustomFormField.CHECKBOX: if ("true".equals(field.getValue())) { return "Yes"; } else {//from w ww .j av a2s . com return "No"; } case CustomFormField.CALENDAR: String calendarValue = field.getValue(); if (StringUtils.hasText(calendarValue)) { try { String convertedDate = DateUtils.getUserToServerDateTimeString(null, DateFormat.SHORT, DateFormat.LONG, field.getValue()); Timestamp timestamp = DatabaseUtils.parseTimestamp(convertedDate); Locale locale = Locale.getDefault(); int dateFormat = DateFormat.SHORT; SimpleDateFormat dateFormatter = (SimpleDateFormat) SimpleDateFormat.getDateInstance(dateFormat, locale); calendarValue = dateFormatter.format(timestamp); } catch (Exception e) { LOG.error(e); } } return calendarValue; case CustomFormField.PERCENT: return field.getValue() + "%"; case CustomFormField.INTEGER: // Determine the value to display in the field String integerValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(integerValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); integerValue = formatter.format(StringUtils.getIntegerNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not integer format: " + field.getValue()); } } return integerValue; case CustomFormField.FLOAT: // Determine the value to display in the field String decimalValue = field.getValue(); if (StringUtils.hasText(decimalValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); decimalValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not decimal format: " + field.getValue()); } } return decimalValue; case CustomFormField.CURRENCY: // Use a currency for formatting String currencyCode = field.getValueCurrency(); if (currencyCode == null) { currencyCode = field.getCurrency(); } if (!StringUtils.hasText(currencyCode)) { currencyCode = "USD"; } try { NumberFormat formatter = NumberFormat.getCurrencyInstance(); if (currencyCode != null) { Currency currency = Currency.getInstance(currencyCode); formatter.setCurrency(currency); } return (formatter.format(StringUtils.getDoubleNumber(field.getValue()))); } catch (Exception e) { LOG.error(e.getMessage()); } return field.getValue(); case CustomFormField.EMAIL: return field.getValue(); case CustomFormField.PHONE: PhoneNumberBean phone = new PhoneNumberBean(); phone.setNumber(field.getValue()); PhoneNumberUtils.format(phone, Locale.getDefault()); return phone.toString(); case CustomFormField.URL: String value = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(value)) { if (!value.contains("://")) { value = "http://" + value; } if (value.contains("://")) { return value; } } return value; case CustomFormField.IMAGE: String image = field.getValue(); if (StringUtils.hasText(image)) { return "WikiImage:" + image; } return image; default: return field.getValue(); } }
From source file:clus.statistic.RegressionStat.java
@Override public Element getPredictElement(Document doc) { Element stats = doc.createElement("RegressionStat"); NumberFormat fr = ClusFormat.SIX_AFTER_DOT; Attr examples = doc.createAttribute("examples"); examples.setValue(fr.format(m_SumWeight)); stats.setAttributeNode(examples);/*from w w w . j a v a 2 s . c o m*/ for (int i = 0; i < m_NbAttrs; i++) { Element attr = doc.createElement("Target"); Attr name = doc.createAttribute("name"); name.setValue(m_Attrs[i].getName()); attr.setAttributeNode(name); double tot = getSumWeights(i); if (tot == 0) attr.setTextContent("?"); else attr.setTextContent(fr.format(getSumValues(i) / tot)); stats.appendChild(attr); } return stats; }
From source file:org.gephi.statistics.plugin.WeightedDegree.java
public String getReport() { String report = ""; if (isDirected) { report = getDirectedReport();// w ww . ja v a 2 s .c om } else { //Distribution series XYSeries dSeries = ChartUtils.createXYSeries(degreeDist, "Degree Distribution"); XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(dSeries); JFreeChart chart1 = ChartFactory.createXYLineChart("Degree Distribution", "Value", "Count", dataset1, PlotOrientation.VERTICAL, true, false, false); chart1.removeLegend(); ChartUtils.decorateChart(chart1); ChartUtils.scaleChart(chart1, dSeries, false); String degreeImageFile = ChartUtils.renderChart(chart1, "w-degree-distribution.png"); NumberFormat f = new DecimalFormat("#0.000"); report = "<HTML> <BODY> <h1>Weighted Degree Report </h1> " + "<hr>" + "<br> <h2> Results: </h2>" + "Average Weighted Degree: " + f.format(avgWDegree) + "<br /><br />" + degreeImageFile + "</BODY></HTML>"; } return report; }
From source file:org.gephi.statistics.plugin.dynamic.DynamicDegree.java
public String getReport() { //Transform to Map Map<Double, Double> map = new HashMap<Double, Double>(); for (Interval<Double> interval : averages.getIntervals()) { map.put(interval.getLow(), interval.getValue()); }/* ww w . j a v a 2 s. c o m*/ //Time series XYSeries dSeries = ChartUtils.createXYSeries(map, "Degree Time Series"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(dSeries); JFreeChart chart = ChartFactory.createXYLineChart("Degree Time Series", "Time", "Average Degree", dataset, PlotOrientation.VERTICAL, true, false, false); chart.removeLegend(); ChartUtils.decorateChart(chart); ChartUtils.scaleChart(chart, dSeries, false); String degreeImageFile = ChartUtils.renderChart(chart, "degree-ts.png"); NumberFormat f = new DecimalFormat("#0.000000"); String report = "<HTML> <BODY> <h1>Dynamic Degree Report </h1> " + "<hr>" + "<br> Bounds: from " + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window + "<br> Tick: " + tick + "<br><br><h2> Average degrees over time: </h2>" + "<br /><br />" + degreeImageFile; /*for (Interval<Double> averages : averages) { report += averages.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />"; }*/ report += "<br /><br /></BODY></HTML>"; return report; }
From source file:org.gephi.statistics.plugin.Degree.java
/** * * @return/*ww w. j av a 2 s .c o m*/ */ public String getReport() { String report = ""; if (isDirected) { report = getDirectedReport(); } else { //Distribution series XYSeries dSeries = ChartUtils.createXYSeries(degreeDist, "Degree Distribution"); XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(dSeries); JFreeChart chart1 = ChartFactory.createXYLineChart("Degree Distribution", "Value", "Count", dataset1, PlotOrientation.VERTICAL, true, false, false); chart1.removeLegend(); ChartUtils.decorateChart(chart1); ChartUtils.scaleChart(chart1, dSeries, false); String degreeImageFile = ChartUtils.renderChart(chart1, "degree-distribution.png"); NumberFormat f = new DecimalFormat("#0.000"); report = "<HTML> <BODY> <h1>Degree Report </h1> " + "<hr>" + "<br> <h2> Results: </h2>" + "Average Degree: " + f.format(avgDegree) + "<br /><br />" + degreeImageFile + "</BODY></HTML>"; } return report; }
From source file:edu.uic.cs.compbio.DyNSPK.DynamicEntropy.java
public String getReport() { NumberFormat f = new DecimalFormat("#0.000000"); String report = "<HTML> <BODY> <h1>Dynamic Entropy Report </h1> " + "<hr>" + "<br> Bounds: from " + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window + "<br> Tick: " + tick + "<br><br><h2> Average degrees over time: </h2>" + "<br /><br />" + makeChart(this.nodedata, "nodets.png", "Node Entropy Time Series", " Time", "Node Changes") + makeChart(this.edgedata, "edgets.png", "Edge Entropy Time Series", " Time", "Edge Changes") + makeChart(this.sumdata, "sumts.png", "Entropy Time Series", " Time", "Total Changes"); /*// ww w . j a v a 2 s . com * private Map<Double, Double> nodedata; private Map<Double, Double> * edgedata; private Map<Double, Double> sumdata; */ /* * for (Interval<Double> average : averages) { report += * average.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) * + "<br />"; } */ report += "<br /><br /></BODY></HTML>"; return report; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.nettoExport.NettoCSVTransformerTest.java
@Test /**//w w w . j a v a 2 s . co m * Testcase creates 4 Informationsystemreleases with Text, Date and Numeric Attributes, which are transformed in CSV * The CSV output stream will be parsed again as CSV and the values are asserted */ public void testCSVTransformerForSpreadsheetReport() { NettoTransformer csvTransformer = NettoCSVTransformer .newInstance(createSimpleSpreadsheetReportTableStructure()); assertNotNull("Can't create netto transformer for overview page table structure for csv", csvTransformer); //Create output stream ByteArrayOutputStream out = new ByteArrayOutputStream(); csvTransformer.transform(sourceList, out, TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE); //assert that output stream InputStream in = new ByteArrayInputStream(out.toByteArray()); CSVReader reader; try { //BOMInputStream is necessary, because of leading BOM in Stream //Otherwise assertion would fail BOMInputStream bOMInputStream = new BOMInputStream(in); ByteOrderMark bom = bOMInputStream.getBOM(); String charsetName = bom == null ? "UTF-8" : bom.getCharsetName(); reader = new CSVReader(new InputStreamReader(new BufferedInputStream(bOMInputStream), charsetName), ';'); List<String[]> allLines = reader.readAll(); int index = 0; SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN); for (String[] line : allLines) { String name = line[0]; String desc = line[1]; String start = line[2]; String end = line[3]; String statusString = line[4]; String numString = line[5]; //get the status enum first //we onlny need planned and current in this test TypeOfStatus status = null; if ("Plan".equals(statusString)) { status = TypeOfStatus.PLANNED; } else if ("Ist".equals(statusString)) { status = TypeOfStatus.CURRENT; } if (index == 0) { //assert the headers of CSV file assertEquals("Name und Version", name.trim()); assertEquals("Beschreibung", desc); assertEquals("von", start); assertEquals("bis", end); assertEquals("Status", statusString); assertEquals("Complexity", numString); } else { //format the number NumberFormat nf = new DecimalFormat("0.00"); String number = nf.format(Double.valueOf(numString)); assertEquals(isArray[index - 1].getName(), name); assertEquals(isArray[index - 1].getDescription(), desc); assertEquals(df.format(isArray[index - 1].getRuntimePeriod().getStart()), start); assertEquals(df.format(isArray[index - 1].getRuntimePeriod().getEnd()), end); assertEquals(isArray[index - 1].getTypeOfStatus(), status); assertEquals(isArray[index - 1].getAttributeValue(numberAT.getName(), Locale.GERMAN), number); } index++; } reader.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.gephi.statistics.plugin.WeightedDegree.java
public String getDirectedReport() { //Distribution series XYSeries dSeries = ChartUtils.createXYSeries(degreeDist, "Degree Distribution"); XYSeries idSeries = ChartUtils.createXYSeries(inDegreeDist, "In-Degree Distribution"); XYSeries odSeries = ChartUtils.createXYSeries(outDegreeDist, "Out-Degree Distribution"); XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(dSeries);/*w w w . jav a 2s. c om*/ XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(idSeries); XYSeriesCollection dataset3 = new XYSeriesCollection(); dataset3.addSeries(odSeries); JFreeChart chart1 = ChartFactory.createXYLineChart("Degree Distribution", "Value", "Count", dataset1, PlotOrientation.VERTICAL, true, false, false); ChartUtils.decorateChart(chart1); ChartUtils.scaleChart(chart1, dSeries, false); String degreeImageFile = ChartUtils.renderChart(chart1, "w-degree-distribution.png"); JFreeChart chart2 = ChartFactory.createXYLineChart("In-Degree Distribution", "Value", "Count", dataset2, PlotOrientation.VERTICAL, true, false, false); ChartUtils.decorateChart(chart2); ChartUtils.scaleChart(chart2, dSeries, false); String indegreeImageFile = ChartUtils.renderChart(chart2, "indegree-distribution.png"); JFreeChart chart3 = ChartFactory.createXYLineChart("Out-Degree Distribution", "Value", "Count", dataset3, PlotOrientation.VERTICAL, true, false, false); ChartUtils.decorateChart(chart3); ChartUtils.scaleChart(chart3, dSeries, false); String outdegreeImageFile = ChartUtils.renderChart(chart3, "outdegree-distribution.png"); NumberFormat f = new DecimalFormat("#0.000"); String report = "<HTML> <BODY> <h1>Weighted Degree Report </h1> " + "<hr>" + "<br> <h2> Results: </h2>" + "Average Weighted Degree: " + f.format(avgWDegree) + "<br /><br />" + degreeImageFile + "<br /><br />" + indegreeImageFile + "<br /><br />" + outdegreeImageFile + "</BODY></HTML>"; return report; }