Add formatted table to string builder @param sb string builder to append to
(StringBuilder sb)
| 216 | * @param sb string builder to append to |
| 217 | */ |
| 218 | public void toString(StringBuilder sb) { |
| 219 | final int rows = mTableContents.size(); |
| 220 | if (rows > 0) { |
| 221 | final int columns = mTableContents.get(0).size(); |
| 222 | if (columns > 0) { |
| 223 | final int[] maxLengths = mColumnWidths; |
| 224 | final long totalWidth = getTotalWidth(); |
| 225 | for (final ArrayList<String> row : mTableContents) { |
| 226 | if (row == SEPARATOR) { |
| 227 | for (long j = 0; j < totalWidth; ++j) { |
| 228 | sb.append('-'); |
| 229 | } |
| 230 | } else { |
| 231 | for (int j = 0; j < columns; ++j) { |
| 232 | if (j == 0) { |
| 233 | appendSpaces(sb, mInitialIndent); |
| 234 | } else { |
| 235 | appendSpaces(sb, mTabWidth); |
| 236 | } |
| 237 | final Align align = j < mAlignment.length ? mAlignment[j] : mDefaultAlignment; |
| 238 | align.appendCell(sb, maxLengths[j], row.get(j)); |
| 239 | } |
| 240 | } |
| 241 | sb.append(StringUtils.LS); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Output the table as basic tab separated |