/** * Print a nicely formatted representation of this object. Currently prints a nicely formatted ACSII table. * * @return a string containing a multi-line description of this object */ public String toPrettyPrintedString() { return PrettyPrinter.toPrettyPrintedString(this); } }
/** * Pretty print a TabularResult in a text-based table format. * * @param result a TabularResult, not null * @return a String containing the table to be printed, not null. */ public static String toPrettyPrintedString(final TabularResult result) { ArgumentChecker.notNull(result, "result"); StringBuilder sb = new StringBuilder(); int[] maxWidths = maximumWidths(result); separator(sb, maxWidths); header(sb, maxWidths, result.getHeaderDefinition()); separator(sb, maxWidths); for (final Row row : result) { row(sb, maxWidths, row); } separator(sb, maxWidths); return sb.toString(); }
private static void separator(final StringBuilder sb, final int[] maxWidths) { for (int width : maxWidths) { sb.append("+"); sb.append(repeat(width + 2, '-')); } sb.append("+"); sb.append("\n"); }
/** * Print a nicely formatted representation of this object. Currently prints a nicely formatted JSON representation. * * @return a string containing a multi-line description of this object */ public String toPrettyPrintedString() { return PrettyPrinter.toPrettyPrintedString(this); }
private static void header(final StringBuilder sb, final int[] maxWidths, final HeaderDefinition headerDefinition) { Iterator<String> iterator = headerDefinition.iterator(); for (int width : maxWidths) { String value = iterator.next(); sb.append("| "); if (value != null) { sb.append(value); sb.append(repeat(width - value.length(), ' ')); } else { sb.append(NULL); sb.append(repeat(width - NULL_SIZE, ' ')); } sb.append(" "); } sb.append("|"); sb.append("\n"); }
/** * Print a nicely formatted representation of this object. Currently prints a nicely formatted JSON representation. * * @return a string containing a multi-line description of this object */ public String toPrettyPrintedString() { return PrettyPrinter.toPrettyPrintedString(this); }
private static void row(final StringBuilder sb, final int[] maxWidths, final Row row) { int i = 0; for (int width : maxWidths) { String value = row.getString(i++); sb.append("| "); if (value != null) { sb.append(value); sb.append(repeat(width - value.length(), ' ')); } else { sb.append(NULL); sb.append(repeat(width - NULL_SIZE, ' ')); } sb.append(" "); } sb.append("|"); sb.append("\n"); }
/** * Pretty print a MetaDataResult as an indented piece of JSON code. Throws a QuandlRuntimeException if it can't render the nested * JSONObject to a String. * * @param metaDataResult the metaDataResult, not null * @return a String representation of the object, probably multi-line. */ public static String toPrettyPrintedString(final MetaDataResult metaDataResult) { return toPrettyPrintedString(metaDataResult.getRawJSON()); }
HeaderDefinition headerDefinition = entry.getValue(); sb.append(quandlCode); sb.append(repeat(max - quandlCode.length(), ' ')); // indent sb.append(" => "); Iterator<String> iterator = headerDefinition.iterator();
/** * Pretty print a SearchResult as an indented piece of JSON code. Throws a QuandlRuntimeException if it can't render the nested JSONObject * to a String. * * @param searchResult the searchResult, not null * @return a String representation of the object, probably multi-line. */ public static String toPrettyPrintedString(final SearchResult searchResult) { return toPrettyPrintedString(searchResult.getRawJSON()); }
/** * Load file using internal counter to generate file name and compare contents to the result provided. * @param tabularResult the result to check file contents against */ public final void processResult(final TabularResult tabularResult) { File file = new File(_baseDir, TABULAR + _fileNumber.getAndIncrement() + TXT); if (file.exists()) { Assert.assertEquals(PrettyPrinter.toPrettyPrintedString(tabularResult), readFile(file)); } else { Assert.fail("File " + file + " does not exist"); } }
/** * Save a JSONObject into a file in pretty printed format. * @param jsonObject the JSON object to save */ private void processResult(final JSONObject jsonObject) { File file = new File(_baseDir, METADATA + _fileNumber.getAndIncrement() + JSON); // subtlety alert! The JSON object pretty printer adds a line separator at the end of the string to match the tabular result pretty printer. // This means when these are read back from a file, every line is terminated with a line separator. writeFile(file, PrettyPrinter.toPrettyPrintedString(jsonObject)); }
/** * Save a JSONObject into a file in pretty printed format. * @param jsonObject the JSON object to save */ private void processResult(final JSONObject jsonObject) { File file = new File(_baseDir, METADATA + _fileNumber.getAndIncrement() + JSON); // subtlety alert! The JSON object pretty printer adds a line separator at the end of the string to match the tabular result pretty printer. // This means when these are read back from a file, every line is terminated with a line separator. writeFile(file, PrettyPrinter.toPrettyPrintedString(jsonObject)); }
/** * Load file using internal counter to generate file name and compare contents to the result provided. * @param tabularResult the result to check file contents against */ public final void processResult(final TabularResult tabularResult) { File file = new File(_baseDir, TABULAR + _fileNumber.getAndIncrement() + TXT); if (file.exists()) { Assert.assertEquals(PrettyPrinter.toPrettyPrintedString(tabularResult), readFile(file)); } else { Assert.fail("File " + file + " does not exist"); } }
/** * Save a map of String to HeaderDefinition. * @param multiHeaderDefinitionResult a map of String to HeaderDefinition, not null */ public final void processResult(final Map<String, HeaderDefinition> multiHeaderDefinitionResult) { ArgumentChecker.notNull(multiHeaderDefinitionResult, "multiHeaderDefinitionResult"); File file = new File(_baseDir, METADATA + _fileNumber.getAndIncrement() + TXT); writeFile(file, PrettyPrinter.toPrettyPrintedString(multiHeaderDefinitionResult)); }
/** * Save a TabularResult into a file in pretty printed format. * @param tabularResult the tabular result to save */ public final void processResult(final TabularResult tabularResult) { ArgumentChecker.notNull(tabularResult, "tabularResult"); File file = new File(_baseDir, TABULAR + _fileNumber.getAndIncrement() + TXT); writeFile(file, PrettyPrinter.toPrettyPrintedString(tabularResult)); } /**
/** * Save a map of String to HeaderDefinition. * @param multiHeaderDefinitionResult a map of String to HeaderDefinition, not null */ public final void processResult(final Map<String, HeaderDefinition> multiHeaderDefinitionResult) { ArgumentChecker.notNull(multiHeaderDefinitionResult, "multiHeaderDefinitionResult"); File file = new File(_baseDir, METADATA + _fileNumber.getAndIncrement() + TXT); writeFile(file, PrettyPrinter.toPrettyPrintedString(multiHeaderDefinitionResult)); }
/** * Save a TabularResult into a file in pretty printed format. * @param tabularResult the tabular result to save */ public final void processResult(final TabularResult tabularResult) { ArgumentChecker.notNull(tabularResult, "tabularResult"); File file = new File(_baseDir, TABULAR + _fileNumber.getAndIncrement() + TXT); writeFile(file, PrettyPrinter.toPrettyPrintedString(tabularResult)); } /**
private void processResult(final JSONObject jsonObject) { File file = new File(_baseDir, METADATA + _fileNumber.getAndIncrement() + JSON); if (file.exists()) { String value = PrettyPrinter.toPrettyPrintedString(jsonObject); String expected = readFile(file); outputDiff(value, expected); try { Assert.assertEquals(value, expected); } catch (AssertionError ae) { s_logger.error("Value exected was \n{}\n rather than \n{}\n as expected", value, expected); } } else { Assert.fail("File " + file + " does not exist"); } }
private void processResult(final JSONObject jsonObject) { File file = new File(_baseDir, METADATA + _fileNumber.getAndIncrement() + JSON); if (file.exists()) { String value = PrettyPrinter.toPrettyPrintedString(jsonObject); String expected = readFile(file); outputDiff(value, expected); try { Assert.assertEquals(value, expected); } catch (AssertionError ae) { s_logger.error("Value exected was \n{}\n rather than \n{}\n as expected", value, expected); } } else { Assert.fail("File " + file + " does not exist"); } }