use of java.util.Formatter in project h2o-3 by h2oai.
the class BufferedString method bytesToString.
public String bytesToString() {
StringBuilder sb = new StringBuilder(_len * 2);
Formatter formatter = new Formatter(sb);
boolean inHex = false;
for (int i = 0; i < _len; i++) {
if ((_buf[_off + i] & 0x80) == 128) {
if (!inHex)
sb.append("<0x");
formatter.format("%02X", _buf[_off + i]);
inHex = true;
} else {
// ASCII
if (inHex) {
sb.append(">");
inHex = false;
}
formatter.format("%c", _buf[_off + i]);
}
}
// close hex values as trailing char
if (inHex)
sb.append(">");
return sb.toString();
}
use of java.util.Formatter in project gradle by gradle.
the class UnsupportedNotationException method format.
private static String format(String failure, String resolution, Collection<String> formats) {
Formatter message = new Formatter();
message.format("%s%n", failure);
message.format("The following types/formats are supported:");
for (String format : formats) {
message.format("%n - %s", format);
}
if (GUtil.isTrue(resolution)) {
message.format("%n%n%s", resolution);
}
return message.toString();
}
use of java.util.Formatter in project buck by facebook.
the class MemberIdsSection method getTooManyMembersMessage.
private String getTooManyMembersMessage() {
Map<String, AtomicInteger> membersByPackage = new TreeMap<String, AtomicInteger>();
for (Object member : items()) {
String packageName = ((MemberIdItem) member).getDefiningClass().getPackageName();
AtomicInteger count = membersByPackage.get(packageName);
if (count == null) {
count = new AtomicInteger();
membersByPackage.put(packageName, count);
}
count.incrementAndGet();
}
Formatter formatter = new Formatter();
try {
String memberType = this instanceof MethodIdsSection ? "method" : "field";
formatter.format("Too many %s references: %d; max is %d.%n" + Main.getTooManyIdsErrorMessage() + "%n" + "References by package:", memberType, items().size(), DexFormat.MAX_MEMBER_IDX + 1);
for (Map.Entry<String, AtomicInteger> entry : membersByPackage.entrySet()) {
formatter.format("%n%6d %s", entry.getValue().get(), entry.getKey());
}
return formatter.toString();
} finally {
formatter.close();
}
}
use of java.util.Formatter in project XobotOS by xamarin.
the class Chronometer method updateText.
private synchronized void updateText(long now) {
long seconds = now - mBase;
seconds /= 1000;
String text = DateUtils.formatElapsedTime(mRecycle, seconds);
if (mFormat != null) {
Locale loc = Locale.getDefault();
if (mFormatter == null || !loc.equals(mFormatterLocale)) {
mFormatterLocale = loc;
mFormatter = new Formatter(mFormatBuilder, loc);
}
mFormatBuilder.setLength(0);
mFormatterArgs[0] = text;
try {
mFormatter.format(mFormat, mFormatterArgs);
text = mFormatBuilder.toString();
} catch (IllegalFormatException ex) {
if (!mLogged) {
Log.w(TAG, "Illegal format string: " + mFormat);
mLogged = true;
}
}
}
setText(text);
}
use of java.util.Formatter in project camel by apache.
the class MongoDbOperationsTest method testUpdate.
@Test
public void testUpdate() throws Exception {
// Prepare test
assertEquals(0, testCollection.count());
for (int i = 1; i <= 100; i++) {
String body = null;
Formatter f = new Formatter();
if (i % 2 == 0) {
body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\"}", i).toString();
} else {
body = f.format("{\"_id\":\"testSave%d\", \"scientist\":\"Einstein\", \"extraField\": true}", i).toString();
}
f.close();
template.requestBody("direct:insert", body);
}
assertEquals(100L, testCollection.count());
// Testing the update logic
BasicDBObject extraField = new BasicDBObject("extraField", true);
assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0, testCollection.count(new BasicDBObject("scientist", "Darwin")));
DBObject updateObj = new BasicDBObject("$set", new BasicDBObject("scientist", "Darwin"));
Exchange resultExchange = template.request("direct:update", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(new Object[] { extraField, updateObj });
exchange.getIn().setHeader(MongoDbConstants.MULTIUPDATE, true);
}
});
Object result = resultExchange.getOut().getBody();
assertTrue(result instanceof UpdateResult);
assertEquals("Number of records updated header should equal 50", 50L, resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50, testCollection.count(new BasicDBObject("scientist", "Darwin")));
}
Aggregations