Skip to content

Commit 3d78007

Browse files
committed
Fix for the IPCI issue where ClientsP(p) is greater than P
1 parent 866bac6 commit 3d78007

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/main/java/nl/rug/jbi/jsm/metrics/packagemetrics/IPCI.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.EnumSet;
1717
import java.util.List;
1818
import java.util.Map;
19+
import java.util.Set;
1920
import java.util.concurrent.atomic.AtomicInteger;
2021

2122
import static nl.rug.jbi.jsm.metrics.packagemetrics.CollectionAccumulator.DEF_ATOMIC_DOUBLE;
@@ -37,7 +38,11 @@ public IPCI() {
3738
@Subscribe
3839
@UsingProducer(PackageProducer.class)
3940
public void onPackage(final MetricState state, final PackageUnit pack) {
40-
state.setValue("IPCI-ClientsP", pack.ClientsP().size());
41+
//For this metric, clamp ClientsP to the set P in M. This is done because ClientsP can contain packages
42+
//that are not part of the same collection, resulting in a ClientsP that is larger than P, which results
43+
//in negative values for this metric.
44+
final Set<String> ClientsP = pack.filterSameCollectionP(pack.ClientsP());
45+
state.setValue("IPCI-ClientsP", ClientsP.size());
4146
state.setValue("Collection", pack.getSourceIdentifier());
4247
}
4348

src/main/java/nl/rug/jbi/jsm/metrics/packagemetrics/resource/PackageUnit.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package nl.rug.jbi.jsm.metrics.packagemetrics.resource;
22

33
import com.google.common.base.Function;
4+
import com.google.common.base.Predicate;
45
import com.google.common.collect.FluentIterable;
56
import com.google.common.collect.Iterables;
67
import com.google.common.collect.Sets;
@@ -232,4 +233,20 @@ public Iterable<String> apply(ClassData member) {
232233
})
233234
.toSet();
234235
}
236+
237+
/**
238+
* Filters the given set of package names so only those that belong to the same collection as this package remain.
239+
*
240+
* @param packageNames Set of package names to filter
241+
* @return A filtered view of the given set.
242+
*/
243+
public Set<String> filterSameCollectionP(final Set<String> packageNames) {
244+
return Sets.filter(packageNames, new Predicate<String>() {
245+
@Override
246+
public boolean apply(final String packageName) {
247+
final String otherSource = packagedata.get(packageName).getPackageSource();
248+
return data.getPackageSource().equals(otherSource);
249+
}
250+
});
251+
}
235252
}

0 commit comments

Comments
 (0)