All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hadii.stiff.metrics.FanInMetric Maven / Gradle / Ivy

The newest version!
package com.hadii.stiff.metrics;

import com.hadii.clarpse.sourcemodel.Component;
import com.hadii.clarpse.sourcemodel.OOPSourceCodeModel;

import java.util.HashSet;
import java.util.Set;

/**
 * Represents the FanIn metric, which is a measure of the number of other classes that reference the given class.
 */
public class FanInMetric implements Metric {

    private final Component component;
    private final OOPSourceCodeModel srcModel;

    public FanInMetric(OOPSourceCodeModel model, Component component) {
        this.component = component;
        this.srcModel = model;
    }

    public double value() {
        Set invokingClasses = new HashSet<>();
        this.srcModel.components().forEach((tmpComponent) -> {
            if (tmpComponent.componentType().isBaseComponent()) {
                tmpComponent.references().forEach(invocation -> {
                    if (invocation.invokedComponent().equals(component.uniqueName())) {
                        invokingClasses.add(tmpComponent.uniqueName());

                    }
                });
            }
        });
        return invokingClasses.size();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy