in apache-rat-tools/src/main/java/org/apache/rat/tools/Naming.java [228:289]
private static void printText(final List<String> columns, final Predicate<Option> filter, final boolean addCLI,
final boolean showMaven, final boolean showAnt,
final Function<Option, String> descriptionFunction, final Writer underWriter, final int width) throws IOException {
List<List<String>> page = new ArrayList<>();
int columnCount = columns.size();
page.add(columns);
for (Option option : OptionCollection.buildOptions().getOptions()) {
if (filter.test(option)) {
page.add(fillColumns(new ArrayList<>(), option, addCLI, showMaven, showAnt, descriptionFunction));
}
}
int[] columnWidth = calculateColumnWidth(width, columnCount, page);
HelpFormatter helpFormatter;
helpFormatter = new HelpFormatter.Builder().get();
helpFormatter.setWidth(width);
List<Deque<String>> entries = new ArrayList<>();
CharArrayWriter cWriter = new CharArrayWriter();
// process one line at a time
for (List<String> cols : page) {
entries.clear();
PrintWriter writer = new PrintWriter(cWriter);
// print each column into a block of strings.
for (int i = 0; i < columnCount; i++) {
String col = cols.get(i);
// split on end of line within a column
for (String line : col.split("\\v")) {
helpFormatter.printWrapped(writer, columnWidth[i], 2, line);
}
writer.flush();
// please the block of strings into a queue.
Deque<String> entryLines = new LinkedList<>(Arrays.asList(cWriter.toString().split("\\v")));
// put the queue into the entries for this line.
entries.add(entryLines);
cWriter.reset();
}
// print the entries by printing the items from the queues until all queues are empty.
boolean cont = true;
while (cont) {
cont = false;
for (int columnNumber = 0; columnNumber < entries.size(); columnNumber++) {
Deque<String> queue = entries.get(columnNumber);
if (queue.isEmpty()) {
underWriter.append(AbstractHelp.createPadding(columnWidth[columnNumber] + 2));
} else {
String ln = queue.pop();
underWriter.append(ln);
underWriter.append(AbstractHelp.createPadding(columnWidth[columnNumber] - ln.length() + 2));
if (!queue.isEmpty()) {
cont = true;
}
}
}
underWriter.append(System.lineSeparator());
}
underWriter.append(System.lineSeparator());
}
}