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 org.w3c.dom.Document;
029: import org.w3c.dom.Element;
030:
031: /**
032: * @author mucbj0
033: *
034: file:///D:/anwend/java/JDepend-2.6/ltcaemodel.xml.html
035:
036: Instability
037: The ratio of efferent coupling (Ce) to total coupling (Ce / (Ce + Ca)). This metric is an indicator of the package's resilience to change.
038:
039: The range for this metric is 0 to 1, with I=0 indicating a completely stable package and I=1 indicating a completely instable package.
040:
041:
042: **/
043: public class CouplingMetric {
044:
045: public float instability = 0;
046:
047: public int afferentMethodCounter = 0;
048: public int efferentMethodCounter = 0;
049:
050: public int afferentMethodCounterProjectInternal = 0;
051: public int efferentMethodCounterProjectInternal = 0;
052:
053: public int efferentMethodUnresolvedCounter = 0;
054: public int reflectiveMethodCounter = 0;
055:
056: public int afferentVariableCounter = 0;
057: public int efferentVariableCounter = 0;
058:
059: public int reflectiveVariableCounter = 0;
060:
061: public CouplingMetric() {
062: super ();
063: }
064:
065: public StringBuffer toXmlCore() {
066: StringBuffer sb = new StringBuffer();
067:
068: sb.append("<Instability>");
069: sb.append(this .getInstability());
070: sb.append("</Instability>");
071:
072: sb.append("<ReflectiveVariableCounter>");
073: sb.append(reflectiveVariableCounter);
074: sb.append("</ReflectiveVariableCounter>");
075:
076: sb.append("<AfferentMethodCounterProjectInternal>");
077: sb.append(afferentMethodCounterProjectInternal);
078: sb.append("</AfferentMethodCounterProjectInternal>");
079: sb.append("<EfferentMethodCounterProjectInternal>");
080: sb.append(efferentMethodCounterProjectInternal);
081: sb.append("</EfferentMethodCounterProjectInternal>");
082:
083: sb.append("<AfferentMethodCounter>");
084: sb.append(afferentMethodCounter);
085: sb.append("</AfferentMethodCounter>");
086: sb.append("<EfferentMethodCounter>");
087: sb.append(efferentMethodCounter);
088: sb.append("</EfferentMethodCounter>");
089:
090: sb.append("<AfferentVariableCounter>");
091: sb.append(afferentVariableCounter);
092: sb.append("</AfferentVariableCounter>");
093: sb.append("<EfferentVariableCounter>");
094: sb.append(efferentVariableCounter);
095: sb.append("</EfferentVariableCounter>");
096:
097: sb.append("<EfferentMethodUnresolvedCounter>");
098: sb.append(efferentMethodUnresolvedCounter);
099: sb.append("</EfferentMethodUnresolvedCounter>");
100:
101: return sb;
102: }
103:
104: public Element toDom(Document document, Element root) {
105:
106: Element ret = document.createElement("AfferentMethodCounter");
107: ret.setAttribute("number", String
108: .valueOf(afferentVariableCounter));
109: root.appendChild(ret);
110:
111: Element ret2 = document.createElement("EfferentMethodCounter");
112: ret2.setAttribute("number", String
113: .valueOf(efferentVariableCounter));
114: root.appendChild(ret2);
115:
116: return root;
117: }
118:
119: /**
120: * @return (Ce / (Ce + Ca))
121: */
122: public float getInstability() {
123: // (Ce / (Ce + Ca))
124: float instability = 0;
125: float denominator = (this .efferentMethodCounter + this .afferentMethodCounter);
126: // System.out.println (" " + denominator +" = " + this.efferentMethodCounter +" + " + this.afferentMethodCounter );
127: if (denominator != 0) {
128: instability = this .efferentMethodCounter / denominator;
129: }
130: // System.out.println (" instability " + instability );
131: return instability;
132: }
133:
134: }
|