File tree Expand file tree Collapse file tree
src/main/java/nl/rug/jbi/jsm/metrics/packagemetrics Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616import java .util .EnumSet ;
1717import java .util .List ;
1818import java .util .Map ;
19+ import java .util .Set ;
1920import java .util .concurrent .atomic .AtomicInteger ;
2021
2122import 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
Original file line number Diff line number Diff line change 11package nl .rug .jbi .jsm .metrics .packagemetrics .resource ;
22
33import com .google .common .base .Function ;
4+ import com .google .common .base .Predicate ;
45import com .google .common .collect .FluentIterable ;
56import com .google .common .collect .Iterables ;
67import 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}
You can’t perform that action at this time.
0 commit comments