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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations