001 package org.shiftone.jrat.provider.tree.ui.summary;
002
003 import org.shiftone.jrat.desktop.util.Table;
004 import org.shiftone.jrat.util.Percent;
005
006 import javax.swing.table.AbstractTableModel;
007 import java.util.List;
008
009 /**
010 * @author jeff@shiftone.org (Jeff Drost)
011 */
012 public class SummaryTableModel extends AbstractTableModel {
013
014 private static final Table TABLE = new Table();
015 public static final Table.Column PACKAGE = TABLE.column("Package", false);
016 public static final Table.Column CLASS = TABLE.column("Class");
017 public static final Table.Column METHOD = TABLE.column("Method");
018 public static final Table.Column SIGNATURE = TABLE.column("Signature", false);
019 public static final Table.Column ENTERS = TABLE.column("Enters", false);
020 public static final Table.Column EXITS = TABLE.column("Exits");
021 public static final Table.Column EXCEPTIONS = TABLE.column("Exceptions Thrown", false);
022 public static final Table.Column EXCEPTION_RATE = TABLE.column("Exception Rate", false);
023 public static final Table.Column UNCOMPLETED = TABLE.column("Uncompleted Calls", false);
024 public static final Table.Column TOTAL = TABLE.column("Total ms");
025 public static final Table.Column MIN = TABLE.column("Min ms", false);
026 public static final Table.Column MAX = TABLE.column("Max ms", false);
027 public static final Table.Column AVERAGE = TABLE.column("Average ms");
028 public static final Table.Column TOTAL_METHOD = TABLE.column("Total Method ms");
029 public static final Table.Column PERCENT_METHOD = TABLE.column("Method Time %");
030 public static final Table.Column AVERAGE_METHOD = TABLE.column("Average Method ms");
031 public static final Table.Column TOTAL_CALLERS = TABLE.column("Total Callers", false);
032
033
034 private final MethodSummaryModel summaryModel;
035 private final List methodSummaryList;
036
037 public SummaryTableModel(MethodSummaryModel summaryModel) {
038 this.summaryModel = summaryModel;
039 this.methodSummaryList = summaryModel.getMethodSummaryList();
040 }
041
042 public Object getValueAt(int rowIndex, int columnIndex) {
043 MethodSummary summary = (MethodSummary) methodSummaryList.get(rowIndex);
044
045 if (columnIndex == PACKAGE.getIndex()) {
046 return summary.getMethodKey().getPackageName();
047 }
048 if (columnIndex == CLASS.getIndex()) {
049 return summary.getMethodKey().getClassName();
050 }
051 if (columnIndex == METHOD.getIndex()) {
052 return summary.getMethodKey().getShortMethodDescription();
053 }
054 if (columnIndex == SIGNATURE.getIndex()) {
055 return summary.getMethodKey().getSig().getShortText();
056 }
057 if (columnIndex == ENTERS.getIndex()) {
058 return new Long(summary.getTotalEnters());
059 }
060 if (columnIndex == EXITS.getIndex()) {
061 return new Long(summary.getTotalExists());
062 }
063 if (columnIndex == EXCEPTIONS.getIndex()) {
064 return new Long(summary.getTotalErrors());
065 }
066 if (columnIndex == EXCEPTION_RATE.getIndex()) {
067 return summary.getErrorRate();
068 }
069 if (columnIndex == UNCOMPLETED.getIndex()) {
070 return new Long(summary.getUncompletedCalls());
071 }
072 if (columnIndex == TOTAL.getIndex()) {
073 return new Long(summary.getTotalDuration());
074 }
075 if (columnIndex == MIN.getIndex()) {
076 return summary.getMinDuration();
077 }
078 if (columnIndex == MAX.getIndex()) {
079 return summary.getMaxDuration();
080 }
081 if (columnIndex == AVERAGE.getIndex()) {
082 return summary.getAverageDuration();
083 }
084 if (columnIndex == TOTAL_METHOD.getIndex()) {
085 return summary.getTotalMethodDuration();
086 }
087 if (columnIndex == AVERAGE_METHOD.getIndex()) {
088 return summary.getAverageMethodDuration();
089 }
090 if (columnIndex == TOTAL_CALLERS.getIndex()) {
091 return new Integer(summary.getTotalCallers());
092 }
093
094 if (columnIndex == PERCENT_METHOD.getIndex()) {
095 return getPercent(summary);
096 }
097
098 throw new IllegalArgumentException("columnIndex = " + columnIndex);
099 }
100
101 private Percent getPercent(MethodSummary summary) {
102 Long tmd = summary.getTotalMethodDuration();
103 return (tmd == null)
104 ? null
105 : new Percent((double) tmd.longValue() * 100.0 / (double) summaryModel.getTotalMethodDuration());
106 }
107
108 public static List getColumns() {
109 return TABLE.getColumns();
110 }
111
112 public int getRowCount() {
113 return methodSummaryList.size();
114 }
115
116 public int getColumnCount() {
117 return TABLE.getColumnCount();
118 }
119
120 public String getColumnName(int column) {
121 return TABLE.getColumn(column).getName();
122 }
123
124
125 }