Search in sources :

Example 11 with NumberFormat

use of java.text.NumberFormat in project cogtool by cogtool.

the class ResultStep method toString.

@Override
public String toString() {
    StringBuilder out = new StringBuilder();
    //TODO: Localize the following strings
    NumberFormat nFmtr = NumberFormat.getInstance(Locale.US);
    nFmtr.setMaximumFractionDigits(3);
    nFmtr.setMinimumFractionDigits(3);
    if (targetResource == null) {
        out.append("Operation: " + operation);
        out.append("\nResource:  " + resource);
    } else {
        out.append("Cascade\n from " + targetResource + "\n to " + resource);
    }
    out.append("\n\nStart Time: " + nFmtr.format(startTime / 1000) + " s");
    out.append("\nDuration:   " + nFmtr.format(duration / 1000) + " s");
    out.append("\nEnd Time: " + nFmtr.format((startTime + duration) / 1000) + " s");
    out.append("\nTrace Start: " + traceStart);
    out.append("\nTrace End: " + traceEnd);
    //        if (object != null) {
    //            out.append("\n\nObject:  " + object);
    //        }
    Iterator<ResultStep.ResultStepDependency> depIt = dependencies.iterator();
    while (depIt.hasNext()) {
        ResultStepDependency dependency = depIt.next();
        out.append("\nDependency on:  " + dependency.dependency.operation + "\n   at start time: " + nFmtr.format(startTime / 1000) + " s");
    }
    return out.toString();
}
Also used : NumberFormat(java.text.NumberFormat)

Example 12 with NumberFormat

use of java.text.NumberFormat in project cogtool by cogtool.

the class CogTool method getMemoryUsage.

public static String getMemoryUsage() {
    Runtime rt = Runtime.getRuntime();
    long max = rt.maxMemory();
    long free = rt.freeMemory();
    long total = rt.totalMemory();
    double used = (100.0 * (total - free)) / total;
    NumberFormat fmt = NumberFormat.getInstance();
    fmt.setMinimumIntegerDigits(1);
    fmt.setMinimumFractionDigits(2);
    fmt.setMaximumFractionDigits(2);
    fmt.setGroupingUsed(true);
    StringBuilder result = new StringBuilder(L10N.get("CT.Memory", "Memory usage: "));
    // TODO this is not properly locale sensitive, as it assumes US
    //      conventions for percent format and lists
    result.append(fmt.format(used));
    result.append(L10N.get("CT.PercentOf", "% of "));
    result.append(fmt.format(total / 1000000.0));
    result.append(";  ");
    result.append(fmt.format(max / 1000000.0));
    return result.toString();
}
Also used : NumberFormat(java.text.NumberFormat)

Example 13 with NumberFormat

use of java.text.NumberFormat in project deeplearning4j by deeplearning4j.

the class Counter method toStringSortedByKeys.

public String toStringSortedByKeys() {
    StringBuilder sb = new StringBuilder("[");
    NumberFormat f = NumberFormat.getInstance();
    f.setMaximumFractionDigits(5);
    int numKeysPrinted = 0;
    for (E element : new TreeSet<>(keySet())) {
        sb.append(element.toString());
        sb.append(" : ");
        sb.append(f.format(getCount(element)));
        if (numKeysPrinted < size() - 1)
            sb.append(", ");
        numKeysPrinted++;
    }
    if (numKeysPrinted < size())
        sb.append("...");
    sb.append("]");
    return sb.toString();
}
Also used : NumberFormat(java.text.NumberFormat)

Example 14 with NumberFormat

use of java.text.NumberFormat in project deeplearning4j by deeplearning4j.

the class PriorityQueue method toString.

/**
     * Returns a representation of the queue in decreasing priority order,
     * displaying at most maxKeysToPrint elements and optionally printing
     * one element per line.
     *
     * @param maxKeysToPrint maximum number of keys to print
     * @param multiline if is set to true, prints each element on new line. Prints elements in one line otherwise.
     */
public String toString(int maxKeysToPrint, boolean multiline) {
    PriorityQueue<E> pq = clone();
    StringBuilder sb = new StringBuilder(multiline ? "" : "[");
    int numKeysPrinted = 0;
    NumberFormat f = NumberFormat.getInstance();
    f.setMaximumFractionDigits(5);
    while (numKeysPrinted < maxKeysToPrint && pq.hasNext()) {
        double priority = pq.getPriority();
        E element = pq.next();
        sb.append(element == null ? "null" : element.toString());
        sb.append(" : ");
        sb.append(f.format(priority));
        if (numKeysPrinted < size() - 1)
            sb.append(multiline ? "\n" : ", ");
        numKeysPrinted++;
    }
    if (numKeysPrinted < size())
        sb.append("...");
    if (!multiline)
        sb.append("]");
    return sb.toString();
}
Also used : NumberFormat(java.text.NumberFormat)

Example 15 with NumberFormat

use of java.text.NumberFormat in project NewPipe by TeamNewPipe.

the class Localization method localizeViewCount.

public static String localizeViewCount(long viewCount, Context context) {
    Locale locale = getPreferredLocale(context);
    Resources res = context.getResources();
    String viewsString = res.getString(R.string.view_count_text);
    NumberFormat nf = NumberFormat.getInstance(locale);
    String formattedViewCount = nf.format(viewCount);
    return String.format(viewsString, formattedViewCount);
}
Also used : Locale(java.util.Locale) Resources(android.content.res.Resources) NumberFormat(java.text.NumberFormat)

Aggregations

NumberFormat (java.text.NumberFormat)429 DecimalFormat (java.text.DecimalFormat)87 BigDecimal (java.math.BigDecimal)23 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)23 Locale (java.util.Locale)22 Map (java.util.Map)18 Test (org.junit.Test)17 ParseException (java.text.ParseException)15 DecimalFormatSymbols (java.text.DecimalFormatSymbols)14 JFreeChart (org.jfree.chart.JFreeChart)13 XYSeries (org.jfree.data.xy.XYSeries)11 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)11 Intent (android.content.Intent)10 ParsePosition (java.text.ParsePosition)10 View (android.view.View)8 TextView (android.widget.TextView)8 Paint (android.graphics.Paint)7 Rect (android.graphics.Rect)6 IOException (java.io.IOException)6