Search in sources :

Example 1 with Formatter

use of java.util.Formatter in project lucida by claritylab.

the class HierarchicalClassifierTrainer method prettyPrintCM.

private String prettyPrintCM(Evaluation.Matrix matrix, String[] classes) {
    double[][] values = matrix.values;
    String[] classAbb = new String[classes.length];
    StringBuilder res = new StringBuilder();
    Formatter formatter = new Formatter(res, Locale.US);
    int max = 0;
    for (int i = 0; i < classes.length; i++) {
        classAbb[i] = classes[i].replaceAll("\\B(.{1,2}).*?(.)\\b", "$1$2");
        if (classAbb[i].length() > max)
            max = classAbb[i].length();
    }
    max++;
    String formatStr = "%-" + max + "s";
    formatter.format(formatStr, "");
    for (int i = 0; i < classes.length; i++) {
        formatter.format(formatStr, classAbb[i]);
    }
    res.append("\n\n");
    for (int i = 0; i < classes.length; i++) {
        formatter.format(formatStr, classAbb[i]);
        for (int j = 0; j < classes.length; j++) {
            formatter.format(formatStr, Double.toString(values[i][j]));
        }
        res.append("\n\n");
    }
    return res.toString();
}
Also used : Formatter(java.util.Formatter)

Example 2 with Formatter

use of java.util.Formatter in project hadoop by apache.

the class StoragePolicySummary method toString.

public String toString() {
    StringBuilder compliantBlocksSB = new StringBuilder();
    compliantBlocksSB.append("\nBlocks satisfying the specified storage policy:");
    compliantBlocksSB.append("\nStorage Policy                  # of blocks       % of blocks\n");
    StringBuilder nonCompliantBlocksSB = new StringBuilder();
    Formatter compliantFormatter = new Formatter(compliantBlocksSB);
    Formatter nonCompliantFormatter = new Formatter(nonCompliantBlocksSB);
    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMinimumFractionDigits(4);
    percentFormat.setMaximumFractionDigits(4);
    for (Map.Entry<StorageTypeAllocation, Long> storageComboCount : sortByComparator(storageComboCounts)) {
        double percent = (double) storageComboCount.getValue() / (double) totalBlocks;
        StorageTypeAllocation sta = storageComboCount.getKey();
        if (sta.policyMatches()) {
            compliantFormatter.format("%-25s %10d  %20s%n", sta.getStoragePolicyDescriptor(), storageComboCount.getValue(), percentFormat.format(percent));
        } else {
            if (nonCompliantBlocksSB.length() == 0) {
                nonCompliantBlocksSB.append("\nBlocks NOT satisfying the specified storage policy:");
                nonCompliantBlocksSB.append("\nStorage Policy                  ");
                nonCompliantBlocksSB.append("Specified Storage Policy      # of blocks       % of blocks\n");
            }
            nonCompliantFormatter.format("%-35s %-20s %10d  %20s%n", sta.getStoragePolicyDescriptor(), sta.getSpecifiedStoragePolicy().getName(), storageComboCount.getValue(), percentFormat.format(percent));
        }
    }
    if (nonCompliantBlocksSB.length() == 0) {
        nonCompliantBlocksSB.append("\nAll blocks satisfy specified storage policy.\n");
    }
    compliantFormatter.close();
    nonCompliantFormatter.close();
    return compliantBlocksSB.toString() + nonCompliantBlocksSB;
}
Also used : Formatter(java.util.Formatter) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Map(java.util.Map) NumberFormat(java.text.NumberFormat)

Example 3 with Formatter

use of java.util.Formatter in project android_frameworks_base by ParanoidAndroid.

the class DateUtils method formatElapsedTime.

/**
     * Formats an elapsed time in a format like "MM:SS" or "H:MM:SS" (using a form
     * suited to the current locale), similar to that used on the call-in-progress
     * screen.
     *
     * @param recycle {@link StringBuilder} to recycle, or null to use a temporary one.
     * @param elapsedSeconds the elapsed time in seconds.
     */
public static String formatElapsedTime(StringBuilder recycle, long elapsedSeconds) {
    // Break the elapsed seconds into hours, minutes, and seconds.
    long hours = 0;
    long minutes = 0;
    long seconds = 0;
    if (elapsedSeconds >= 3600) {
        hours = elapsedSeconds / 3600;
        elapsedSeconds -= hours * 3600;
    }
    if (elapsedSeconds >= 60) {
        minutes = elapsedSeconds / 60;
        elapsedSeconds -= minutes * 60;
    }
    seconds = elapsedSeconds;
    // Create a StringBuilder if we weren't given one to recycle.
    // TODO: if we cared, we could have a thread-local temporary StringBuilder.
    StringBuilder sb = recycle;
    if (sb == null) {
        sb = new StringBuilder(8);
    } else {
        sb.setLength(0);
    }
    // Format the broken-down time in a locale-appropriate way.
    // TODO: use icu4c when http://unicode.org/cldr/trac/ticket/3407 is fixed.
    Formatter f = new Formatter(sb, Locale.getDefault());
    initFormatStrings();
    if (hours > 0) {
        return f.format(sElapsedFormatHMMSS, hours, minutes, seconds).toString();
    } else {
        return f.format(sElapsedFormatMMSS, minutes, seconds).toString();
    }
}
Also used : Formatter(java.util.Formatter)

Example 4 with Formatter

use of java.util.Formatter in project android_frameworks_base by ParanoidAndroid.

the class StaticLayoutDirectionsTest method testDirections.

// @SmallTest
public void testDirections() {
    StringBuilder buf = new StringBuilder("\n");
    Formatter f = new Formatter(buf);
    LayoutBuilder b = StaticLayoutTest.builder();
    for (int i = 0; i < texts.length; ++i) {
        b.setText(pseudoBidiToReal(texts[i]));
        checkDirections(b.build(), i, b.text, expected, f);
    }
    if (buf.length() > 1) {
        fail(buf.toString());
    }
}
Also used : LayoutBuilder(android.text.StaticLayoutTest.LayoutBuilder) Formatter(java.util.Formatter)

Example 5 with Formatter

use of java.util.Formatter in project neo4j by neo4j.

the class DefaultUdcInformationCollector method determineMacAddress.

private String determineMacAddress() {
    String formattedMac = "0";
    try {
        InetAddress address = InetAddress.getLocalHost();
        NetworkInterface ni = NetworkInterface.getByInetAddress(address);
        if (ni != null) {
            byte[] mac = ni.getHardwareAddress();
            if (mac != null) {
                StringBuilder sb = new StringBuilder(mac.length * 2);
                Formatter formatter = new Formatter(sb);
                for (byte b : mac) {
                    formatter.format("%02x", b);
                }
                formattedMac = sb.toString();
            }
        }
    } catch (Throwable t) {
    //
    }
    return formattedMac;
}
Also used : Formatter(java.util.Formatter) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Aggregations

Formatter (java.util.Formatter)558 ArrayList (java.util.ArrayList)26 File (java.io.File)25 IOException (java.io.IOException)25 Date (java.util.Date)22 Test (org.junit.Test)19 HashMap (java.util.HashMap)16 Map (java.util.Map)16 AlertDialog (android.app.AlertDialog)14 DialogInterface (android.content.DialogInterface)14 MessageDigest (java.security.MessageDigest)14 PrintWriter (java.io.PrintWriter)13 Justif (aQute.lib.justif.Justif)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 Locale (java.util.Locale)11 BigInteger (java.math.BigInteger)10 PrintStream (java.io.PrintStream)9 Calendar (java.util.Calendar)7 LayoutBuilder (android.text.StaticLayoutTest.LayoutBuilder)6 View (android.view.View)6