001 package org.shiftone.jrat.provider.tree.ui.hierarchy.nodes; 002 003 import org.shiftone.jrat.provider.tree.ui.summary.MethodSummaryModel; 004 005 import java.util.ArrayList; 006 import java.util.Iterator; 007 import java.util.List; 008 009 /** 010 * @author jeff@shiftone.org (Jeff Drost) 011 */ 012 public class PackageHierarchyNode extends HierarchyNode { 013 014 015 private List childPackages = new ArrayList(); 016 private List childClasses = new ArrayList(); 017 private int totalMethods; 018 private int executedMethods; 019 private long totalDuration; 020 private long totalMethodDuration; 021 private long totalErrors; 022 private long totalExits; 023 024 public PackageHierarchyNode(String name, MethodSummaryModel methodSummaryModel) { 025 super(name, methodSummaryModel); 026 027 } 028 029 public void finalizeStatistics() { 030 031 for (Iterator i = childPackages.iterator(); i.hasNext();) { 032 PackageHierarchyNode node = (PackageHierarchyNode) i.next(); 033 addStatistics(node); 034 } 035 for (Iterator i = childClasses.iterator(); i.hasNext();) { 036 ClassHierarchyNode node = (ClassHierarchyNode) i.next(); 037 addStatistics(node); 038 } 039 040 } 041 042 private void addStatistics(HierarchyNode node) { 043 044 node.finalizeStatistics(); 045 046 totalMethods += node.getTotalMethods(); 047 executedMethods += node.getExecutedMethods(); 048 totalDuration += node.getTotalDuration(); 049 totalErrors += node.getTotalErrors(); 050 totalExits += node.getTotalExits(); 051 052 Long tmd = node.getTotalMethodDuration(); 053 if (tmd != null) { 054 totalMethodDuration += tmd.longValue(); 055 } 056 } 057 058 059 public Long getTotalMethodDuration() { 060 return new Long(totalMethodDuration); 061 } 062 063 public int getTotalMethods() { 064 return totalMethods; 065 } 066 067 public int getExecutedMethods() { 068 return executedMethods; 069 } 070 071 public long getTotalDuration() { 072 return totalDuration; 073 } 074 075 076 public long getTotalExits() { 077 return totalExits; 078 } 079 080 public long getTotalErrors() { 081 return totalErrors; 082 } 083 084 public List getChildren() { 085 List list = new ArrayList(); 086 list.addAll(childPackages); 087 list.addAll(childClasses); 088 return list; 089 } 090 091 public void addClass(ClassHierarchyNode classNode) { 092 childClasses.add(classNode); 093 } 094 095 096 public void addPackage(PackageHierarchyNode packageNode) { 097 childPackages.add(packageNode); 098 } 099 100 /** 101 * Retreves the child package with the provided name or creates it if it 102 * does not exist. 103 */ 104 public PackageHierarchyNode getChildPackage(String name) { 105 for (int i = 0; i < childPackages.size(); i++) { 106 PackageHierarchyNode child = (PackageHierarchyNode) childPackages.get(i); 107 if (child.getName().equals(name)) { 108 return child; 109 } 110 } 111 PackageHierarchyNode node = new PackageHierarchyNode(name, getMethodSummaryModel()); 112 addPackage(node); 113 return node; 114 } 115 116 public PackageHierarchyNode getChildPackage(String[] nameParts) { 117 if (nameParts.length == 0) { 118 return this; 119 } 120 121 PackageHierarchyNode current = getChildPackage(nameParts[0]); 122 for (int i = 1; i < nameParts.length; i++) { 123 current = current.getChildPackage(nameParts[i]); 124 } 125 return current; 126 } 127 128 129 /** 130 * Retreves the child class with the provided name or creates it if it does 131 * not exist. 132 */ 133 public ClassHierarchyNode getChildClass(String name) { 134 for (int i = 0; i < childClasses.size(); i++) { 135 ClassHierarchyNode child = (ClassHierarchyNode) childClasses.get(i); 136 if (child.getName().equals(name)) { 137 return child; 138 } 139 } 140 ClassHierarchyNode node = new ClassHierarchyNode(name, getMethodSummaryModel()); 141 addClass(node); 142 return node; 143 } 144 145 }