Search in sources :

Example 41 with Formatter

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();
}
Also used : Formatter(java.util.Formatter)

Example 42 with Formatter

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();
}
Also used : Formatter(java.util.Formatter)

Example 43 with Formatter

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();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Formatter(java.util.Formatter) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 44 with Formatter

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);
}
Also used : Locale(java.util.Locale) Formatter(java.util.Formatter) IllegalFormatException(java.util.IllegalFormatException)

Example 45 with Formatter

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")));
}
Also used : Exchange(org.apache.camel.Exchange) BasicDBObject(com.mongodb.BasicDBObject) Processor(org.apache.camel.Processor) Formatter(java.util.Formatter) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) UpdateResult(com.mongodb.client.result.UpdateResult) Test(org.junit.Test)

Aggregations

Formatter (java.util.Formatter)335 File (java.io.File)20 AlertDialog (android.app.AlertDialog)14 DialogInterface (android.content.DialogInterface)14 Justif (aQute.lib.justif.Justif)12 Map (java.util.Map)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 Test (org.junit.Test)10 BigInteger (java.math.BigInteger)9 Locale (java.util.Locale)9 UnknownFormatConversionException (java.util.UnknownFormatConversionException)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 BigDecimal (java.math.BigDecimal)7 IllegalFormatException (java.util.IllegalFormatException)7 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)7 LayoutBuilder (android.text.StaticLayoutTest.LayoutBuilder)6 FileOutputStream (java.io.FileOutputStream)6 FormatFlagsConversionMismatchException (java.util.FormatFlagsConversionMismatchException)6