001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Johannes Bellert
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.com
021: * e-Mail: Johannes.Bellert@ercgroup.com
022: *
023: * * Created on Apr 11, 2004
024: *
025: */
026: package org.hammurapi.inspectors.metrics;
027:
028: import java.util.HashSet;
029: import java.util.Iterator;
030: import java.util.Set;
031: import java.util.Vector;
032:
033: import com.pavelvlasov.jsel.TypeDefinition;
034:
035: /**
036: * @author mucbj0
037: *
038: * To change the template for this generated type comment go to
039: * Window>Preferences>Java>Code Generation>Code and Comments
040: */
041: public class CouplingMetricOfPackage extends CouplingMetric {
042:
043: public Set listAfferentPackage = new HashSet();
044: public Set listEfferentPackage = new HashSet();
045:
046: protected String packageName = "";
047:
048: private Vector listOfCouplingMetricOfClass = new Vector();
049:
050: public CouplingMetricOfPackage(String _packageName) {
051: super ();
052: this .packageName = _packageName;
053: }
054:
055: public void aggregate(CouplingMetric cCmc) {
056:
057: this .afferentMethodCounterProjectInternal += cCmc.afferentMethodCounterProjectInternal;
058: this .efferentMethodCounterProjectInternal += cCmc.efferentMethodCounterProjectInternal;
059:
060: this .afferentMethodCounter += cCmc.afferentMethodCounter;
061: this .efferentMethodCounter += cCmc.efferentMethodCounter;
062: this .efferentMethodUnresolvedCounter += cCmc.efferentMethodUnresolvedCounter;
063: this .reflectiveMethodCounter += cCmc.reflectiveMethodCounter;
064: this .afferentVariableCounter += cCmc.afferentVariableCounter;
065: this .efferentVariableCounter += cCmc.efferentVariableCounter;
066: this .reflectiveVariableCounter += cCmc.reflectiveVariableCounter;
067:
068: // this call has to be AFTER all other var aggregation
069: this .instability = this .getInstability();
070: }
071:
072: public String getRootPackageName(String fcn) {
073: //!! cut class name out of package
074: return fcn;
075: }
076:
077: public void aggregate(CouplingMetricOfClass cCmc) {
078:
079: this .aggregate((CouplingMetric) cCmc);
080:
081: for (Iterator it = cCmc.listAfferentTypes.iterator(); it
082: .hasNext();) {
083: TypeDefinition t = (TypeDefinition) it.next();
084: if (t.getFcn() != null) {
085: listAfferentPackage.add(this .getRootPackageName(t
086: .getFcn()));
087: }
088: }
089:
090: for (Iterator it = cCmc.listEfferentTypes.iterator(); it
091: .hasNext();) {
092: TypeDefinition t = (TypeDefinition) it.next();
093: if (t.getFcn() != null) {
094: listEfferentPackage.add(this .getRootPackageName(t
095: .getFcn()));
096: }
097: }
098:
099: listOfCouplingMetricOfClass.add(cCmc);
100: }
101: /*
102: public StringBuffer toXml() {
103: StringBuffer sb = new StringBuffer();
104:
105: sb.append("<CouplingMetricOfPackage ");
106: sb.append(" package=\"");
107: sb.append(this.packageName);
108: sb.append("\" numberOfClasses=\"");
109: sb.append(this.listOfCouplingMetricOfClass.size() );
110: sb.append("\">");
111: sb.append( super.toXmlCore() );
112:
113: sb.append("<ListAfferentPackages>");
114: for (Iterator it = listAfferentPackage.iterator(); it.hasNext();){
115: String p = (String)it.next();
116: if( p != null){
117: sb.append("<Package name=\"" );
118: sb.append(p);
119: sb.append("\"/>" );
120: }
121: }
122: sb.append("</ListAfferentPackages>");
123:
124: sb.append("<ListEfferentPackages>");
125: for (Iterator it = listEfferentPackage.iterator(); it.hasNext();){
126: String p = (String)it.next();
127: if( p != null){
128: sb.append("<Package name=\"" );
129: sb.append(p);
130: sb.append("\"/>" );
131: } }
132: sb.append("</ListEfferentPackages>");
133:
134: sb.append("<ListOfCouplingMetricOfClass>");
135: for( int i=0; i< this.listOfCouplingMetricOfClass.size(); i++){
136: CouplingMetricOfClass cmc = (CouplingMetricOfClass)listOfCouplingMetricOfClass.elementAt(i);
137:
138: sb.append(cmc.toXml());
139: }
140: sb.append("</ListOfCouplingMetricOfClass>");
141: sb.append("</CouplingMetricOfPackage>");
142: return sb;
143: }
144: */
145: }
|