use of java.util.Formatter in project j2objc by google.
the class FormatterTest method test_ConstructorLjava_util_Locale.
/**
* java.util.Formatter#Formatter(Locale)
*/
public void test_ConstructorLjava_util_Locale() {
Formatter f1 = new Formatter(Locale.FRANCE);
assertTrue(f1.out() instanceof StringBuilder);
assertEquals(f1.locale(), Locale.FRANCE);
assertNotNull(f1.toString());
Formatter f2 = new Formatter((Locale) null);
assertNull(f2.locale());
assertTrue(f2.out() instanceof StringBuilder);
assertNotNull(f2.toString());
}
use of java.util.Formatter in project guice by google.
the class Errors method childBindingAlreadySet.
public Errors childBindingAlreadySet(Key<?> key, Set<Object> sources) {
Formatter allSources = new Formatter();
for (Object source : sources) {
if (source == null) {
allSources.format("%n (bound by a just-in-time binding)");
} else {
allSources.format("%n bound at %s", source);
}
}
Errors errors = addMessage("Unable to create binding for %s." + " It was already configured on one or more child injectors or private modules" + "%s%n" + " If it was in a PrivateModule, did you forget to expose the binding?", key, allSources.out());
return errors;
}
use of java.util.Formatter in project guice by google.
the class Errors method format.
/** Returns the formatted message for an exception with the specified messages. */
public static String format(String heading, Collection<Message> errorMessages) {
Formatter fmt = new Formatter().format(heading).format(":%n%n");
int index = 1;
boolean displayCauses = getOnlyCause(errorMessages) == null;
Map<Equivalence.Wrapper<Throwable>, Integer> causes = Maps.newHashMap();
for (Message errorMessage : errorMessages) {
int thisIdx = index++;
fmt.format("%s) %s%n", thisIdx, errorMessage.getMessage());
List<Object> dependencies = errorMessage.getSources();
for (int i = dependencies.size() - 1; i >= 0; i--) {
Object source = dependencies.get(i);
formatSource(fmt, source);
}
Throwable cause = errorMessage.getCause();
if (displayCauses && cause != null) {
Equivalence.Wrapper<Throwable> causeEquivalence = ThrowableEquivalence.INSTANCE.wrap(cause);
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");
}
if (errorMessages.size() == 1) {
fmt.format("1 error");
} else {
fmt.format("%s errors", errorMessages.size());
}
return fmt.toString();
}
use of java.util.Formatter in project CoreNLP by stanfordnlp.
the class BuildLexicalizedParserITest method buildAndTest.
public static void buildAndTest(ParserTestCase test) throws IOException {
PrintStream originalOut = System.out;
PrintStream originalErr = System.err;
System.out.println("Training:");
System.out.println(StringUtils.join(test.trainCommandLine));
ByteArrayOutputStream savedOutput = new ByteArrayOutputStream();
TeeStream teeOut = new TeeStream(savedOutput, System.out);
PrintStream teeOutPS = new PrintStream(teeOut);
TeeStream teeErr = new TeeStream(savedOutput, System.err);
PrintStream teeErrPS = new PrintStream(teeErr);
System.setOut(teeOutPS);
System.setErr(teeErrPS);
LexicalizedParser.main(test.trainCommandLine);
teeOutPS.flush();
teeErrPS.flush();
teeOut.flush();
teeErr.flush();
String[] outputLines = savedOutput.toString().split("(?:\\n|\\r)+");
String perfLine = outputLines[outputLines.length - 5];
System.out.println(perfLine);
assertEquals("factor LP/LR summary evalb: LP: 100.0 LR: 100.0 F1: 100.0 Exact: 100.0 N: 1", perfLine.trim());
Formatter commandLineFormatter = new Formatter();
commandLineFormatter.format(baseTestSerCommandLine, test.parserFile.getPath(), test.testPath);
String[] testCommandLine = commandLineFormatter.toString().split("\\s");
System.out.println("Testing:");
System.out.println(StringUtils.join(testCommandLine));
LexicalizedParser.main(testCommandLine);
commandLineFormatter = new Formatter();
commandLineFormatter.format(baseTestTextCommandLine, test.textFile.getPath(), test.testPath);
testCommandLine = commandLineFormatter.toString().split("\\s");
System.out.println("Testing:");
System.out.println(StringUtils.join(testCommandLine));
LexicalizedParser.main(testCommandLine);
teeOutPS.flush();
teeErrPS.flush();
teeOut.flush();
teeErr.flush();
System.setOut(originalOut);
System.setErr(originalErr);
}
use of java.util.Formatter in project camel by apache.
the class AbstractMongoDbTest method pumpDataIntoTestCollection.
protected void pumpDataIntoTestCollection() {
// there should be 100 of each
String[] scientists = { "Einstein", "Darwin", "Copernicus", "Pasteur", "Curie", "Faraday", "Newton", "Bohr", "Galilei", "Maxwell" };
for (int i = 1; i <= 1000; i++) {
int index = i % scientists.length;
Formatter f = new Formatter();
String doc = f.format("{\"_id\":\"%d\", \"scientist\":\"%s\", \"fixedField\": \"fixedValue\"}", i, scientists[index]).toString();
IOHelper.close(f);
testCollection.insertOne(Document.parse(doc));
}
assertEquals("Data pumping of 1000 entries did not complete entirely", 1000L, testCollection.count());
}
Aggregations