int (StringBuilder buffer, int currentLevel, Object node, AbstractTreeStructure structure, @Nullable Comparator<?> comparator, int maxRowCount, int currentLine, char paddingChar, Function<Object, String> nodePresenter) { if (currentLine >= maxRowCount && maxRowCount != -1) return currentLine; StringUtil.repeatSymbol(buffer, paddingChar, currentLevel); buffer.append(nodePresenter.apply(node)).append("\n"); currentLine++; Object[] children = structure.getChildElements(node); if (comparator != null) { List<?> list = new ArrayList<>(Arrays.asList(children)); @SuppressWarnings("unchecked") Comparator<Object> c = (Comparator<Object>)comparator; list.sort(c); children = ArrayUtil.toObjectArray(list); } for (Object child : children) { currentLine = doPrint(buffer, currentLevel + 1, child, structure, comparator, maxRowCount, currentLine, paddingChar, nodePresenter); } return currentLine; }