01: package com.kirkk.analyzer.framework.bcelbundle;
02:
03: import com.kirkk.analyzer.framework.*;
04: import java.math.BigDecimal;
05:
06: public class JarMetricsImpl implements JarMetrics {
07: private Jar jar;
08:
09: public JarMetricsImpl(Jar jar) {
10: this .jar = jar;
11: }
12:
13: public BigDecimal calculateAbstractness() {
14: int classCount = jar.getClassCount();
15: if (classCount == 0) {
16: return new BigDecimal("-1.0");
17: }
18: BigDecimal totalClassCount = new BigDecimal(new Integer(
19: classCount).toString());
20: BigDecimal abstractClassCount = new BigDecimal(new Integer(jar
21: .getAbstractClassCount()).toString());
22: return abstractClassCount.divide(totalClassCount, 2,
23: BigDecimal.ROUND_HALF_UP);
24: }
25:
26: public BigDecimal calculateInstability() {
27: int afferent = this .calculateAfferentCoupling();
28: int efferent = this .calculateEfferentCoupling();
29:
30: if (afferent + efferent == 0) {
31: return new BigDecimal("-1.0");
32: }
33:
34: BigDecimal top = new BigDecimal(new Integer(efferent)
35: .toString());
36: BigDecimal bottom = new BigDecimal(new Integer(afferent
37: + efferent).toString());
38:
39: return top.divide(bottom, 2, BigDecimal.ROUND_HALF_UP);
40: }
41:
42: public int calculateEfferentCoupling() {
43: return jar.getOutgoingDependencies().size();
44: }
45:
46: public int calculateAfferentCoupling() {
47: return jar.getIncomingDependencies().size();
48: }
49:
50: public BigDecimal calculateDistance() {
51: BigDecimal abstractness = this .calculateAbstractness();
52: BigDecimal instability = this .calculateInstability();
53: if (abstractness.equals(new BigDecimal("-1.0"))
54: || instability.equals(new BigDecimal("-1.0"))) {
55: return new BigDecimal("-1.0");
56: }
57: return abstractness.add(instability).subtract(
58: new BigDecimal("1.00")).abs();
59: }
60: }
|