Example usage for java.util Formatter Formatter

List of usage examples for java.util Formatter Formatter

Introduction

In this page you can find the example usage for java.util Formatter Formatter.

Prototype

public Formatter(OutputStream os) 

Source Link

Document

Constructs a new formatter with the specified output stream.

Usage

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.secondCycle.SecondCycleIndividualCandidacy.java

@Override
public void exportValues(StringBuilder result) {
    super.exportValues(result);

    Formatter formatter = new Formatter(result);

    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.process.id"),
            getCandidacyProcess().getProcessCode());
    PrecedentDegreeInformation precedentDegreeInformation = getCandidacyProcess()
            .getPrecedentDegreeInformation();
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.previous.degree"),
            precedentDegreeInformation.getDegreeDesignation());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.conclusionDate"),
            precedentDegreeInformation.getConclusionDate());
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.institution"),
            precedentDegreeInformation.getInstitution().getName());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.conclusionGrade"),
            precedentDegreeInformation.getConclusionGrade());
    formatter.format("\n");
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.professionalStatus"),
            StringUtils.isEmpty(getProfessionalStatus()) ? StringUtils.EMPTY : getProfessionalStatus());
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.otherEducation"),
            StringUtils.isEmpty(getOtherEducation()) ? StringUtils.EMPTY : getOtherEducation());
    formatter.format("%s: %d\n",
            BundleUtil.getString(Bundle.ACADEMIC,
                    "label.SecondCycleIndividualCandidacy.professionalExperience"),
            getProfessionalExperience() != null ? getProfessionalExperience() : 0);
    formatter.format("%s: %f\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.affinity"),
            getAffinity() != null ? getAffinity() : BigDecimal.ZERO);
    formatter.format("%s: %d\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.degreeNature"),
            getDegreeNature() != null ? getDegreeNature() : 0);
    formatter.format("%s: %f\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.candidacyGrade"),
            getCandidacyGrade() != null ? getCandidacyGrade() : BigDecimal.ZERO);
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.interviewGrade"),
            getInterviewGrade());// ww  w .j  a  v  a2 s .c o  m
    formatter.format("%s: %f\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.seriesCandidacyGrade"),
            getSeriesCandidacyGrade() != null ? getSeriesCandidacyGrade() : BigDecimal.ZERO);

    formatter.close();
}

From source file:be.milieuinfo.core.proxy.controller.ProxyServlet.java

/**
 * <p>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
 *//*from  w  w w  . j  a v a  2 s.  c  o  m*/
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:com.diablominer.DiabloMiner.NetworkState.JSONRPCNetworkState.java

boolean doSendWorkMessage(WorkState workState) throws IOException {
    StringBuilder dataOutput = new StringBuilder(8 * 32 + 1);
    Formatter dataFormatter = new Formatter(dataOutput);
    int[] data = workState.getData();

    dataFormatter.format(/*from  www  .ja  v  a2s. c om*/
            "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x"
                    + "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
            Integer.reverseBytes(data[0]), Integer.reverseBytes(data[1]), Integer.reverseBytes(data[2]),
            Integer.reverseBytes(data[3]), Integer.reverseBytes(data[4]), Integer.reverseBytes(data[5]),
            Integer.reverseBytes(data[6]), Integer.reverseBytes(data[7]), Integer.reverseBytes(data[8]),
            Integer.reverseBytes(data[9]), Integer.reverseBytes(data[10]), Integer.reverseBytes(data[11]),
            Integer.reverseBytes(data[12]), Integer.reverseBytes(data[13]), Integer.reverseBytes(data[14]),
            Integer.reverseBytes(data[15]), Integer.reverseBytes(data[16]), Integer.reverseBytes(data[17]),
            Integer.reverseBytes(data[18]), Integer.reverseBytes(data[19]), Integer.reverseBytes(data[20]),
            Integer.reverseBytes(data[21]), Integer.reverseBytes(data[22]), Integer.reverseBytes(data[23]),
            Integer.reverseBytes(data[24]), Integer.reverseBytes(data[25]), Integer.reverseBytes(data[26]),
            Integer.reverseBytes(data[27]), Integer.reverseBytes(data[28]), Integer.reverseBytes(data[29]),
            Integer.reverseBytes(data[30]), Integer.reverseBytes(data[31]));

    ObjectNode sendWorkMessage = mapper.createObjectNode();
    sendWorkMessage.put("method", "getwork");
    ArrayNode params = sendWorkMessage.putArray("params");
    params.add(dataOutput.toString());
    sendWorkMessage.put("id", 1);

    JsonNode responseMessage = doJSONRPCCall(false, sendWorkMessage);

    boolean accepted;

    dataFormatter.close();

    try {
        accepted = responseMessage.getBooleanValue();
    } catch (Exception e) {
        throw new IOException("Bitcoin returned unparsable JSON");
    }

    return accepted;
}

From source file:com.itemanalysis.psychometrics.rasch.Theta.java

public String toStringWithRawScore(String title, boolean header, boolean footer) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    if (header) {
        f.format("%-50s", title);
        f.format("%n");
        f.format("%50s", "==================================================");
        f.format("%n");
        f.format("%10s", "Sum Score");
        f.format("%2s", " ");
        f.format("%10s", "Theta");
        f.format("%2s", " ");
        f.format("%10s", "Std. Error");
        f.format("%2s", " ");
        f.format("%10s", "Frequency");
        f.format("%2s", " ");
        f.format("%n");
        f.format("%50s", "--------------------------------------------------");
        f.format("%n");
    }/*from www  .  j a  va  2s .c  o m*/
    f.format("%10.4f", rawScore);
    f.format("%2s", " ");
    f.format("%10.4f", theta);
    f.format("%2s", " ");
    if (rawScore == 0 || rawScore == maximumPossibleScore) {
        f.format("%10.4s", "--");
        f.format("%2s", " ");
    } else {
        f.format("%10.4f", stdError);
        f.format("%2s", " ");
    }
    f.format("%10.0f", freq);
    f.format("%n");
    if (footer) {
        f.format("%50s", "==================================================");
        f.format("%n");
    }

    return f.toString();
}

From source file:adapters.HistogramChartAdapter.java

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);/*from  w  ww .ja  v  a 2  s.  com*/

    // 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:fr.inrialpes.exmo.align.cli.WGroupEval.java

public void printHTML(Vector<Vector<Object>> result, PrintStream writer) {
    // variables for computing iterative harmonic means
    int expected = 0; // expected so far
    int foundVect[]; // found so far
    int correctFoundVect[]; // correct so far
    int correctExpVect[]; // correct so far
    long timeVect[]; // time so far
    fsize = format.length();// w  w w.  j  av a 2 s  .  c  om
    // JE: the writer should be put out
    // JE: the h-means computation should be put out as well
    Formatter formatter = new Formatter(writer);

    // Print the header
    if (embedded != true)
        writer.println("<html><head></head><body>");
    writer.println("<table border='2' frame='sides' rules='groups'>");
    writer.println("<colgroup align='center' />");
    // for each algo <td spancol='2'>name</td>
    for (String m : listAlgo) {
        writer.println("<colgroup align='center' span='" + fsize + "' />");
    }
    // For each file do a
    writer.println("<thead valign='top'><tr><th>algo</th>");
    // for each algo <td spancol='2'>name</td>
    for (String m : listAlgo) {
        writer.println("<th colspan='" + fsize + "'>" + m + "</th>");
    }
    writer.println("</tr></thead><tbody><tr><td>test</td>");
    // for each algo <td>Prec.</td><td>Rec.</td>
    for (String m : listAlgo) {
        for (int i = 0; i < fsize; i++) {
            writer.print("<td>");
            if (format.charAt(i) == 'p') {
                writer.print("Prec.");
            } else if (format.charAt(i) == 'f') {
                writer.print("FMeas.");
            } else if (format.charAt(i) == 'o') {
                writer.print("Over.");
            } else if (format.charAt(i) == 't') {
                writer.print("Time");
            } else if (format.charAt(i) == 'r') {
                writer.print("Rec.");
            }
            writer.println("</td>");
        }
        //writer.println("<td>Prec.</td><td>Rec.</td>");
    }
    writer.println("</tr></tbody><tbody>");
    foundVect = new int[size];
    correctFoundVect = new int[size];
    correctExpVect = new int[size];
    timeVect = new long[size];
    for (int k = size - 1; k >= 0; k--) {
        foundVect[k] = 0;
        correctFoundVect[k] = 0;
        correctExpVect[k] = 0;
        timeVect[k] = 0;
    }
    // </tr>
    // For each directory <tr>
    boolean colored = false;
    for (Vector<Object> test : result) {
        double newexpected = -1.;
        if (colored == true && color != null) {
            colored = false;
            writer.println("<tr bgcolor=\"" + color + "\">");
        } else {
            colored = true;
            writer.println("<tr>");
        }
        ;
        // Print the directory <td>bla</td>
        writer.println("<td>" + (String) test.get(0) + "</td>");
        // For each record print the values <td>bla</td>
        Enumeration<Object> f = test.elements();
        f.nextElement();
        for (int k = 0; f.hasMoreElements(); k++) {
            WeightedPREvaluator eval = (WeightedPREvaluator) f.nextElement();
            if (eval != null) {
                // iterative H-means computation
                if (newexpected == -1.) {
                    newexpected = eval.getExpected();
                    expected += newexpected;
                }
                foundVect[k] += eval.getFound();
                correctFoundVect[k] += eval.getCorrectFound();
                correctExpVect[k] += eval.getCorrectExpected();
                timeVect[k] += eval.getTime();

                for (int i = 0; i < fsize; i++) {
                    writer.print("<td>");
                    if (format.charAt(i) == 'p') {
                        formatter.format("%1.2f", eval.getPrecision());
                    } else if (format.charAt(i) == 'f') {
                        formatter.format("%1.2f", eval.getFmeasure());
                    } else if (format.charAt(i) == 'o') {
                        formatter.format("%1.2f", eval.getOverall());
                    } else if (format.charAt(i) == 't') {
                        if (eval.getTime() == 0) {
                            writer.print("-");
                        } else {
                            formatter.format("%1.2f", eval.getTime());
                        }
                    } else if (format.charAt(i) == 'r') {
                        formatter.format("%1.2f", eval.getRecall());
                    }
                    writer.println("</td>");
                }
            } else { // JE 2013: will break if the previous tests are all NULL
                correctExpVect[k] += newexpected;
                // Nothing needs to be incremented for precision
                for (int i = 0; i < fsize; i++)
                    writer.print("<td>n/a</td>");
                writer.println();
            }
        }
        writer.println("</tr>");
    }
    writer.print("<tr bgcolor=\"yellow\"><td>H-mean</td>");
    // Here we are computing a sheer average.
    // While in the column results we print NaN when the returned
    // alignment is empty,
    // here we use the real values, i.e., add 0 to both correctVect and
    // foundVect, so this is OK for computing the average.
    int k = 0;
    // ???
    for (String m : listAlgo) {
        double precision = 1. - (double) correctFoundVect[k] / foundVect[k];
        double recall = 1. - (double) correctExpVect[k] / expected;
        for (int i = 0; i < fsize; i++) {
            writer.print("<td>");
            if (format.charAt(i) == 'p') {
                formatter.format("%1.2f", precision);
            } else if (format.charAt(i) == 'f') {
                formatter.format("%1.2f", 2 * precision * recall / (precision + recall));
            } else if (format.charAt(i) == 'o') {
                formatter.format("%1.2f", recall * (2 - (1 / precision)));
            } else if (format.charAt(i) == 't') {
                if (timeVect[k] == 0) {
                    writer.print("-");
                } else {
                    formatter.format("%1.2f", timeVect[k]);
                }
            } else if (format.charAt(i) == 'r') {
                formatter.format("%1.2f", recall);
            }
            writer.println("</td>");
        }
        ;
        k++;
    }
    writer.println("</tr>");
    writer.println("</tbody></table>");
    writer.println("<p><small>n/a: result alignment not provided or not readable<br />");
    writer.println("NaN: division per zero, likely due to empty alignment.</small></p>");
    if (embedded != true)
        writer.println("</body></html>");
}

From source file:com.itemanalysis.psychometrics.irt.estimation.MarginalMaximumLikelihoodEstimation.java

public String printItemFitStatistics() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    f.format("%34s", "ITEM FIT STATISTIC");
    f.format("%n");
    f.format("%50s", "==================================================");
    f.format("%n");
    f.format("%-18s", "Item");
    f.format("%2s", "");
    if (g2ItemFit) {
        f.format("%8s", "G2");
    } else {//from   ww  w .  java 2 s.  co m
        f.format("%8s", "S-X2");
    }
    f.format("%2s", "");
    f.format("%8s", "df");
    f.format("%2s", "");
    f.format("%8s", "p-value");
    f.format("%n");
    f.format("%50s", "--------------------------------------------------");
    f.format("%n");

    for (int j = 0; j < nItems; j++) {
        f.format("%-18s", irm[j].getName());
        f.format("%2s", "");
        f.format("%8.4f", itemFit[j].getValue());
        f.format("%2s", "");
        f.format("%8.4f", itemFit[j].getDegreesOfFreedom());
        f.format("%2s", "");
        f.format("%8.4f", itemFit[j].getPValue());
        f.format("%n");
    }

    f.format("%50s", "==================================================");
    f.format("%n");

    return f.toString();
}

From source file:org.opengeoportal.proxy.controllers.DynamicOgcController.java

/**
* <p>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
*///  w  w  w .j  ava  2s . c o m
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
            formatter.close();
        }
    }
    return outBuf != null ? outBuf : in;
}

From source file:com.itemanalysis.psychometrics.cmh.CochranMantelHaenszel.java

@Override
public String toString() {
    StringBuilder buffer = new StringBuilder();
    Formatter f = new Formatter(buffer);
    ChiSquaredDistribution chiSquare = new ChiSquaredDistribution(1.0);

    double cmh = cochranMantelHaenszel();
    Double pvalue = 1.0;//  w  w w.j  a v a 2 s  .  c  om
    pvalue = 1.0 - chiSquare.cumulativeProbability(cmh);

    double commonOddsRatio = 0.0;
    double[] tempConfInt = { 0.0, 0.0 };
    double[] confInt = { 0.0, 0.0 };
    double smd = 0.0;
    double effectSize = 0.0;
    String etsClass = "";

    if (itemVariable.getType().getItemType() == ItemType.BINARY_ITEM) {
        commonOddsRatio = commonOddsRatio();
        tempConfInt = commonOddsRatioConfidenceInterval(commonOddsRatio);
        if (etsDelta) {
            effectSize = etsDelta(commonOddsRatio);
            confInt[0] = etsDelta(tempConfInt[0]);
            confInt[1] = etsDelta(tempConfInt[1]);
        } else {
            effectSize = commonOddsRatio;
            confInt[0] = tempConfInt[0];
            confInt[1] = tempConfInt[1];
        }
        etsClass = etsBinayClassification(cmh, pvalue, commonOddsRatio);
    } else if (itemVariable.getType().getItemType() == ItemType.POLYTOMOUS_ITEM) {
        smd = pF();
        tempConfInt = smdConfidenceInterval(smd);
        confInt[0] = tempConfInt[0];
        confInt[1] = tempConfInt[1];
        effectSize = pF();
        //            etsClass = etsPolytomousClassification(cmh, pvalue, effectSize);
        etsClass = smdDifClass();
    }

    f.format("%-10s", itemVariable.getName().toString());
    f.format("%2s", " ");
    //      f.format("%10s", focalCode + "/" + referenceCode);f.format("%2s", " ");
    f.format("%10.2f", cmh);
    f.format("%2s", " ");
    f.format("%7.2f", pvalue);
    f.format("%2s", " ");
    f.format("%7.0f", validSampleSize);
    f.format("%2s", " ");
    f.format("%8.2f", effectSize);
    f.format(" (%8.2f", confInt[0]);
    f.format(",%8.2f)", confInt[1]);
    f.format("%2s", " ");
    f.format("%5s", etsClass);
    f.format("%2s", " ");
    return f.toString();
}

From source file:umontreal.ssj.charts.XYLineChart.java

/**
 * @name Latex-specific method//from w  ww  . jav a  2s  . co  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();
}