001: /*
002: * Author: Chris Seguin
003: *
004: * This software has been developed under the copyleft
005: * rules of the GNU General Public License. Please
006: * consult the GNU General Public License for more
007: * details about use and distribution of this software.
008: */
009: package org.acm.seguin.metrics;
010:
011: /**
012: * Stores the metrics for a particular package
013: *
014: *@author Chris Seguin
015: *@created July 23, 1999
016: */
017: public class PackageMetrics {
018: /*<Instance Variables>*/
019: private String packageName;
020: private int publicMethodTotal = 0;
021: private int otherMethodTotal = 0;
022: private int classMethodTotal = 0;
023: private int instanceVariableTotal = 0;
024: private int classVariableTotal = 0;
025: private int classTotal = 0;
026: private int abstractClassCount = 0;
027: private int interfaceCount = 0;
028: private int statementTotal = 0;
029: private int parameterTotal = 0;
030: private int blockDepthTotal = 0;
031: private int lineCountTotal = 0;
032:
033: /*</Instance Variables>*/
034:
035: /*<Constructor>*/
036: /**
037: * Constructor for the PackageMetrics object
038: *
039: *@param initPackage Description of Parameter
040: */
041: public PackageMetrics(String initPackage) {
042: packageName = initPackage;
043: }
044:
045: /*</Constructor>*/
046:
047: /*<Getters>*/
048: /**
049: * Get the package name
050: *
051: *@return the package name
052: */
053: public String getPackageName() {
054: return packageName;
055: }
056:
057: /**
058: * Return the public method count
059: *
060: *@return The public method count
061: */
062: public int getPublicMethodTotal() {
063: return publicMethodTotal;
064: }
065:
066: /**
067: * Return the other method count
068: *
069: *@return The other method count
070: */
071: public int getOtherMethodTotal() {
072: return otherMethodTotal;
073: }
074:
075: /**
076: * Return the class method count
077: *
078: *@return The class method count
079: */
080: public int getClassMethodTotal() {
081: return classMethodTotal;
082: }
083:
084: /**
085: * Return the instance variable count
086: *
087: *@return The instance variable count
088: */
089: public int getInstanceVariableTotal() {
090: return instanceVariableTotal;
091: }
092:
093: /**
094: * Return the class variable count
095: *
096: *@return The class variable count
097: */
098: public int getClassVariableTotal() {
099: return classVariableTotal;
100: }
101:
102: /**
103: * Return the class count
104: *
105: *@return The class count
106: */
107: public int getClassTotal() {
108: return classTotal;
109: }
110:
111: /**
112: * Return the abstract class count
113: *
114: *@return The abstract class count
115: */
116: public int getAbstractClassCount() {
117: return abstractClassCount;
118: }
119:
120: /**
121: * Return the abstract class count
122: *
123: *@return The abstract class count
124: */
125: public int getInterfaceCount() {
126: return interfaceCount;
127: }
128:
129: /**
130: * Return the statement total
131: *
132: *@return The statement total
133: */
134: public int getStatementTotal() {
135: return statementTotal;
136: }
137:
138: /**
139: * Return the parameter total
140: *
141: *@return The parameter total
142: */
143: public int getParameterTotal() {
144: return parameterTotal;
145: }
146:
147: /**
148: * Return the statement average
149: *
150: *@return The statement average
151: */
152: public double getStatementAverage() {
153: double top = statementTotal;
154: double bottom = publicMethodTotal + otherMethodTotal
155: + classMethodTotal;
156: return top / bottom;
157: }
158:
159: /**
160: * Return the parameter average
161: *
162: *@return The parameter average
163: */
164: public double getParameterAverage() {
165: double top = parameterTotal;
166: double bottom = publicMethodTotal + otherMethodTotal
167: + classMethodTotal;
168: return top / bottom;
169: }
170:
171: /**
172: * Return the block depth average
173: *
174: *@return The block depth average
175: */
176: public double getBlockDepthAverage() {
177: double top = blockDepthTotal;
178: double bottom = publicMethodTotal + otherMethodTotal
179: + classMethodTotal;
180: return top / bottom;
181: }
182:
183: /**
184: * Return the lines of code average
185: *
186: *@return The lines of code average
187: */
188: public double getLinesOfCodeAverage() {
189: double top = lineCountTotal;
190: double bottom = publicMethodTotal + otherMethodTotal
191: + classMethodTotal;
192: return top / bottom;
193: }
194:
195: /**
196: * Return the public method count
197: *
198: *@return The public method count
199: */
200: public double getPublicMethodAverage() {
201: double top = publicMethodTotal;
202: double bottom = classTotal;
203: return top / bottom;
204: }
205:
206: /**
207: * Return the other method count
208: *
209: *@return The other method count
210: */
211: public double getOtherMethodAverage() {
212: double top = otherMethodTotal;
213: double bottom = classTotal;
214: return top / bottom;
215: }
216:
217: /**
218: * Return the class method count
219: *
220: *@return The class method count
221: */
222: public double getClassMethodAverage() {
223: double top = classMethodTotal;
224: double bottom = classTotal;
225: return top / bottom;
226: }
227:
228: /**
229: * Return the instance variable count
230: *
231: *@return The instance variable count
232: */
233: public double getInstanceVariableAverage() {
234: double top = instanceVariableTotal;
235: double bottom = classTotal;
236: return top / bottom;
237: }
238:
239: /**
240: * Return the class variable count
241: *
242: *@return The class variable count
243: */
244: public double getClassVariableAverage() {
245: double top = classVariableTotal;
246: double bottom = classTotal;
247: return top / bottom;
248: }
249:
250: /**
251: * Return the abstract class count
252: *
253: *@return The abstract class count
254: */
255: public double getAbstractClassPercentage() {
256: double top = abstractClassCount;
257: double bottom = classTotal;
258: return 100 * top / bottom;
259: }
260:
261: /**
262: * Return the abstract class count
263: *
264: *@return The abstract class count
265: */
266: public double getInterfacePercentage() {
267: double top = interfaceCount;
268: double bottom = classTotal;
269: return 100 * top / bottom;
270: }
271:
272: /*</Getters>*/
273:
274: /*<Setters>*/
275: /**
276: * Increment the abstract class count
277: */
278: void incrAbstractClassCount() {
279: abstractClassCount++;
280: }
281:
282: /**
283: * Increment the interface count
284: */
285: void incrInterfaceCount() {
286: interfaceCount++;
287: }
288:
289: /**
290: * Add in a type
291: *
292: *@param typeData the type data
293: */
294: void add(TypeMetrics typeData) {
295: publicMethodTotal += typeData.getPublicMethodCount();
296: otherMethodTotal += typeData.getOtherMethodCount();
297: classMethodTotal += typeData.getClassMethodCount();
298: instanceVariableTotal += typeData.getInstanceVariableCount();
299: classVariableTotal += typeData.getClassVariableCount();
300: statementTotal += typeData.getStatementTotal();
301: parameterTotal += typeData.getParameterTotal();
302: lineCountTotal += typeData.getLinesOfCodeTotal();
303: blockDepthTotal += typeData.getBlockDepthTotal();
304: classTotal++;
305: }
306: /*</Setters>*/
307: }
|