1 | package ai.d.ai18;
|
2 |
|
3 | import drjava.util.Lizt;
|
4 | import drjava.util.StringUtil;
|
5 | import net.luaos.tb.tb15.CentralDatabase;
|
6 | import net.luaos.tb.tb20.DatabaseAPI;
|
7 | import net.luaos.tb.tb20.ListEntry;
|
8 |
|
9 | import java.util.List;
|
10 | import java.util.Map;
|
11 | import java.util.TreeMap;
|
12 |
|
13 | public class GetDiskStats {
|
14 | public static void main(String[] args) {
|
15 | DatabaseAPI db = CentralDatabase.copyToMemory("df", "GetDiskStats");
|
16 | String dfOutputID = "#t1-kokjwjhpwuas-qbtsjoyahagl";
|
17 | doIt(db, dfOutputID);
|
18 | }
|
19 |
|
20 | public static void doIt(DatabaseAPI db, String dfOutputID) {
|
21 | ListEntry dfOutput = db.get(dfOutputID);
|
22 | String text = dfOutput.desc;
|
23 | System.out.println(text);
|
24 | List<String> lines = StringUtil.toLines(text);
|
25 | System.out.println(StringUtil.n(lines.size(), "line"));
|
26 |
|
27 | ListEntry rowMarking = db.oneOfType_flex("RowMarking"); // TODO: check link to DFOutput
|
28 | System.out.println("RowMarking: " + rowMarking);
|
29 |
|
30 | List<ListEntry> colMarkings = db.allOfType("ColMarking"); // TODO: check link to DFOutput
|
31 | System.out.println("ColMarkings: " + colMarkings);
|
32 |
|
33 | Map<String, String> map = new TreeMap<String, String>(); // Yes - we like it sorted
|
34 |
|
35 | for (ListEntry colMarking : colMarkings) {
|
36 | int textRow = rowMarking.getInt("textRow");
|
37 | String line = lines.get(textRow-1);
|
38 | String textCol = colMarking.getString("textCol");
|
39 | String[] fromTo = textCol.split("\\-");
|
40 | int col1 = Integer.parseInt(fromTo[0]), col2;
|
41 | if (fromTo[1].equals("end"))
|
42 | col2 = line.length();
|
43 | else if (fromTo[1].endsWith(" (inc)"))
|
44 | col2 = Integer.parseInt(fromTo[1].substring(0, fromTo[1].length()-" (inc)".length()));
|
45 | else
|
46 | throw new RuntimeException("Ambiguous column range: " + textCol);
|
47 | String value = line.substring(col1-1, col2);
|
48 | System.out.println("Value: |" + value + "|");
|
49 | map.put(colMarking.desc, value);
|
50 | }
|
51 |
|
52 | System.out.println("Values: " + map);
|
53 | }
|
54 | }
|