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 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 colMarkings = db.allOfType("ColMarking"); // TODO: check link to DFOutput System.out.println("ColMarkings: " + colMarkings); Map map = new TreeMap(); // 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); } }