package journal.action; import java.util.HashMap; import java.util.Map; import journal.reader.DataJournalEntry; public class CountDirectories extends BaseAction { public CountDirectories() { root = new Node("/"); } @Override public void finish() throws Exception { out.println("Directory count: " + dirCounter); out.println("Total head file count: " + fileCounter); super.finish(); } @Override public void putValue(DataJournalEntry data) throws Exception { if( data.getTableName().equals("db.revhx") ) { String depotFile = (String) data.getValue("dfile"); fileCounter++; if( options.isCaseInsensitive() ) depotFile = depotFile.toLowerCase(); // cut of the first two chars (always //), // then split into directories String[] dirs = depotFile.substring(2).split("/"); Node node = root; StringBuilder fullName = new StringBuilder("/"); for (int i = 0; i < dirs.length - 1; i++) { String dir = dirs[i]; fullName.append('/'); fullName.append(dir); Node subNode = node.findNode(dir); if( subNode == null ) { subNode = new Node(dir, node); node.addNode(subNode); dirCounter++; } node = subNode; } } } class Node { private String name; private Node parent; private Map<String, Node> subNodes = new HashMap<String, Node>(); public Node(String name) { this.name = name; this.parent = null; } public Node(String name, Node parent) { this(name); this.parent = parent; } public void addNode(Node subNode) { subNodes.put(subNode.getName(), subNode); } public Node findNode(String subNode) { if( subNodes.containsKey(subNode) ) { return subNodes.get(subNode); } else return null; } public String getName() { return name; } public Node getParent() { return parent; } public String getFullName() { return getFullNameRecursive(name); } private String getFullNameRecursive(String postfix) { if( parent != null ) { return parent.getFullNameRecursive(parent.name + "/" + postfix); } else { return postfix; } } } private long fileCounter = 0; private long dirCounter = 0; private Node root; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 24773 | Norman Morse |
Moving journalReader from sven's private branch to perforce_software. This is because journalReader is used in the perfsplit test harness, and should be updated over time. Merging //guest/sven_erik_knop/java/JournalReader/... to //guest/perforce_software/journalReader/... |
||
//guest/sven_erik_knop/java/JournalReader/src/journal/action/CountDirectories.java | |||||
#2 | 8296 | Sven Erik Knop |
Clean-up: instead of casting in every action, cast only once in the dispatcher. Should make code saner and safer. No functional change. |
||
#1 | 8173 | Sven Erik Knop |
Added journal.action.CountDirectories ... to prove a point :-) |