List of usage examples for java.util Formatter Formatter
public Formatter(OutputStream os)
From source file:umontreal.ssj.charts.HistogramChart.java
/** * @name LaTeX-specific method//w w w .j a v a 2 s. c o m * @{ */ public String toLatex(double width, double height) { double xunit, yunit; double[] save = new double[4]; if (dataset.getSeriesCollection().getSeriesCount() == 0) throw new IllegalArgumentException("Empty chart"); if (YAxis.getTwinAxisPosition() < 0) YAxis.setTwinAxisPosition(0); // Calcul des parametres d'echelle et de decalage double XScale = computeXScale(XAxis.getTwinAxisPosition()); double YScale = computeYScale(YAxis.getTwinAxisPosition()); // taille d'une unite en x et en cm dans l'objet "tikzpicture" xunit = width / ((Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) * XScale) - (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) * XScale)); // taille d'une unite en y et en cm dans l'objet "tikzpicture" yunit = height / ((Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) * YScale) - (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) * YScale)); Formatter formatter = new Formatter(Locale.US); /*Entete du document*/ if (latexDocFlag) { formatter.format("\\documentclass[12pt]{article}%n%n"); formatter.format("\\usepackage{tikz}%n\\usetikzlibrary{plotmarks}%n\\begin{document}%n%n"); } if (chart.getTitle() != null) formatter.format("%% PGF/TikZ picture from SSJ: %s%n", chart.getTitle().getText()); else formatter.format("%% PGF/TikZ picture from SSJ %n"); formatter.format("%% XScale = %s, YScale = %s, XShift = %s, YShift = %s%n", XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition()); formatter.format("%% Therefore, thisFileXValue = (originalSeriesXValue+XShift)*XScale%n"); formatter.format("%% and thisFileYValue = (originalSeriesYValue+YShift)*YScale%n%n"); if (chart.getTitle() != null) formatter.format("\\begin{figure}%n"); formatter.format("\\begin{center}%n"); formatter.format("\\begin{tikzpicture}[x=%scm, y=%scm]%n", xunit, yunit); formatter.format("\\footnotesize%n"); if (grid) formatter.format("\\draw[color=lightgray] (%s, %s) grid[xstep = %s, ystep=%s] (%s, %s);%n", (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale, xstepGrid * XScale, ystepGrid * YScale, (Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale); setTick0Flags(); formatter.format("%s", XAxis.toLatex(XScale)); formatter.format("%s", YAxis.toLatex(YScale)); formatter.format("%s", dataset.toLatex(XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition(), XAxis.getAxis().getLowerBound(), XAxis.getAxis().getUpperBound(), YAxis.getAxis().getLowerBound(), YAxis.getAxis().getUpperBound())); formatter.format("\\end{tikzpicture}%n"); formatter.format("\\end{center}%n"); if (chart.getTitle() != null) { formatter.format("\\caption{"); formatter.format(chart.getTitle().getText()); formatter.format("}%n\\end{figure}%n"); } if (latexDocFlag) formatter.format("\\end{document}%n"); return formatter.toString(); }
From source file:com.itemanalysis.psychometrics.histogram.Histogram.java
/** * A string representation of the histogram. It lists the bin intervals, midpoints, and value values. * * @return histogram values for display as plain text. *//* w w w .ja v a2 s .c o m*/ @Override public String toString() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); String li = "", ui = ""; f.format("%n"); f.format("%64s", " HISTOGRAM VALUES "); f.format("%n"); f.format("%64s", "================================================================"); f.format("%n"); f.format("%16s", "Lower Bound"); f.format("%18s", "Upper Bound"); f.format("%15s", "MidPoint"); if (histogramType == HistogramType.FREQUENCY) { f.format("%15s", "Frequency"); } else if (histogramType == HistogramType.RELATIVE_FREQUENCY) { f.format("%15s", "Rel. Freq."); } else if (histogramType == HistogramType.NORMALIZED_RELATIVE_FREQUENCY) { f.format("%15s", "Rel. Freq."); } else { f.format("%15s", "Density"); } f.format("%n"); f.format("%64s", "----------------------------------------------------------------"); f.format("%n"); Bin b = null; for (int i = bins.size() - 1; i > -1; i--) { b = bins.get(i); // for(Bin b : bins){ if (b.lowerInclusive()) { li = "["; ui = ")"; } else { li = "("; ui = "]"; } f.format("%1s", li); f.format("% 15.5f, ", b.getLowerBound()); f.format("% 15.5f", b.getUpperBound()); f.format("%1s", ui); f.format("% 15.5f", points[i]); f.format("% 15.5f", value[i]); f.format("%n"); } f.format("%64s", "================================================================"); f.format("%n"); f.format("%11s", "Binwidth = "); f.format("% .4f", binWidth); f.format("%n"); return f.toString(); }
From source file:com.itemanalysis.psychometrics.irt.estimation.MarginalMaximumLikelihoodEstimation.java
public String printItemParameters() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%58s", "MMLE ITEM PARAMETER ESTIMATES"); f.format("%n"); f.format("%87s", "======================================================================================="); f.format("%n"); f.format("%-18s", "Item"); f.format("%5s", "Code"); f.format("%9s", "Apar"); f.format("%7s", "(SE)"); f.format("%9s", "Bpar"); f.format("%1s", ""); f.format("%6s", "(SE)"); f.format("%9s", "Cpar"); f.format("%1s", ""); f.format("%6s", "(SE)"); f.format("%9s", "Upar"); f.format("%1s", ""); f.format("%6s", "(SE)"); f.format("%n"); f.format("%87s", "---------------------------------------------------------------------------------------"); f.format("%n"); for (int j = 0; j < nItems; j++) { sb.append(irm[j].toString() + "\n"); }/* ww w .j a v a 2 s. c o m*/ f.format("%87s", "======================================================================================="); f.format("%n"); return f.toString(); }
From source file:org.realityforge.proxy_servlet.AbstractProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * <p/>//from w w w . j av a 2 s .co m * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link java.net.URI}. * To be more forgiving, we must escape the problematic characters. See the URI class for the * spec. * * @param in example: name=value&foo=bar#fragment */ private static CharSequence encodeUriQuery(final CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder sb = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < MAX_ASCII_VALUE) { if (ASCII_QUERY_CHARS.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) { //not-ascii escape = false; } if (!escape) { if (null != sb) { sb.append(c); } } else { //escape if (null == sb) { final int formatLength = 5 * 3; sb = new StringBuilder(in.length() + formatLength); sb.append(in, 0, i); formatter = new Formatter(sb); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c); } } return sb != null ? sb : in; }
From source file:umontreal.ssj.charts.ScatterChart.java
/** * @name LaTex-specific method//from www .j a va 2s. c o m * @{ */ public String toLatex(double width, double height) { double xunit = 0, yunit = 0; double[] save = new double[4]; if (dataset.getSeriesCollection().getSeriesCount() == 0) throw new IllegalArgumentException("Empty chart"); //Calcul des parametres d'echelle et de decalage double XScale = computeXScale(XAxis.getTwinAxisPosition()); double YScale = computeYScale(YAxis.getTwinAxisPosition()); //taille d'une unite en x et en cm dans l'objet "tikzpicture" xunit = width / ((Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) * XScale) - (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) * XScale)); //taille d'une unite en y et en cm dans l'objet "tikzpicture" yunit = height / ((Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) * YScale) - (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) * YScale)); Formatter formatter = new Formatter(Locale.US); /*Entete du document*/ if (latexDocFlag) { formatter.format("\\documentclass[12pt]{article}%n%n"); formatter.format("\\usepackage{tikz}%n\\usetikzlibrary{plotmarks}%n\\begin{document}%n%n"); } if (chart.getTitle() != null) formatter.format("%% PGF/TikZ picture from SSJ: %s%n", chart.getTitle().getText()); else formatter.format("%% PGF/TikZ picture from SSJ %n"); formatter.format("%% XScale = %s, YScale = %s, XShift = %s, YShift = %s%n", XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition()); formatter.format("%% Therefore, thisFileXValue = (originalSeriesXValue+XShift)*XScale%n"); formatter.format("%% and thisFileYValue = (originalSeriesYValue+YShift)*YScale%n%n"); if (chart.getTitle() != null) formatter.format("\\begin{figure}%n"); formatter.format("\\begin{center}%n"); formatter.format("\\begin{tikzpicture}[x=%scm, y=%scm]%n", xunit, yunit); formatter.format("\\footnotesize%n"); if (grid) formatter.format("\\draw[color=lightgray] (%s, %s) grid[xstep = %s, ystep=%s] (%s, %s);%n", (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale, xstepGrid * XScale, ystepGrid * YScale, (Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale); setTick0Flags(); formatter.format("%s", XAxis.toLatex(XScale)); formatter.format("%s", YAxis.toLatex(YScale)); formatter.format("%s", dataset.toLatex(XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition(), XAxis.getAxis().getLowerBound(), XAxis.getAxis().getUpperBound(), YAxis.getAxis().getLowerBound(), YAxis.getAxis().getUpperBound())); formatter.format("\\end{tikzpicture}%n"); formatter.format("\\end{center}%n"); if (chart.getTitle() != null) { formatter.format("\\caption{"); formatter.format(chart.getTitle().getText()); formatter.format("}%n\\end{figure}%n"); } if (latexDocFlag) formatter.format("\\end{document}%n"); return formatter.toString(); }
From source file:uk.ac.ebi.phenotype.web.proxy.ExternalUrlConfiguratbleProxyServlet.java
/** * <p>//from w w w. j a v a2s .co m * Encodes characters in the query or fragment part of the URI. * * <p> * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient insists that the outgoing proxied request has a valid * URI because it uses Java's {@link URI}. To be more forgiving, we must * escape the problematic characters. See the URI class for the spec. * * @param in * example: name=value&foo=bar#fragment */ static CharSequence encodeUriQuery(CharSequence in) { // Note that I can't simply use URI.java to encode because it will // escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {// not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { // escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } // leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);// TODO } } return outBuf != null ? outBuf : in; }
From source file:org.ocpsoft.rewrite.servlet.config.proxy.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * //from w w w . java2s . co m * <p> * Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient insists that the * outgoing proxied request has a valid URI because it uses Java's {@link URI}. To be more forgiving, we must escape * the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { /* * Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. TODO: * replace/compare to with Rewrite Encoding */ StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get(c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) { /* * not-ascii */ escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { /* * escape */ if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } /* * leading %, 0 padded, width 2, capital hex */ formatter.format("%%%02X", (int) c);// TODO } } return outBuf != null ? outBuf : in; }
From source file:com.itemanalysis.psychometrics.irt.estimation.MarginalMaximumLikelihoodEstimation.java
public String printLatentDistribution() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%30s", " Latent Distribution "); f.format("%n"); f.format("%30s", "=============================="); f.format("%n"); f.format("%10s", "Point"); f.format("%4s", ""); f.format("%16s", "Density"); f.format("%n"); f.format("%30s", "------------------------------"); f.format("%n"); for (int k = 0; k < latentDistribution.getNumberOfPoints(); k++) { f.format("% 10.8f", latentDistribution.getPointAt(k)); f.format("%4s", ""); f.format("% 10.8e", latentDistribution.getDensityAt(k));//15 wide f.format("%n"); }/*from ww w. j a v a 2s .c o m*/ f.format("%30s", "=============================="); f.format("%n"); f.format("%12s", "Mean = "); f.format("%8.4f", latentDistribution.getMean()); f.format("%n"); f.format("%12s", "Std. Dev. = "); f.format("%8.4f", latentDistribution.getStandardDeviation()); f.format("%n"); return f.toString(); }
From source file:edu.stanford.muse.index.EmailDocument.java
/** used mostly as a debug routine */ public String getHeader() { StringBuilder sb = new StringBuilder(); sb.append("Folder: " + folderName + "\n"); StringBuilder timeSB = new StringBuilder(); Formatter formatter = new Formatter(timeSB); if (date != null) { Calendar c = new GregorianCalendar(); c.setTime(date);// ww w.j a v a 2s . c o m formatter.format("%02d:%02d", c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE)); sb.append("Date: " + c.get(Calendar.DATE) + " " + CalendarUtil.getDisplayMonth(c) + " " + c.get(Calendar.YEAR) + " " + timeSB + "\n"); } formatter.close(); sb.append("From: " + getFromString() + "\n"); sb.append("To: " + getToString() + "\n"); String cc = getCcString(); if (!Util.nullOrEmpty(cc)) sb.append("Cc: " + cc + "\n"); String bcc = getBccString(); if (!Util.nullOrEmpty(bcc)) sb.append("Bcc: " + bcc + "\n"); if (description == null) description = "<None>"; sb.append("Subject: " + description + "\n"); if (messageID != null) sb.append("Message-ID: " + messageID + "\n"); sb.append("\n"); return sb.toString(); }
From source file:com.itemanalysis.psychometrics.mixture.MvNormalMixtureModel.java
public String printResults() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%20s", "Number of groups = "); f.format("%-4d", groups); f.format("%n"); f.format("%20s", "Free parameters = "); f.format("%-4d", freeParameters()); f.format("%n"); f.format("%20s", "Sample size = "); f.format("%-10d", sampleSize); f.format("%n"); f.format("%20s", "Log-likelihood = "); f.format("%-12.4f", this.loglikelihood()); f.format("%n"); f.format("%20s", "Converged = "); f.format("%-5s", converged); f.format("%n"); f.format("%20s", "Status = "); f.format("%-35s", statusMessage); f.format("%n"); f.format("%n"); f.format(fit.printFitStatistics());// ww w .j a v a 2s. c om f.format("%n"); MvNormalComponentDistribution mvnDist = null; for (int g = 0; g < groups; g++) { f.format("%n"); mvnDist = (MvNormalComponentDistribution) compDistribution[g]; f.format("%-12s", "Group " + (g + 1) + " "); f.format("%n"); f.format("%12s", "Mix Prop: "); f.format(mvnDist.printMixingProportion()); f.format("%12s", "Mean: "); f.format(mvnDist.printMean()); f.format("%12s", "Covar: "); f.format("%n"); f.format(mvnDist.printCovariance()); } return f.toString(); }