/** * Generating header for a given table. * * @param table * the table where the header should fit to * @return another {@link NiceTable} instance */ private NiceTable generateHeader(final NiceTable table) { table.addHeader("Benchmark"); table.addRow(new String[] { "-", "unit", "sum", "min", "max", "avg", "stddev", "conf95", "runs" }); return table; }
/** * Adds a string row. checks that the strings added do not contain newlines, * because if so, it has to split them in order to make them fit the row. * * @param data * the array of data. */ public void addRow(final String[] data) { if (anyStringContainsNewLine(data)) { final String[][] theMatrix = Util.createMatrix(data); for (int i = 0; i < theMatrix.length; i++) { addRow(theMatrix[i]); } } else { final Row myRow = new Row(this, data); rows.add(myRow); } }
/** * Returns the row's total width. * * @return the width of the row. */ public int getRowWidth() { int overallWidth = 0; for (int i = 0; i < data.length; i++) { overallWidth += getTable().getColumnWidth(i); } return overallWidth; }
/** * Returns the total width of the table. * * @return int the width of the table */ protected int getTotalWidth() { return this.getRowWidth() + 3 * numColumns() + 1; }
/** * Test method for {@link org.perfidix.ouput.asciitable.NiceTable#toString()}. */ @Test public void testToString() { table.addHeader("This is a header"); table.addRow(new String[] { "This", "is", "one", "data" }); table.addLine('-'); table.addRow(new String[] { "This", "is", "another", "data" }); assertEquals( "Test for a complete table", "|= This is a header ===========================|\n| This | is | one | data |\n|----------------------------------------------|\n| This | is | another | data |\n", table.toString()); }
public void visitBenchmark(final BenchmarkResult benchRes) { final int numberOfColumns = 9; NiceTable table = new NiceTable(numberOfColumns); table = generateHeader(table); for (final AbstractMeter meter : benchRes.getRegisteredMeters()) { table.addHeader(meter.getName(), '=', Alignment.Center); for (final ClassResult classRes : benchRes.getIncludedResults()) { table.addHeader(classRes.getElementName(), '.', Alignment.Left); for (final MethodResult methRes : classRes.getIncludedResults()) { table = generateMeterResult(methRes.getElementName(), meter, methRes, table); table.addHeader(new StringBuilder("Summary for ").append(classRes.getElementName()) .toString(), '_', Alignment.Left); table = generateMeterResult("", meter, classRes, table); table.addLine('-'); table.addHeader("Summary for the whole benchmark", '=', Alignment.Center); table.addHeader("Exceptions", '=', Alignment.Center); for (final AbstractPerfidixMethodException exec : benchRes.getExceptions()) { final StringBuilder execBuilder0 = new StringBuilder(); execBuilder0.append("Related exception: ").append(exec.getExec().getClass().getSimpleName()); table.addHeader(execBuilder0.toString(), ' ', Alignment.Left); table.addHeader(execBuilder1.toString(), ' ', Alignment.Left); if (exec.getMethod() != null) { final StringBuilder execBuilder2 = new StringBuilder(); execBuilder2.append("Related method: ").append(exec.getMethod().getName()); table.addHeader(execBuilder2.toString(), ' ', Alignment.Left);
}; final NiceTable zero = new NiceTable(string.length); zero.addLine('-'); zero.addRow(string); zero.addLine('='); zero.addRow(new String[] { numbers[0].toString(), numbers[1].toString(), numbers[2].toString(), numbers[3].toString(), numbers[4].toString() }); zero.addLine('-'); final String result = zero.toString(); final StringBuilder expected = new StringBuilder(); expected.append("|------------------------------------|\n");
/** * Recursive usage of multiple tables */ @Test public void testNestedTable() { final NiceTable zero = new NiceTable(3); final NiceTable one = new NiceTable(2); final NiceTable two = new NiceTable(2); final NiceTable three = new NiceTable(2); one.addRow(new String[] { "a", "b" }); two.addRow(new String[] { "c", "d" }); three.addRow(new String[] { "e", "f" }); zero.addRow(new String[] { one.toString(), two.toString(), three.toString() }); final String result = zero.toString().trim(); assertEquals("Test for encapsulated tables", "| | a | b | | | c | d | | | e | f | |", result); }
/** * Adds a header. * * @param title * the text to display within the header */ public void addHeader(final String title) { addHeader(title, '=', Alignment.Left); }
/** * {@inheritDoc} */ @Override public String draw() { final String[] row = new String[data.length]; for (int i = 0; i < data.length; i++) { row[i] = Util.pad(data[i], ' ', getTable().getColumnWidth(i), getTable().getOrientation(i)); } return Util.combine(new String(new char[] { AbstractTabularComponent.BORDER }), SPACE, Util.implode(Util.combine(SPACE, new String(new char[] { AbstractTabularComponent.BORDER }), SPACE), row), SPACE, new String(new char[] { AbstractTabularComponent.BORDER }), NEWLINE); }
/** * Simple setUp. */ @Before public void setUp() { table = new NiceTable(COLUMNNUMBER); }
/** * Test method for {@link org.perfidix.ouput.asciitable.NiceTable#NiceTable(int)}. */ @Test public void testCreate() { assertEquals("Test for create", "", table.toString()); }
/** * Generating the results for a given table. * * @param columnDesc * the description for the row * @param meter * the corresponding {@link AbstractMeter} instance * @param result * the corresponding {@link AbstractResult} instance * @param input * the {@link NiceTable} to be print to * @return the modified {@link NiceTable} instance */ private NiceTable generateMeterResult(final String columnDesc, final AbstractMeter meter, final AbstractResult result, final NiceTable input) { input.addRow(new String[] { columnDesc, meter.getUnit(), AbstractOutput.format(result.sum(meter)), AbstractOutput.format(result.min(meter)), AbstractOutput.format(result.max(meter)), AbstractOutput.format(result.mean(meter)), AbstractOutput.format(result.getStandardDeviation(meter)), new StringBuilder("[").append(AbstractOutput.format(result.getConf05(meter))).append("-").append( AbstractOutput.format(result.getConf95(meter))).append("]").toString(), AbstractOutput.format(result.getResultSet(meter).size()) }); return input; }
/** * {@inheritDoc} */ @Override public String draw() { return Util.combine(new String(new char[] { AbstractTabularComponent.BORDER }), Util.repeat(new String(new char[] { content }), getTable().getTotalWidth() - 2), new String(new char[] { AbstractTabularComponent.BORDER }), NEWLINE); }
/** * Alignement test if some rows are incomplete */ @Test public void testRowAlignment() { final NiceTable zero = new NiceTable(2); zero.addRow(new String[] { "a\nb\nc", "a\nb" }); zero.addRow(new String[] { "d", "d" }); final String expected = "| a | a |\n" + "| b | b |\n" + "| c | |\n" + "| d | d |\n"; assertEquals("Test for row alignment", expected, zero.toString()); }
/** * Test method for * {@link org.perfidix.ouput.asciitable.NiceTable#addHeader(String, char, org.perfidix.ouput.asciitable.AbstractTabularComponent.Alignment)} */ @Test public void testAddHeaderStringCharAlignment() { table.addHeader(TESTSTRING, '-', Alignment.Left); assertEquals("Test for left alignement adding", "|- This is a test -------------|\n", table .toString()); setUp(); table.addHeader(TESTSTRING, '/', Alignment.Center); assertEquals("Test for center alignment", "|/////// This is a test ///////|\n", table.toString()); setUp(); table.addHeader(TESTSTRING, '\\', Alignment.Right); assertEquals("Test for right alignment", "|\\\\\\\\\\\\\\\\\\\\\\\\\\ This is a test \\|\n", table .toString()); }
/** * {@inheritDoc} */ @Override public String draw() { return Util.combine(new String(new char[] { AbstractTabularComponent.BORDER }), Util.pad(title, enclosing, getTable().getTotalWidth() - 2, orientation), new String(new char[] { AbstractTabularComponent.BORDER }), NEWLINE); }