if (colLabels != null) { buff.append(makeAsciiTableCell("", padLeft, padRight, tsv)); // the top left cell for (int j = 0; j < table[0].length; j++) { // assume table is a rectangular matrix buff.append(makeAsciiTableCell(colLabels[j], padLeft, padRight, (j != table[0].length - 1) && tsv)); buff.append(makeAsciiTableCell(rowLabels[i], padLeft, padRight, tsv)); buff.append(makeAsciiTableCell(table[i][j], padLeft, padRight, (j != table[0].length - 1) && tsv));
/** * Returns an text table containing the matrix of Strings passed in. * The first dimension of the matrix should represent the rows, and the * second dimension the columns. */ public static String makeAsciiTable(Object[][] table, Object[] rowLabels, Object[] colLabels, int padLeft, int padRight, boolean tsv) { StringBuilder buff = new StringBuilder(); // top row buff.append(makeAsciiTableCell("", padLeft, padRight, tsv)); // the top left cell for (int j = 0; j < table[0].length; j++) { // assume table is a rectangular matrix buff.append(makeAsciiTableCell(colLabels[j], padLeft, padRight, (j != table[0].length - 1) && tsv)); } buff.append('\n'); // all other rows for (int i = 0; i < table.length; i++) { // one row buff.append(makeAsciiTableCell(rowLabels[i], padLeft, padRight, tsv)); for (int j = 0; j < table[i].length; j++) { buff.append(makeAsciiTableCell(table[i][j], padLeft, padRight, (j != table[0].length - 1) && tsv)); } buff.append('\n'); } return buff.toString(); }
/** * Returns a text table containing the matrix of objects passed in. * The first dimension of the matrix should represent the rows, and the * second dimension the columns. Each object is printed in a cell with toString(). * The printing may be padded with spaces on the left and then on the right to * ensure that the String form is of length at least padLeft or padRight. * If tsv is true, a tab is put between columns. * * @return A String form of the table */ public static String makeTextTable(Object[][] table, Object[] rowLabels, Object[] colLabels, int padLeft, int padRight, boolean tsv) { StringBuilder buff = new StringBuilder(); // top row buff.append(makeAsciiTableCell("", padLeft, padRight, tsv)); // the top left cell for (int j = 0; j < table[0].length; j++) { // assume table is a rectangular matrix buff.append(makeAsciiTableCell(colLabels[j], padLeft, padRight, (j != table[0].length - 1) && tsv)); } buff.append('\n'); // all other rows for (int i = 0; i < table.length; i++) { // one row buff.append(makeAsciiTableCell(rowLabels[i], padLeft, padRight, tsv)); for (int j = 0; j < table[i].length; j++) { buff.append(makeAsciiTableCell(table[i][j], padLeft, padRight, (j != table[0].length - 1) && tsv)); } buff.append('\n'); } return buff.toString(); }
if (colLabels != null) { buff.append(makeAsciiTableCell("", padLeft, padRight, tsv)); // the top left cell for (int j = 0; j < table[0].length; j++) { // assume table is a rectangular matrix buff.append(makeAsciiTableCell(colLabels[j], padLeft, padRight, (j != table[0].length - 1) && tsv)); buff.append(makeAsciiTableCell(rowLabels[i], padLeft, padRight, tsv)); buff.append(makeAsciiTableCell(table[i][j], padLeft, padRight, (j != table[0].length - 1) && tsv));
if (colLabels != null) { buff.append(makeAsciiTableCell("", padLeft, padRight, tsv)); // the top left cell for (int j = 0; j < table[0].length; j++) { // assume table is a rectangular matrix buff.append(makeAsciiTableCell(colLabels[j], padLeft, padRight, (j != table[0].length - 1) && tsv)); buff.append(makeAsciiTableCell(rowLabels[i], padLeft, padRight, tsv)); buff.append(makeAsciiTableCell(table[i][j], padLeft, padRight, (j != table[0].length - 1) && tsv));