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:com.hazelcast.stabilizer.Utils.java

public static String formatLong(long number, int length) {
    StringBuffer sb = new StringBuffer();
    Formatter f = new Formatter(sb);
    f.format("%,d", number);

    return padLeft(sb.toString(), length);
}

From source file:ca.nines.ise.cmd.Wikify.java

/**
 * Wikify a tag.//from  ww  w. j a  v  a 2s .  c o  m
 *
 * @param out
 * @param tag
 */
private static void wikifySchemaAttrInfo(PrintStream out, Tag tag) {
    if (tag.countAttributes() == 0) {
        return;
    }
    Formatter fmt = new Formatter(out);
    fmt.format("|| Name || Type || Optional || Empty || Renumberable || Depreciated || Options ||%n");
    for (Attribute attr : tag.getAttributes()) {
        fmt.format("|| ''%s'' || %s || %s || %s || %s || %s || %s ||%n", attr.getName(), attr.getType(),
                attr.isOptional(), attr.isEmpty(), attr.isRenumberable(), attr.getDepreciated(),
                wikifySchemaAttrOptions(attr));
        fmt.format("{{{#!td%n}}}%n{{{#!td colspan=7%n%s%n}}}%n|-------------------%n", attr.getDescription());
    }
    out.println();
}

From source file:fll.web.scoreEntry.ScoreEntry.java

/**
 * Genrate the increment methods and variable declarations for the goals in
 * the performance element of document. Generate the methods to compute goals
 * as well./*w  w  w.  ja v  a 2 s.c o  m*/
 * 
 * @throws ParseException
 */
public static void generateIncrementMethods(final Writer writer, final ServletContext application)
        throws IOException, ParseException {
    final ChallengeDescription description = ApplicationAttributes.getChallengeDescription(application);
    final PerformanceScoreCategory performanceElement = description.getPerformance();
    final Formatter formatter = new Formatter(writer);

    for (final AbstractGoal goal : performanceElement.getGoals()) {
        if (goal.isComputed()) {
            // generate the method to update the computed goal variables
            final String goalName = goal.getName();
            formatter.format("<!-- %s -->%n", goalName);
            formatter.format("var %s;%n", getVarNameForComputedScore(goalName));
            generateComputedGoalFunction(formatter, (ComputedGoal) goal);
        } else {
            final String name = goal.getName();
            final double min = goal.getMin();
            final double max = goal.getMax();
            final String rawVarName = getVarNameForRawScore(name);

            formatter.format("<!-- %s -->%n", name);
            formatter.format("var %s;%n", rawVarName);
            formatter.format("var %s;%n", getVarNameForComputedScore(name));

            // set method
            formatter.format("function %s(newValue) {%n", getSetMethodName(name));
            formatter.format("  var temp = %s;%n", rawVarName);
            formatter.format("  %s = newValue;%n", rawVarName);
            formatter.format("  if(!isConsistent()) {%n");
            formatter.format("    %s = temp;%n", rawVarName);
            formatter.format("  }%n");
            formatter.format("  refresh();%n");
            formatter.format("}%n");

            // check input method
            formatter.format("function %s() {%n", getCheckMethodName(name));
            formatter.format("  var str = document.scoreEntry.%s.value;%n", name);
            if (ScoreType.FLOAT == goal.getScoreType()) {
                formatter.format("  var num = parseFloat(str);%n");
            } else {
                formatter.format("  var num = parseInt(str);%n");
            }
            formatter.format("  if(!isNaN(num)) {%n");
            formatter.format("    %s(num);%n", getSetMethodName(name));
            formatter.format("  }%n");
            formatter.format("  refresh();%n");
            formatter.format("}%n");

            if (!goal.isEnumerated() && !goal.isYesNo()) {
                formatter.format("function %s(increment) {%n", getIncrementMethodName(name));
                formatter.format("  var temp = %s%n", rawVarName);
                formatter.format("  %s += increment;%n", rawVarName);
                formatter.format("  if(%s > %s) {%n", rawVarName, max);
                formatter.format("    %s = %s;%n", rawVarName, max);
                formatter.format("   }%n");
                formatter.format("  if(%s < %s) {%n", rawVarName, min);
                formatter.format("    %s = %s;%n", rawVarName, min);
                formatter.format("   }%n");
                formatter.format("  if(!isConsistent()) {%n");
                formatter.format("    %s = temp;%n", rawVarName);
                formatter.format("  }%n");
                formatter.format("  refresh();%n");
                formatter.format("}%n");
            }

            formatter.format("%n%n");
        }
    } // end for each goal

    // method for double-check field
    formatter.format("<!-- Verified -->%n");
    formatter.format("var Verified;%n");
    formatter.format("function %s(newValue) {%n", getSetMethodName("Verified"));
    formatter.format("  Verified = newValue;%n");
    formatter.format("  if (newValue == 1 && document.getElementsByName('EditFlag').length == 0) {");
    formatter.format("    replaceText('verification_error', 'Are you sure this score has been Verified?');");
    formatter.format("  } else if (newValue == 0) {");
    formatter.format("    replaceText('verification_error', '');");
    formatter.format("  }");
    formatter.format("  refresh();%n");
    formatter.format("}%n%n%n");
}

From source file:com.itemanalysis.psychometrics.factoranalysis.ExploratoryFactorAnalysis.java

/**
 * Formatted output of the results. It includes the factor loadings, communalities, and unqiuenesses.
 *
 * @param precision number of decimal places to report
 * @return string of result//  w w w . ja  va2 s .c  o m
 */
public String printOutput(int precision) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    int size = 24;
    String line1 = "=========================";
    String line2 = "-------------------------";
    for (int j = 0; j < nFactors; j++) {
        size = size + 10;
        line1 += "==========";
        line2 += "----------";
    }
    size = size + 10;
    line1 += "==========";
    line2 += "----------";
    size = size + 6;
    line1 += "======";
    line2 += "------";

    f.format("%36s", title);
    f.format("%n");
    f.format("%" + size + "s", line1);
    f.format("%n");
    f.format("%20s", "Name");
    f.format("%4s", "");
    for (int j = 0; j < nFactors; j++) {
        f.format("%6s", "F" + (j + 1));
        f.format("%4s", "");
    }
    f.format("%6s", "H2");
    f.format("%4s", "");
    f.format("%6s", "U2");
    f.format("%n");
    f.format("%" + size + "s", line2);
    f.format("%n");

    for (int i = 0; i < nVariables; i++) {
        f.format("%20s", "V" + (i + 1));
        f.format("%5s", "");
        for (int j = 0; j < nFactors; j++) {
            f.format("%6." + precision + "f", factorMethod.getFactorLoadingAt(i, j));
            f.format("%4s", "");
        }
        f.format("%6." + precision + "f", factorMethod.getCommunalityAt(i));
        f.format("%4s", "");
        f.format("%6." + precision + "f", factorMethod.getUniquenessAt(i));
        f.format("%n");
    }

    f.format("%" + size + "s", line1);
    f.format("%n");
    f.format("%30s", "Value of the objective function = ");
    f.format("%-8.4f", fmin);
    f.format("%n");
    f.format("%n");

    f.format("%20s", "");
    for (int j = 0; j < nFactors; j++) {
        f.format("%6s", "F" + (j + 1));
        f.format("%2s", "");
    }
    f.format("%n");

    f.format("%20s", "SS loadings");
    for (int j = 0; j < nFactors; j++) {
        f.format("%6." + precision + "f", factorMethod.getSumsOfSquaresAt(j));
        f.format("%2s", "");
    }
    f.format("%n");

    f.format("%20s", "Proportion Var");
    for (int j = 0; j < nFactors; j++) {
        f.format("%6." + precision + "f", factorMethod.getProportionOfVarianceAt(j));
        f.format("%2s", "");
    }
    f.format("%n");

    f.format("%20s", "Proportion Explained");
    for (int j = 0; j < nFactors; j++) {
        f.format("%6." + precision + "f", factorMethod.getProportionOfExplainedVarianceAt(j));
        f.format("%2s", "");
    }
    f.format("%n");

    return f.toString();
}

From source file:umontreal.iro.lecuyer.charts.SSJXYSeriesCollection.java

/**
 * Returns in a <TT>String</TT> all data contained in the current object.
 * //from ww w .j  a v a2s  . c  o m
 * @return All data contained in the current object as a {@link String}.
 * 
 */
public String toString() {
    Formatter formatter = new Formatter(Locale.US);
    for (int i = 0; i < seriesCollection.getSeriesCount(); i++) {
        formatter.format(" Series " + i + " : %n");
        for (int j = 0; j < seriesCollection.getItemCount(i); j++)
            formatter.format("%15e,%15e%n", getX(i, j), getY(i, j));
    }
    return formatter.toString();
}

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

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

    double[] rowSE = getRowThresholdStandardErrors();
    double[] colSE = getColumnThresholdStandardErrors();

    f.format("%34s", "Polychoric correlation, ML est. = ");
    f.format("%6.4f", rho);
    f.format(" (%6.4f)", variance[0][0]);
    f.format("%n");
    f.format("%41s", "Test of bivariate normality: Chisquare = ");
    f.format("%-8.4f", chiSquare);
    f.format("%6s", " df = ");
    f.format("%-6.0f", df);
    f.format("%5s", " p = ");
    f.format("%-6.4f", probChiSquare);
    f.format("%n");
    f.format("%n");
    f.format("%18s", "Row Thresholds");
    f.format("%n");
    f.format("%-15s", "Threshold");
    f.format("%-10s", "Std.Err.");
    f.format("%n");

    for (int i = 0; i < rowThresholds.length; i++) {
        f.format("%6.4f", rowThresholds[i]);
        f.format("%9s", "");
        f.format("%6.4f", rowSE[i]);
        f.format("%n");
    }//w w w. jav  a2 s  .  c o  m

    f.format("%n");
    f.format("%n");
    f.format("%19s", "Column Thresholds");
    f.format("%n");
    f.format("%-15s", "Threshold");
    f.format("%-10s", "Std.Err.");
    f.format("%n");

    for (int i = 0; i < columnThresholds.length; i++) {
        f.format("% 6.4f", columnThresholds[i]);
        f.format("%9s", "");
        f.format("% 6.4f", colSE[i]);
        f.format("%n");
    }

    f.format("%n");
    return f.toString();

}

From source file:com.yeldi.yeldibazaar.ManageRepo.java

private void redraw() {
    try {/*w w  w  .j  a v a2  s.  c om*/
        DB db = DB.getDB();
        repos = db.getRepos();
    } finally {
        DB.releaseDB();
    }

    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    Map<String, Object> server_line;

    for (DB.Repo repo : repos) {
        server_line = new HashMap<String, Object>();
        server_line.put("address", repo.address);
        if (repo.inuse) {
            server_line.put("inuse", R.drawable.btn_check_on);
        } else {
            server_line.put("inuse", R.drawable.btn_check_off);
        }
        if (repo.pubkey != null) {
            try {
                MessageDigest digest = MessageDigest.getInstance("SHA-1");
                digest.update(Hasher.unhex(repo.pubkey));
                byte[] fingerprint = digest.digest();
                Formatter formatter = new Formatter(new StringBuilder());
                formatter.format("%02X", fingerprint[0]);
                for (int i = 1; i < fingerprint.length; i++) {
                    formatter.format(i % 5 == 0 ? " %02X" : ":%02X", fingerprint[i]);
                }
                server_line.put("fingerprint", formatter.toString());
                formatter.close();
            } catch (Exception e) {
                Log.w("FDroid", "Unable to get certificate fingerprint.\n" + Log.getStackTraceString(e));
            }
        }
        result.add(server_line);
    }
    SimpleAdapter show_out = new SimpleAdapter(this, result, R.layout.repolisticons,
            new String[] { "address", "inuse", "fingerprint" },
            new int[] { R.id.uri, R.id.img, R.id.fingerprint });

    setListAdapter(show_out);
}

From source file:org.apache.jackrabbit.oak.plugins.segment.RecordUsageAnalyser.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    @SuppressWarnings("resource")
    Formatter formatter = new Formatter(sb);
    formatter.format("%s in maps (%s leaf and branch records)%n", byteCountToDisplaySize(mapSize), mapCount);
    formatter.format("%s in lists (%s list and bucket records)%n", byteCountToDisplaySize(listSize), listCount);
    formatter.format(// www. j a v  a 2 s .  c om
            "%s in values (value and block records of %s properties, "
                    + "%s/%s/%s/%s small/medium/long/external blobs, %s/%s/%s small/medium/long strings)%n",
            byteCountToDisplaySize(valueSize), propertyCount, smallBlobCount, mediumBlobCount, longBlobCount,
            externalBlobCount, smallStringCount, mediumStringCount, longStringCount);
    formatter.format("%s in templates (%s template records)%n", byteCountToDisplaySize(templateSize),
            templateCount);
    formatter.format("%s in nodes (%s node records)%n", byteCountToDisplaySize(nodeSize), nodeCount);
    formatter.format("links to non existing segments: %s", deadLinks);
    return sb.toString();
}

From source file:contrail.stages.CompressAndCorrect.java

/**
 * Remove the tips in the graph.//from   w ww  . java2  s . c o  m
 * @param inputPath
 * @param outputPath
 * @return True if any tips were removed.
 */
private JobInfo removeTips(String inputPath, String outputPath) throws Exception {
    RemoveTipsAvro stage = new RemoveTipsAvro();
    stage.setConf(getConf());
    // Make a shallow copy of the stage options required by the compress
    // stage.
    Map<String, Object> stageOptions = ContrailParameters.extractParameters(this.stage_options,
            stage.getParameterDefinitions().values());

    stageOptions.put("inputpath", inputPath);
    stageOptions.put("outputpath", outputPath);
    stage.setParameters(stageOptions);
    RunningJob job = stage.runJob();

    JobInfo result = new JobInfo();
    if (job == null) {
        result.logMessage = "RemoveTips stage was skipped because graph would not change.";
        sLogger.info(result.logMessage);
        result.graphPath = inputPath;
        result.graphChanged = false;
        return result;
    }

    // Check if any tips were found.
    long tipsRemoved = job.getCounters()
            .findCounter(RemoveTipsAvro.NUM_REMOVED.group, RemoveTipsAvro.NUM_REMOVED.tag).getValue();

    if (tipsRemoved > 0) {
        result.graphChanged = true;
    }
    result.graphPath = outputPath;

    Formatter formatter = new Formatter(new StringBuilder());
    result.logMessage = formatter.format("RemoveTips: number of nodes removed %d", tipsRemoved).toString();
    return result;
}

From source file:com.itemanalysis.psychometrics.measurement.ClassicalItemStatistics.java

/**
 * A string that contains all of the item statistics.
 *
 * @return string of estimated statistics
 *///ww w .j  av a  2  s  . co  m
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    f.format("% 10.4f", getDifficulty());
    f.format("%2s", " ");//category proportion endorsing
    f.format("% 10.4f", getStdDev());
    f.format("%2s", " ");//category standard deviation
    f.format("% 10.4f", getDiscrimination());
    f.format("%2s", " "); //item discrimination

    return f.toString();
}