@Override public String toString() { return String.format("Oliphaunt id=%d", id); } }
@Override public String toString() { return String.format("(ok=%s, access_token=%s, scope=%s, user_id=%s, team_name=%s, team_id=%s)", ok, access_token, scope, user_id, team_name, team_id); } }
String url = "http://example.com"; String charset = "UTF-8"; // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name() String param1 = "value1"; String param2 = "value2"; // ... String query = String.format("param1=%s¶m2=%s", URLEncoder.encode(param1, charset), URLEncoder.encode(param2, charset));
@Override public synchronized String toString() { return String.format("Pool available=%d inUse=%d", available.size(), inUse.size()); } }
public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); }
String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) );
String.format("%02d min, %02d sec", TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) );
@Override public String toString() { return String.format("%s.%s() %s", method.getDeclaringClass().getName(), method.getName(), arguments); } }
@Override public String toString() { return String.format("%s{%s}", getClass().getSimpleName(), super.toString()); } }
@Override public String toString() { return String.format("%s{%s}", getClass().getSimpleName(), super.toString()); } }
@Override public String toString() { return String.format("%s{%s}", getClass().getSimpleName(), super.toString()); } }
@Override public String toString() { return String.format("%s{%s}", getClass().getSimpleName(), super.toString()); } }
@Override public String toString() { return String.format("%s{%s}", getClass().getSimpleName(), super.toString()); } }
@Override public Response intercept(Chain chain) throws IOException { long t1 = System.nanoTime(); Request request = chain.request(); logger.info(String.format("Sending request %s on %s%n%s", request.url(), chain.connection(), request.headers())); Response response = chain.proceed(request); long t2 = System.nanoTime(); logger.info(String.format("Received response for %s in %.1fms%n%s", request.url(), (t2 - t1) / 1e6d, response.headers())); return response; } }
protected final NetworkConnections<N, E> checkedConnections(N node) { NetworkConnections<N, E> connections = nodeConnections.get(node); if (connections == null) { checkNotNull(node); throw new IllegalArgumentException(String.format(NODE_NOT_IN_GRAPH, node)); } return connections; }
protected final N checkedReferenceNode(E edge) { N referenceNode = edgeToReferenceNode.get(edge); if (referenceNode == null) { checkNotNull(edge); throw new IllegalArgumentException(String.format(EDGE_NOT_IN_GRAPH, edge)); } return referenceNode; }
private static void printContributors(GitHub gitHub, String owner, String repo) throws IOException { System.out.println(String.format("== Contributors for %s/%s ==", owner, repo)); Call<List<Contributor>> contributors = gitHub.contributors(owner, repo); for (Contributor contributor : contributors.execute().body()) { System.out.println(contributor.login + " (" + contributor.contributions + ")"); } System.out.println(); } }
private static String hmacToString(String methodName, Key key) { return String.format( "Hashing.%s(Key[algorithm=%s, format=%s])", methodName, key.getAlgorithm(), key.getFormat()); }
@Override public void writeTo(BufferedSink sink) throws IOException { sink.writeUtf8("Numbers\n"); sink.writeUtf8("-------\n"); for (int i = 2; i <= 997; i++) { sink.writeUtf8(String.format(" * %s = %s\n", i, factor(i))); } }
public void testKnownUtf8Hashing() { for (Cell<HashFunction, String, String> cell : KNOWN_HASHES.cellSet()) { HashFunction func = cell.getRowKey(); String input = cell.getColumnKey(); String expected = cell.getValue(); assertEquals( String.format(Locale.ROOT, "Known hash for hash(%s, UTF_8) failed", input), expected, func.hashString(input, UTF_8).toString()); } }