org.pitest.mutationtest.build.DefaultGrouper Maven / Gradle / Ivy
package org.pitest.mutationtest.build;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.pitest.classinfo.ClassName;
import org.pitest.functional.FCollection;
import org.pitest.mutationtest.engine.MutationDetails;
public class DefaultGrouper implements MutationGrouper {
private final int unitSize;
public DefaultGrouper(final int unitSize) {
this.unitSize = unitSize;
}
@Override
public List> groupMutations(
final Collection codeClasses,
final Collection mutations) {
final Map> bucketed = FCollection
.bucket(mutations, MutationDetails::getClassName);
final List> chunked = new ArrayList<>();
for (final Map.Entry> each : bucketed.entrySet()) {
shrinkToMaximumUnitSize(chunked, each.getValue());
}
return chunked;
}
private void shrinkToMaximumUnitSize(
final List> chunked,
final Collection each) {
if (this.unitSize > 0) {
for (final List ms : FCollection.splitToLength(
this.unitSize, each)) {
chunked.add(ms);
}
} else {
chunked.add(new ArrayList<>(each));
}
}
}