Example usage for java.util Formatter toString

List of usage examples for java.util Formatter toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the result of invoking toString() on the destination for the output.

Usage

From source file:com.richtodd.android.quiltdesign.block.Swatch.java

public String getSortString() {
    if (m_sortString == null) {
        Color.colorToHSV(m_color, m_hsv);

        Formatter formatter = new Formatter();
        try {//w  w w.  java2 s .  com
            formatter.format("%03d-%03d-%03d", (int) m_hsv[0], (int) (m_hsv[1] * 100f),
                    (int) (m_hsv[2] * 100f));
            m_sortString = formatter.toString();
        } finally {
            formatter.close();
        }
    }

    return m_sortString;
}

From source file:org.apache.drill.parsers.DrqlParserAstTest.java

@Test
public void testQueryList() throws IOException {
    Joiner withNewline = Joiner.on("\n");
    //tests parsing all SQL that are encountered in the documentation
    for (int i = 1; i <= 15; i++) {

        File tempFile = getFile("q" + i + "_temp.drql.sm");
        File expectedFile = getFile("q" + i + ".drql.ast");
        File queryFile = getFile("q" + i + ".drql");

        String query = FileUtils.readFileToString(queryFile);
        String ast = AntlrParser.parseToAst(query).toStringTree();
        Formatter f = new Formatter();
        formatAst(AntlrParser.parseToAst(query), f, 0);

        query = withNewline.join(Resources.readLines(Resources.getResource("q" + i + ".drql"), Charsets.UTF_8));
        assertEquals(query, f.toString());

        FileUtils.writeStringToFile(tempFile, ast);

        assertEquals(withNewline.join(Files.readLines(expectedFile, Charsets.UTF_8)),
                withNewline.join(Files.readLines(expectedFile, Charsets.UTF_8)));
        assertEquals(String.format("sm files differs %s versus %s", expectedFile, tempFile),
                withNewline.join(Files.readLines(expectedFile, Charsets.UTF_8)),
                withNewline.join(Files.readLines(tempFile, Charsets.UTF_8)));
        assertTrue(String.format("sm files differs %s versus %s", expectedFile, tempFile),
                FileUtils.contentEquals(expectedFile, tempFile));

        FileUtils.forceDelete(tempFile);
    }//from   w w w.  j  av a 2s .c  o  m
}

From source file:com.itemanalysis.psychometrics.mixture.MvNormalComponentDistribution.java

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

    for (int i = 0; i < mu.getRowDimension(); i++) {
        f.format("% 8.2f", mu.getEntry(i, 0));
        f.format("%5s", "");
    }//from   w ww .  j av a 2  s . co  m
    f.format("%n");
    return f.toString();
}

From source file:com.imesha.imageprocessor.controllers.MainController.java

/**
 * Calculates the distortion between the original gray image and the final up sampled image
 *//* w  ww  .  ja  v a 2s.  c o m*/
private void calculateAndShowDistortion() {
    try {
        double distortion = ImageAnalyser.calculateAverageDistortion(this.originalGrayImage,
                this.bufferedImage);
        double sd = ImageAnalyser.calculateStandardDeviation(this.originalGrayImage, this.bufferedImage);
        StringBuilder stringBuilder = new StringBuilder();
        Formatter formatter = new Formatter(stringBuilder, Locale.US);
        formatter.format("Distortion : \n\t%.2f\nSD : \n\t%.2f", distortion, sd);
        MainController.showMessage(formatter.toString(), messageLabel);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.itemanalysis.psychometrics.polycor.PolychoricTwoStepOLD.java

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

    double r = this.value();
    double[] t = this.getRowThresholds();

    for (int i = 0; i < t.length - 1; i++) {
        f.format("% 6.4f", t[i]);
        f.format("%2s", "");
    }//from   ww w . j  ava2  s.  c o  m
    return f.toString();

}

From source file:url.Domain.java

public String getColor() {

    Random random = new Random();
    final float hue = random.nextFloat() + 0.5f;
    final float saturation = 0.9f;//1.0 for brilliant, 0.0 for dull
    final float luminance = 1.0f; //1.0 for brighter, 0.0 for black*/
    Color color = Color.getHSBColor(hue, saturation, luminance);

    Formatter f = new Formatter(new StringBuffer("#"));
    f.format("%06x", color.getRGB());
    f.toString();
    return f.toString();
}

From source file:org.omegat.core.team2.impl.HTTPRemoteRepository.java

/**
 * Use SHA-1 as file version./*from   w w  w . j  a va 2s.  c o m*/
 */
@Override
public String getFileVersion(String file) throws Exception {
    MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
    sha1.reset();

    // calculate SHA-1
    byte[] buffer = new byte[8192];
    InputStream in = new BufferedInputStream(new FileInputStream(file));
    try {
        while (true) {
            int len = in.read(buffer);
            if (len < 0) {
                break;
            }
            sha1.update(buffer, 0, len);
        }
    } finally {
        in.close();
    }

    // out as hex
    Formatter formatter = new Formatter();
    try {
        for (byte b : sha1.digest()) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    } finally {
        formatter.close();
    }
}

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

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    f.format("%5s", "G2  ");
    f.format("%8.4d", getValue());
    f.format("%2s", "");
    f.format("%4d", (int) getDegreesOfFreedom());
    f.format("%2s", "");
    f.format("%1.4f", getPValue());
    return f.toString();
}

From source file:org.gradle.internal.execution.impl.steps.SkipUpToDateStep.java

private void logOutOfDateReasons(List<String> reasons, UnitOfWork work) {
    if (LOGGER.isInfoEnabled()) {
        Formatter formatter = new Formatter();
        formatter.format("%s is not up-to-date because:", StringUtils.capitalize(work.getDisplayName()));
        for (String message : reasons) {
            formatter.format("%n  %s", message);
        }// w ww.  j  a  v  a  2s  .co  m
        LOGGER.info(formatter.toString());
    }
}

From source file:com.itemanalysis.psychometrics.mixture.MvNormalComponentDistribution.java

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

    for (int i = 0; i < sigma.getRowDimension(); i++) {
        for (int j = 0; j < sigma.getColumnDimension(); j++) {
            f.format("% 8.2f", sigma.getEntry(i, j));
            f.format("%5s", "");
        }// ww  w  . java2  s .  c  o m
        f.format("%n");
    }
    return f.toString();
}