MCPcopy Create free account
hub / github.com/RealTimeGenomics/rtg-tools / addRow

Method addRow

src/main/java/com/rtg/util/RstTable.java:104–128  ·  view source on GitHub ↗

Add a row to the table @param text each value for corresponding column in this row

(String... text)

Source from the content-addressed store, hash-verified

102 * @param text each value for corresponding column in this row
103 */
104 public void addRow(String... text) {
105 if (text.length != mWidths.length) {
106 throw new IllegalArgumentException("Expected " + mWidths.length + " columns, got " + text.length);
107 }
108 final String[][] cols = new String[text.length][];
109 int rows = 0;
110 for (int col = 0; col < text.length; ++col) {
111 cols[col] = splitToWidthWithWrap(mWidths[col], text[col]);
112 rows = Math.max(rows, cols[col].length);
113 }
114 for (int row = 0; row < rows; row++) {
115 for (int col = 0; col < cols.length; ++col) {
116 final String s = (row < cols[col].length) ? cols[col][row] : "";
117 if (s.length() > mWidths[col]) {
118 System.err.println("Arrays.toString(mWidths) = " + Arrays.toString(mWidths));
119 System.err.println("Arrays.toString(text) = " + Arrays.toString(text));
120 throw new IllegalArgumentException("text too wide, expected: " + mWidths[col] + " got: " + s.length() + " " + s);
121 }
122 final String formatString = "|" + widthString(mSpacing) + widthString(mWidths[col]) + widthString(mSpacing);
123 mTable.append(String.format(formatString, "", s, ""));
124 }
125 mTable.append("|").append(StringUtils.LS);
126 }
127 addSeparator();
128 }
129
130 private static String[] splitToWidthWithWrap(int width, String text) {
131 final WrappingStringBuilder sb = new WrappingStringBuilder();

Callers 3

testMethod · 0.95
appendTableFlagUsageMethod · 0.95
addSummaryRowMethod · 0.45

Calls 9

splitToWidthWithWrapMethod · 0.95
widthStringMethod · 0.95
addSeparatorMethod · 0.95
printlnMethod · 0.80
lengthMethod · 0.65
toStringMethod · 0.65
appendMethod · 0.65
maxMethod · 0.45
formatMethod · 0.45

Tested by 1

testMethod · 0.76