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 | } |
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
| ID | Author/Program | Comment | Date | |
|---|---|---|---|---|
| 556 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { package ai.d.ai18; import drjava.util.Lizt; import drjava.util.StringUtil; import net.luaos.tb.tb15.CentralDatabase; import net.luaos.tb.tb20.DatabaseAPI; import net.luaos.tb.tb20.ListEntry; import java.util.List; import java.util.Map; import java.util.TreeMap; public class GetDiskStats { public static void main(String[] args) { DatabaseAPI db = CentralDatabase.copyToMemory("df", "GetDiskStats"); String dfOutputID = "#t1-kokjwjhpwuas-qbtsjoyahagl"; doIt(db, dfOutputID); } public static void doIt(DatabaseAPI db, String dfOutputID) { ListEntry dfOutput = db.get(dfOutputID); String text = dfOutput.desc; System.out.println(text); List<String> lines = StringUtil.toLines(text); System.out.println(StringUtil.n(lines.size(), "line")); ListEntry rowMarking = db.oneOfType_flex("RowMarking"); // TODO: check link to DFOutput System.out.println("RowMarking: " + rowMarking); List<ListEntry> colMarkings = db.allOfType("ColMarking"); // TODO: check link to DFOutput System.out.println("ColMarkings: " + colMarkings); Map<String, String> map = new TreeMap<String, String>(); // Yes - we like it sorted for (ListEntry colMarking : colMarkings) { int textRow = rowMarking.getInt("textRow"); String line = lines.get(textRow-1); String textCol = colMarking.getString("textCol"); String[] fromTo = textCol.split("\\-"); int col1 = Integer.parseInt(fromTo[0]), col2; if (fromTo[1].equals("end")) col2 = line.length(); else if (fromTo[1].endsWith(" (inc)")) col2 = Integer.parseInt(fromTo[1].substring(0, fromTo[1].length()-" (inc)".length())); else throw new RuntimeException("Ambiguous column range: " + textCol); String value = line.substring(col1-1, col2); System.out.println("Value: |" + value + "|"); map.put(colMarking.desc, value); } System.out.println("Values: " + map); } } }} | 2015-08-18 20:05:35 | delete |
| 554 | #1000604 (pitcher) | 2015-08-18 00:07:22 |
| Recognizer | Recognition Result | Visualize | Recalc |
|---|---|---|---|
| #308 | 1999 | [visualize] |
| Snippet ID: | #283 |
| Snippet name: | GetDiskStats.java |
| Eternal ID of this version: | #283/1 |
| Text MD5: | 917644d594c2117e0d5d2ba65462cc54 |
| Author: | stefan |
| Category: | |
| Type: | Java source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2014-11-08 22:25:05 |
| Source code size: | 1999 bytes / 54 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1599 / 230 |
| Referenced in: | [show references] |