📄 table.java
字号:
/* * Table.java * * Created on August 14, 2001, 7:33 AM * * See LICENSE file for license conditions. */package residue.tables;import java.util.*;import java.io.*;/** * This class is a container class for the table used to * associate probe numbers with sections of code * * @author chowells * @version */public class Table{ private List probedEntries; private List refEntries; private Set roots; // create TableEntry -> Set<TableEntry> containing children Map private Map children = new HashMap(); // package visible constructor used by parser and getTable methods Table(List probed, List refs, Set classpathRoots) { probedEntries = probed; refEntries = refs; roots = classpathRoots; boolean [] hitTable = residue.runtime.Monitor.getHitTable(); // Mark all nodes that were executed, and build the implicit // reference trees for use in Reinstrumenter // queue for reverse breadth first traversal LinkedList parents = new LinkedList(); // enqueue the leaves of the forest. Iterator it = probedEntries.iterator(); while (it.hasNext()) { TableEntry te = (TableEntry)it.next(); parents.add(te); if (hitTable[te.getIndex()]) te.setExecuted(); } // while // traverse up the trees while (!parents.isEmpty()) { TableEntry te = (TableEntry)parents.removeFirst(); if (te.getRef() >= 0) { TableEntry par = getRefEntry(te.getRef()); if (te.wasExecuted()) par.setExecuted(); // if parent isn't already found, add it to the queue. if (!children.containsKey(par)) { parents.add(par); children.put(par, new HashSet()); } Set s = (Set)children.get(par); s.add(te); } } } // Table /** * This method returns an immutable set containing Strings * which are absolute paths to the roots of the source * directories. */ public Set getSourceRoots() { return Collections.unmodifiableSet(roots); } // getSourceRoots /** * Adds a source root to the source root set, and writes it * to the table, assuming it is a valid path. */ public void addSourceRoot(String root, String file) { File dir = new File(root); if (!dir.exists() || !dir.isDirectory()) return; root = dir.getAbsolutePath() + dir.separator; try { PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(file, true))); p.println(TableCreator.filter(root)); p.close(); } catch (IOException e) {} roots.add(root); } // addSourceRoot /** * This class returns an immutable set containing the children of * the given TableEntry, or null, if that TableEntry has no children. */ public Set getChildrenOf(TableEntry te) { if (!children.containsKey(te)) return null; return Collections.unmodifiableSet((Set)children.get(te)); } // getChildrenOf /** * This method returns an iterator that iterates over ALL the * TableEntries in this Table, regardless of what type they are. */ public Iterator iterator() { return new Iterator() { Iterator probedIt = probedEntries.iterator(); Iterator refIt = refEntries.iterator(); Iterator curr = probedIt; public boolean hasNext() { return refIt.hasNext() || probedIt.hasNext(); } // hasNext() public Object next() { if (!probedIt.hasNext()) curr = refIt; return curr.next(); } // next public void remove() { throw new UnsupportedOperationException(); } // remove }; // anonymous Iterator } // iterator public TableEntry getProbedEntry(int index) { return (TableEntry)probedEntries.get(index); } // getProbedEntry public TableEntry getRefEntry(int index) { return (TableEntry)refEntries.get(index); } // getRefEntry /** * This method returns a Table generated from the contents of * the given InputStream, or throws an IOException if it's * not a valid representation of a Table. The InputStream is * closed after the read. */ public static Table getTable(InputStream is) throws IOException { try { parser p = new parser(new TableScanner(is)); return (Table)p.parse().value; } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e.getMessage()); } finally { // no matter what, try to close the stream, and // don't complain if it's not possible try { is.close(); } catch (IOException e) {} } } // getTable /** * This method returns a Table generated from the contents of * the given File, or throws an IOException if it's * not a valid representation of a Table. */ public static Table getTable(File f) throws IOException { return getTable(new BufferedInputStream(new FileInputStream(f))); } // getTable /** * This method returns a Table generated from the contents of * the file given in the String filename, or throws an IOException * if it's not a valid representation of a Table. */ public static Table getTable(String filename) throws IOException { return getTable(new File(filename)); } // getTable } // class Table
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -