use of java.text.DecimalFormatSymbols in project camel by apache.
the class TimeUtils method printDuration.
/**
* Prints the duration in a human readable format as X days Y hours Z minutes etc.
*
* @param uptime the uptime in millis
* @return the time used for displaying on screen or in logs
*/
public static String printDuration(double uptime) {
// Code taken from Karaf
// https://svn.apache.org/repos/asf/karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/InfoAction.java
NumberFormat fmtI = new DecimalFormat("###,###", new DecimalFormatSymbols(Locale.ENGLISH));
NumberFormat fmtD = new DecimalFormat("###,##0.000", new DecimalFormatSymbols(Locale.ENGLISH));
uptime /= 1000;
if (uptime < 60) {
return fmtD.format(uptime) + " seconds";
}
uptime /= 60;
if (uptime < 60) {
long minutes = (long) uptime;
String s = fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute");
return s;
}
uptime /= 60;
if (uptime < 24) {
long hours = (long) uptime;
long minutes = (long) ((uptime - hours) * 60);
String s = fmtI.format(hours) + (hours > 1 ? " hours" : " hour");
if (minutes != 0) {
s += " " + fmtI.format(minutes) + (minutes > 1 ? " minutes" : " minute");
}
return s;
}
uptime /= 24;
long days = (long) uptime;
long hours = (long) ((uptime - days) * 24);
String s = fmtI.format(days) + (days > 1 ? " days" : " day");
if (hours != 0) {
s += " " + fmtI.format(hours) + (hours > 1 ? " hours" : " hour");
}
return s;
}
use of java.text.DecimalFormatSymbols in project zeppelin by apache.
the class TransferListener method transferSucceeded.
@Override
public void transferSucceeded(TransferEvent event) {
transferCompleted(event);
TransferResource resource = event.getResource();
long contentLength = event.getTransferredBytes();
if (contentLength >= 0) {
String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";
String throughput = "";
long duration = System.currentTimeMillis() - resource.getTransferStartTime();
if (duration > 0) {
DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
throughput = " at " + format.format(kbPerSec) + " KB/sec";
}
logger.info(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput + ")");
}
}
use of java.text.DecimalFormatSymbols in project cucumber-jvm by cucumber.
the class Stats method printDuration.
private void printDuration(PrintStream out) {
out.print(String.format("%dm", (totalDuration / ONE_MINUTE)));
DecimalFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(locale));
out.println(format.format(((double) (totalDuration % ONE_MINUTE)) / ONE_SECOND) + "s");
}
use of java.text.DecimalFormatSymbols in project jphp by jphp-compiler.
the class NumUtils method format.
@FastMethod
@Signature({ @Arg("number"), @Arg("pattern"), @Arg(value = "decSep", optional = @Optional(".")), @Arg(value = "groupSep", optional = @Optional(",")) })
public static Memory format(Environment env, Memory... args) {
try {
char decSep = args[2].toChar();
char groupSep = args[3].toChar();
DecimalFormat decimalFormat;
if (decSep == '.' && groupSep == ',')
decimalFormat = new DecimalFormat(args[1].toString(), DEFAULT_DECIMAL_FORMAT_SYMBOLS);
else {
DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols();
formatSymbols.setZeroDigit('0');
formatSymbols.setDecimalSeparator(decSep);
formatSymbols.setGroupingSeparator(groupSep);
decimalFormat = new DecimalFormat(args[1].toString(), formatSymbols);
}
return new StringMemory(decimalFormat.format(args[0].toDouble()));
} catch (IllegalArgumentException e) {
return Memory.FALSE;
}
}
use of java.text.DecimalFormatSymbols in project android-saripaar by ragunathjawahar.
the class AbstractNumberValidator method getFormat.
/**
* <p>Returns a <code>NumberFormat</code> for the specified <i>pattern</i>
* and/or <code>Locale</code>.</p>
*
* @param pattern The pattern used to validate the value against or
* <code>null</code> to use the default for the <code>Locale</code>.
* @param locale The locale to use for the currency format, system default if null.
* @return The <code>NumberFormat</code> to created.
*/
protected Format getFormat(String pattern, Locale locale) {
NumberFormat formatter = null;
boolean usePattern = (pattern != null && pattern.length() > 0);
if (!usePattern) {
formatter = (NumberFormat) getFormat(locale);
} else if (locale == null) {
formatter = new DecimalFormat(pattern);
} else {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
formatter = new DecimalFormat(pattern, symbols);
}
if (determineScale(formatter) == 0) {
formatter.setParseIntegerOnly(true);
}
return formatter;
}
Aggregations