KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > metrics > CouplingMetricOfPackage


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Johannes Bellert
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.com
21  * e-Mail: Johannes.Bellert@ercgroup.com
22  *
23  * * Created on Apr 11, 2004
24  *
25  */

26 package org.hammurapi.inspectors.metrics;
27
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import com.pavelvlasov.jsel.TypeDefinition;
34
35 /**
36  * @author mucbj0
37  *
38  * To change the template for this generated type comment go to
39  * Window>Preferences>Java>Code Generation>Code and Comments
40  */

41 public class CouplingMetricOfPackage extends CouplingMetric {
42
43     public Set JavaDoc listAfferentPackage = new HashSet JavaDoc();
44     public Set JavaDoc listEfferentPackage = new HashSet JavaDoc();
45
46     protected String JavaDoc packageName = "";
47
48     private Vector JavaDoc listOfCouplingMetricOfClass = new Vector JavaDoc();
49
50     public CouplingMetricOfPackage( String JavaDoc _packageName){
51                 super();
52                 this.packageName = _packageName;
53             }
54
55     public void aggregate(CouplingMetric cCmc) {
56
57         this.afferentMethodCounterProjectInternal
58             += cCmc.afferentMethodCounterProjectInternal;
59         this.efferentMethodCounterProjectInternal
60             += cCmc.efferentMethodCounterProjectInternal;
61
62         this.afferentMethodCounter += cCmc.afferentMethodCounter;
63         this.efferentMethodCounter += cCmc.efferentMethodCounter;
64         this.efferentMethodUnresolvedCounter
65             += cCmc.efferentMethodUnresolvedCounter;
66         this.reflectiveMethodCounter += cCmc.reflectiveMethodCounter;
67         this.afferentVariableCounter += cCmc.afferentVariableCounter;
68         this.efferentVariableCounter += cCmc.efferentVariableCounter;
69         this.reflectiveVariableCounter += cCmc.reflectiveVariableCounter;
70
71         // this call has to be AFTER all other var aggregation
72
this.instability = this.getInstability();
73     }
74
75     public String JavaDoc getRootPackageName( String JavaDoc fcn){
76         //!! cut class name out of package
77
return fcn;
78     }
79     public void aggregate(CouplingMetricOfClass cCmc) {
80
81         this.aggregate( (CouplingMetric)cCmc );
82
83         for (Iterator JavaDoc it = cCmc.listAfferentTypes.iterator(); it.hasNext();){
84             TypeDefinition t = (TypeDefinition)it.next();
85             if( t.getFcn() != null ){
86                 listAfferentPackage.add(this.getRootPackageName( t.getFcn()));
87             }
88             }
89
90         for (Iterator JavaDoc it = cCmc.listEfferentTypes.iterator(); it.hasNext();){
91             TypeDefinition t = (TypeDefinition)it.next();
92             if( t.getFcn() != null ){
93             listEfferentPackage.add( this.getRootPackageName( t.getFcn()) );
94             }
95             }
96
97         listOfCouplingMetricOfClass.add(cCmc);
98     }
99 /*
100     public StringBuffer toXml() {
101         StringBuffer sb = new StringBuffer();
102
103         sb.append("<CouplingMetricOfPackage ");
104                 sb.append(" package=\"");
105                 sb.append(this.packageName);
106                 sb.append("\" numberOfClasses=\"");
107                 sb.append(this.listOfCouplingMetricOfClass.size() );
108                 sb.append("\">");
109         sb.append( super.toXmlCore() );
110
111         sb.append("<ListAfferentPackages>");
112         for (Iterator it = listAfferentPackage.iterator(); it.hasNext();){
113             String p = (String)it.next();
114             if( p != null){
115                 sb.append("<Package name=\"" );
116             sb.append(p);
117             sb.append("\"/>" );
118             }
119         }
120         sb.append("</ListAfferentPackages>");
121
122         sb.append("<ListEfferentPackages>");
123         for (Iterator it = listEfferentPackage.iterator(); it.hasNext();){
124             String p = (String)it.next();
125                     if( p != null){
126                         sb.append("<Package name=\"" );
127                     sb.append(p);
128                     sb.append("\"/>" );
129                     } }
130         sb.append("</ListEfferentPackages>");
131
132         sb.append("<ListOfCouplingMetricOfClass>");
133         for( int i=0; i< this.listOfCouplingMetricOfClass.size(); i++){
134             CouplingMetricOfClass cmc = (CouplingMetricOfClass)listOfCouplingMetricOfClass.elementAt(i);
135
136             sb.append(cmc.toXml());
137         }
138         sb.append("</ListOfCouplingMetricOfClass>");
139         sb.append("</CouplingMetricOfPackage>");
140         return sb;
141     }
142 */

143 }
144
145
Popular Tags