Example usage for java.util Formatter format

List of usage examples for java.util Formatter format

Introduction

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

Prototype

public Formatter format(Locale l, String format, Object... args) 

Source Link

Document

Writes a formatted string to this object's destination using the specified locale, format string, and arguments.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.performance.ThroughputTestAE.java

public String getPerformanceaAnalysis() {
    StringBuilder sb = new StringBuilder();

    long sumMillis = 0;
    for (double timeValue : times) {
        sumMillis += timeValue;/*from w w  w. j a  va  2s .  c o  m*/
    }

    DescriptiveStatistics statTimes = new DescriptiveStatistics();
    for (Long timeValue : times) {
        statTimes.addValue((double) timeValue / 1000);
    }

    sb.append("Estimate after processing " + times.size() + " documents.");
    sb.append(LF);

    Formatter formatter = new Formatter(sb, Locale.US);

    formatter.format("Time / Document:       %,.3f (%,.3f)\n", statTimes.getMean(),
            statTimes.getStandardDeviation());
    formatter.format("Time / 10^4 Token:     %,.3f\n", getNormalizedTime(sumMillis, nrofTokens, 1000));
    formatter.format("Time / 10^4 Sentences: %,.3f\n", getNormalizedTime(sumMillis, nrofSentences, 1000));

    formatter.close();

    return sb.toString();
}

From source file:org.megam.deccanplato.provider.ProviderRegistry.java

public void Data() {
    StringBuilder strbd = new StringBuilder();
    final Formatter formatter = new Formatter(strbd);
    for (Map.Entry<String, Provider> entry : providersMap.entrySet()) {
        formatter.format("%10s = %s%n", entry.getKey(), entry.getValue());
    }//from   w w  w .j av a2  s . com
    for (Map.Entry<String, Set<BusinessActivity>> entry1 : bizActivityMap.entrySet()) {
        formatter.format("%10s = %s%n", entry1.getKey(), entry1.getValue());
    }
    formatter.close();

}

From source file:org.kalypso.model.wspm.tuhh.ui.export.sobek.SobekProfileDefExportOperation.java

private void writeNormalProfile(final String id, final String profileName, final IRecord[] points,
        final IProfile profil) {
    final Formatter formatter = getFormatter();
    formatter.format("CRDS id '%s' nm '%s' ty 10 st 0 lt sw 0 0 gl 0 gu 0 lt yz%n", id, profileName); //$NON-NLS-1$
    formatter.format("TBLE%n"); //$NON-NLS-1$

    final int widhtIndex = profil.indexOfProperty(IWspmConstants.POINT_PROPERTY_BREITE);
    final int heightIndex = profil.indexOfProperty(IWspmConstants.POINT_PROPERTY_HOEHE);

    for (final IRecord point : points) {
        final Number y = (Number) point.getValue(widhtIndex);
        final Number z = (Number) point.getValue(heightIndex);
        formatter.format(Locale.US, "%.4f %.4f <%n", y, z); //$NON-NLS-1$
    }/*w w w  .  j  a v  a2s  . c om*/
    formatter.format("tble%n"); //$NON-NLS-1$
    formatter.format("crds%n"); //$NON-NLS-1$
}

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

/**
 * Calculates the distortion between the original gray image and the final up sampled image
 *//*from w w w.j  ava2s . c  om*/
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.terrain.WorldChunk.java

@Override
public String getName() {
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb, Locale.US);
    formatter.format("Chunk [x=%1s, z=%1s]", getLocalX(), getLocalZ());
    return sb.toString();
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.over23.Over23IndividualCandidacy.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.over23.languages.read"),
            StringUtils.isEmpty(getLanguagesRead()) ? StringUtils.EMPTY : getLanguagesRead());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.write"),
            StringUtils.isEmpty(getLanguagesWrite()) ? StringUtils.EMPTY : getLanguagesWrite());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.speak"),
            StringUtils.isEmpty(getLanguagesSpeak()) ? StringUtils.EMPTY : getLanguagesSpeak());
    formatter.close();//from   w  ww.j ava 2 s.c  om
}

From source file:org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.AbstractFormAdapter.java

protected void migrateFields(final Set<Field> fields, final FormDefinition newForm,
        final FormMigrationSummary formSummary) {

    LayoutHelper helper = new LayoutHelper();

    fields.forEach(originalField -> {
        if (!StringUtils.isEmpty(originalField.getMovedToForm())) {
            return;
        }/*from www.  ja v  a 2  s.  com*/

        if (!Boolean.TRUE.equals(originalField.getGroupWithPrevious())) {
            helper.newRow();
        }

        String originalTypeCode = originalField.getFieldType().getCode();
        FieldAdapter adapter = adaptersRegistry.get(originalTypeCode);
        if (adapter == null) {
            // trying a backup adapter
            UnSupportedFieldAdapter unSupportedFieldAdapter = unSupportedAdapters.get(originalTypeCode);
            if (unSupportedFieldAdapter != null) {
                warn("Problems migrating field '" + originalField.getFieldName()
                        + "': the original field has an unsupported field type '" + originalTypeCode
                        + "'. It will be added on the new Form as a '"
                        + unSupportedFieldAdapter.getNewFieldType() + "'");
                unSupportedFieldAdapter.parseField(originalField, formSummary, newForm, helper::add);
            } else {
                warn("Cannot migrate field '" + originalField.getFieldName() + "': Unsupported field type '"
                        + originalTypeCode + "'");

                Formatter formatter = new Formatter();
                formatter.format(FormsMigrationConstants.UNSUPORTED_FIELD_HTML_TEMPLATE,
                        originalField.getFieldName(), originalTypeCode);

                LayoutComponent component = new LayoutComponent(FormsMigrationConstants.HTML_COMPONENT);
                component.addProperty(FormsMigrationConstants.HTML_CODE_PARAMETER, formatter.toString());
                formatter.close();

                helper.add(component);
            }
        } else {
            try {
                adapter.parseField(originalField, formSummary, newForm, helper::add);
            } catch (Exception ex) {
                warn("Cannot migrate field '" + originalField.getFieldName()
                        + "': Unexpected error, see message for details");
                ex.printStackTrace(migrationContext.getSystem().err());
            }
        }
    });

    newForm.setLayoutTemplate(helper.build());
}

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(//from w ww  .j a  v a 2 s  .  c o  m
            "%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:it.geosolutions.android.map.geostore.fragment.GeoStoreResourceListFragment.java

/**
 * Update the info about pagination and visibility of more button
 *//*from   w w w.  j av a 2  s  . co m*/
private void updateView() {
    int count = adapter.getCount();
    if (loader != null) {
        TextView infoView = (TextView) getView().findViewById(R.id.info);

        Formatter f = new Formatter();
        String info = f.format(getString(R.string.geostore_info_format), count, loader.totalCount).toString();
        f.close();
        infoView.setText(info);
        //      if(count < loader.totalCount){
        //         moreButton.setVisibility(Button.VISIBLE);
        //      }
    }

}

From source file:fungus.FluctuationObserver.java

@SuppressWarnings("unchecked")
public boolean execute() {

    if (CDState.getCycle() % period != 0)
        return false;

    updateStats();/*  w ww.  j  av  a2  s .  c om*/
    if (fluctuations.isEmpty())
        return false;

    StringBuilder sb = new StringBuilder();
    java.util.Formatter f = new java.util.Formatter(sb, Locale.US);

    Integer i = 0;

    HashMap<Integer, Integer> map = (HashMap<Integer, Integer>) fluctuations.clone();
    while (!map.isEmpty()) {
        Integer val = map.remove(i);
        if (val == null) {
            f.format("%1d:%1d, ", i, 0);
        } else {
            f.format("%1d:%1d, ", i, val);
        }
        i++;
    }

    // ah: remove last commaspace and add a newline
    sb.delete(sb.length() - 2, sb.length());
    sb.append("\n");

    // ah: TODO: copy experiment writer to get this writing to
    // a file, too, so i can make a graph out of it.
    try {
        FileOutputStream out = new FileOutputStream(filename, true);
        PrintStream p = new PrintStream(out);
        p.print(sb.toString());
        out.close();
    } catch (IOException e) {
        log.severe("Error writing fluctuation data to file");
        debug(e.getMessage());
    }

    log.info("fluctuation counts " + sb.toString());
    return false;
}