com.hadii.stiff.metrics.DITMetric Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stiff-lib Show documentation
Show all versions of stiff-lib Show documentation
stiff-lib is a java library for generating stiff diagrams.
The newest version!
package com.hadii.stiff.metrics;
import com.hadii.clarpse.reference.ComponentReference;
import com.hadii.clarpse.sourcemodel.Component;
import com.hadii.clarpse.sourcemodel.OOPSourceCodeModel;
import com.hadii.clarpse.sourcemodel.OOPSourceModelConstants;
import java.util.Optional;
/**
* Represents a Depth of Inheritance metric, which is a measure of how far down a class is declared in
* the inheritance hierarchy.
*/
public class DITMetric implements Metric {
private final double value;
private final OOPSourceCodeModel srcModel;
public DITMetric(Component component, OOPSourceCodeModel srcModel) {
this.srcModel = srcModel;
this.value = calculateDit(component);
}
private int calculateDit(Component cmp) {
if (cmp.componentType() == OOPSourceModelConstants.ComponentType.INTERFACE) {
return 1;
}
int currentHighestScore = 1;
for (ComponentReference cmpRef : cmp.references(OOPSourceModelConstants.TypeReferences.EXTENSION)) {
Optional invkCmp = this.srcModel.getComponent(cmpRef.invokedComponent());
if (invkCmp.isPresent()) {
int hierarchyScore = 1 + calculateDit(invkCmp.get());
if (hierarchyScore > currentHighestScore) {
currentHighestScore = hierarchyScore;
}
}
}
return currentHighestScore;
}
public double value() {
return this.value;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy