cn.mapway.document.helper.markdown.Table Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-tools-doc Show documentation
Show all versions of api-tools-doc Show documentation
auto gen doc from api with ui
The newest version!
package cn.mapway.document.helper.markdown;
import java.util.ArrayList;
import java.util.List;
public class Table {
public Table() {
headers = new ArrayList<>();
rows = new ArrayList<>();
}
List headers;
List> rows;
public void appendHeader(String... header) {
for (int i = 0; i < header.length; i++) {
headers.add(header[i]);
}
}
public void addRow(String... text) {
ArrayList row = new ArrayList<>();
for (int i = 0; i < text.length; i++) {
row.add(text[i]);
}
rows.add(row);
}
public String toString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < headers.size(); i++) {
sb.append("|").append(headers.get(i));
}
sb.append("|\r\n");
for (int i = 0; i < headers.size(); i++) {
sb.append("|").append("---");
}
sb.append("|\r\n");
for (int i = 0; i < rows.size(); i++) {
List row = rows.get(i);
for (int j = 0; j < row.size(); j++) {
sb.append("|").append(row.get(j));
}
sb.append("|\r\n");
}
sb.append("\r\n\r\n");
return sb.toString();
}
}