001 package org.shiftone.jrat.provider.tree.ui.hierarchy.nodes;
002
003 import org.shiftone.jrat.provider.tree.ui.summary.MethodSummaryModel;
004 import org.shiftone.jrat.util.Percent;
005
006 import java.util.List;
007
008 public abstract class HierarchyNode {
009
010 private final MethodSummaryModel methodSummaryModel;
011 private static final HierarchyNode[] EMPTY = {};
012 private final String name;
013
014
015 public HierarchyNode(String name, MethodSummaryModel methodSummaryModel) {
016 this.name = name;
017 this.methodSummaryModel = methodSummaryModel;
018 }
019
020 public String getName() {
021 return name;
022 }
023
024 public String toString() {
025 return getName();
026 }
027
028
029 public MethodSummaryModel getMethodSummaryModel() {
030 return methodSummaryModel;
031 }
032
033 public abstract void finalizeStatistics();
034
035 public abstract long getTotalDuration();
036
037 public abstract int getTotalMethods();
038
039 public abstract int getExecutedMethods();
040
041 public abstract long getTotalExits();
042
043 public abstract long getTotalErrors();
044
045 public abstract Long getTotalMethodDuration();
046
047 public Percent getErrorRate() {
048 return new Percent((double) getTotalErrors() * 100.0 / (double) getTotalExits());
049 }
050
051 public Percent getCoverage() {
052 return new Percent((double) getExecutedMethods() * 100.0 / (double) getTotalMethods());
053 }
054
055 public int getUncalledMethods() {
056 return getTotalMethods() - getExecutedMethods();
057 }
058
059 public Percent getTotalMethodPercent() {
060 Long tmd = getTotalMethodDuration();
061 return (tmd == null)
062 ? null
063 : new Percent((double) tmd.longValue() * 100.0 / (double) methodSummaryModel.getTotalMethodDuration());
064 }
065
066 public abstract List getChildren();
067
068 public boolean isLeaf() {
069 return getChildCount() == 0;
070 }
071
072 public int getIndexOfChild(HierarchyNode node) {
073 for (int i = 0; i < getChildCount(); i++) {
074 if (node == getChild(i)) {
075 return i;
076 }
077 }
078 return -1;
079 }
080
081 public HierarchyNode getChild(int index) {
082 return (HierarchyNode) getChildren().get(index);
083 }
084
085 public int getChildCount() {
086 return getChildren().size();
087 }
088 }