MCPcopy Index your code
hub / github.com/0linlin0/CyberBox / formatTable

Method formatTable

Skay_Exp/src/tools/Strings.java:29–49  ·  view source on GitHub ↗
(List<String[]> rows)

Source from the content-addressed store, hash-verified

27 }
28
29 public static List<String> formatTable(List<String[]> rows) {
30 final Integer[] maxLengths = new Integer[rows.get(0).length];
31 for (String[] row : rows) {
32 if (maxLengths.length != row.length) throw new IllegalStateException("mismatched columns");
33 for (int i = 0; i < maxLengths.length; i++) {
34 if (maxLengths[i] == null || maxLengths[i] < row[i].length()) {
35 maxLengths[i] = row[i].length();
36 }
37 }
38 }
39
40 final List<String> lines = new LinkedList<String>();
41 for (String[] row : rows) {
42 for (int i = 0; i < maxLengths.length; i++) {
43 final String pad = repeat(" ", maxLengths[i] - row[i].length());
44 row[i] = row[i] + pad;
45 }
46 lines.add(join(Arrays.asList(row), " ", "", ""));
47 }
48 return lines;
49 }
50
51 public static class ToStringComparator implements Comparator<Object> {
52 public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); }

Callers

nothing calls this directly

Calls 3

repeatMethod · 0.95
joinMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected