public static String getTimeString(int milliSeconds) { long seconds = (milliSeconds % 60000L) / 1000L; long minutes = (milliSeconds % 3600000L) / 60000L; long hours = (milliSeconds % 86400000L) / 3600000L; long days = (milliSeconds % (86400000L * 7L)) / 86400000L; stringBuilder.setLength(0); return days > 0 ? stringFormatter.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds).toString() : hours > 0 ? stringFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString() : stringFormatter.format("%02d:%02d", minutes, seconds).toString(); }
private static String escapeUnicode(String input) { StringBuilder b = new StringBuilder(input.length()); Formatter formatter = new Formatter(b); for (char c : input.toCharArray()) { if (c < 128) { b.append(c); } else { formatter.format("\\u%04x", (int) c); } } formatter.close(); return b.toString(); } }
/** {@inheritDoc} */ public void formatValue(StringBuffer toAppendTo, Object value) { double elapsed = ((Number) value).doubleValue(); if (elapsed < 0) { toAppendTo.append('-'); elapsed = -elapsed; } Object[] parts = new Long[specs.size()]; for (int i = 0; i < specs.size(); i++) { parts[i] = specs.get(i).valueFor(elapsed); } Formatter formatter = new Formatter(toAppendTo, Locale.ROOT); try { formatter.format(printfFmt, parts); } finally { formatter.close(); } }
Formatter formatter = new Formatter(treeDebugLine); boolean isDone = (Math.abs(bestTree.getScore() - goldTree.getScore()) <= 0.00001 || goldTree.getScore() > bestTree.getScore()); String done = isDone ? "done" : ""; formatter.format("Tree %6d Highest tree: %12.4f Correct tree: %12.4f %s", treeNum, bestTree.getScore(), goldTree.getScore(), done); log.info(treeDebugLine.toString()); if (!isDone){ value = (1.0/trainingBatch.size()) * value; ArrayMath.multiplyInPlace(derivative, (1.0/trainingBatch.size()));
private static String escapeUnicode(String input) { StringBuilder b = new StringBuilder(input.length()); Formatter formatter = new Formatter(b); for (char c : input.toCharArray()) { if (c < 128) { b.append(c); } else { formatter.format("\\u%04x", (int) c); } } formatter.close(); return b.toString(); } }
/** * Returns the specified millisecond time formatted as a string. * * @param builder The builder that {@code formatter} will write to. * @param formatter The formatter. * @param timeMs The time to format as a string, in milliseconds. * @return The time formatted as a string. */ public static String getStringForTime(StringBuilder builder, Formatter formatter, long timeMs) { if (timeMs == C.TIME_UNSET) { timeMs = 0; } long totalSeconds = (timeMs + 500) / 1000; long seconds = totalSeconds % 60; long minutes = (totalSeconds / 60) % 60; long hours = totalSeconds / 3600; builder.setLength(0); return hours > 0 ? formatter.format("%d:%02d:%02d", hours, minutes, seconds).toString() : formatter.format("%02d:%02d", minutes, seconds).toString(); }
Formatter fmt = new Formatter().format(heading).format(":%n%n"); int index = 1; boolean displayCauses = getOnlyCause(errorMessages) == null; for (Message errorMessage : errorMessages) { int thisIdx = index++; fmt.format("%s) %s%n", thisIdx, errorMessage.getMessage()); for (int i = dependencies.size() - 1; i >= 0; i--) { Object source = dependencies.get(i); formatSource(fmt, source); if (!causes.containsKey(causeEquivalence)) { causes.put(causeEquivalence, thisIdx); fmt.format("Caused by: %s", Throwables.getStackTraceAsString(cause)); } else { int causeIdx = causes.get(causeEquivalence); fmt.format( "Caused by: %s (same stack trace as error #%s)", cause.getClass().getName(), causeIdx); fmt.format("%n"); fmt.format("1 error"); } else { fmt.format("%s errors", errorMessages.size()); return fmt.toString();
public void print(ReadOnlyTStore<T> zs, IZooReader zk, String lockPath, Formatter fmt, Set<Long> filterTxid, EnumSet<TStatus> filterStatus) throws KeeperException, InterruptedException { FateStatus fateStatus = getStatus(zs, zk, lockPath, filterTxid, filterStatus); for (TransactionStatus txStatus : fateStatus.getTransactions()) { fmt.format("txid: %s status: %-18s op: %-15s locked: %-15s locking: %-15s top: %s%n", txStatus.getTxid(), txStatus.getStatus(), txStatus.getDebug(), txStatus.getHeldLocks(), txStatus.getWaitingLocks(), txStatus.getTop()); } fmt.format(" %s transactions", fateStatus.getTransactions().size()); if (fateStatus.getDanglingHeldLocks().size() != 0 || fateStatus.getDanglingWaitingLocks().size() != 0) { fmt.format("%nThe following locks did not have an associated FATE operation%n"); for (Entry<String,List<String>> entry : fateStatus.getDanglingHeldLocks().entrySet()) fmt.format("txid: %s locked: %s%n", entry.getKey(), entry.getValue()); for (Entry<String,List<String>> entry : fateStatus.getDanglingWaitingLocks().entrySet()) fmt.format("txid: %s locking: %s%n", entry.getKey(), entry.getValue()); } }
private void writeSingleInteger(String fmt, int num, StringBuffer output, List<Special> numSpecials, Set<CellNumberStringMod> mods) { StringBuffer sb = new StringBuffer(); Formatter formatter = new Formatter(sb, locale); try { formatter.format(locale, fmt, num); } finally { formatter.close(); } writeInteger(sb, output, numSpecials, mods, false); }
/** * Formats number of milliseconds to a HH:MM representation * * TODO: implement automatic scale (e.g. 1d 7h instead of 31:13m) * @param millis * @return */ public String toHHMM(long millis) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); formatter .format("%2d:%2dm", millis / 1000 / 3600, (millis / 1000 / 60) % 60); return sb.toString(); }
/** * Formats the specified milliseconds to a human readable format * in the form of (Hours : Minutes : Seconds). If the specified * milliseconds is less than 0 the resulting format will be * "--:--" to represent an unknown time * * @param milliseconds The time in milliseconds to format * @return The human readable time */ public static String formatMs(long milliseconds) { if (milliseconds < 0) { return "--:--"; } long seconds = (milliseconds % DateUtils.MINUTE_IN_MILLIS) / DateUtils.SECOND_IN_MILLIS; long minutes = (milliseconds % DateUtils.HOUR_IN_MILLIS) / DateUtils.MINUTE_IN_MILLIS; long hours = (milliseconds % DateUtils.DAY_IN_MILLIS) / DateUtils.HOUR_IN_MILLIS; formatBuilder.setLength(0); if (hours > 0) { return formatter.format("%d:%02d:%02d", hours, minutes, seconds).toString(); } return formatter.format("%02d:%02d", minutes, seconds).toString(); } }
public static String stringForTime(int timeMs) { if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) { return "00:00"; } int totalSeconds = timeMs / 1000; int seconds = totalSeconds % 60; int minutes = (totalSeconds / 60) % 60; int hours = totalSeconds / 3600; StringBuilder stringBuilder = new StringBuilder(); Formatter mFormatter = new Formatter(stringBuilder, Locale.getDefault()); if (hours > 0) { return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString(); } else { return mFormatter.format("%02d:%02d", minutes, seconds).toString(); } }