Skip to content

Commit

Permalink
#648 order feature descriptions by name
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Aug 30, 2019
1 parent 9efe91f commit c7e36f4
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.pitest.coverage.CoverageExporter;
import org.pitest.coverage.execute.CoverageOptions;
Expand Down Expand Up @@ -90,16 +91,21 @@ public void describeFeatures(SideEffect1<Feature> enabled, SideEffect1<Feature>
final List<FeatureSetting> settings = parser.parseFeatures(this.options.getFeatures());
final FeatureSelector<ProvidesFeature> selector = new FeatureSelector<>(settings, available);

final HashSet<Feature> enabledFeatures = new HashSet<>();
FCollection.mapTo(selector.getActiveFeatures(), toFeature(), enabledFeatures);
List<Feature> enabledFeatures = selector.getActiveFeatures().stream()
.map(toFeature())
.distinct()
.sorted(byName())
.collect(Collectors.toList());

enabledFeatures.stream().forEach(each -> enabled.apply(each));

FCollection.forEach(enabledFeatures, enabled);

final HashSet<Feature> disabledFeatures = new HashSet<>();
FCollection.mapTo(available, toFeature(), disabledFeatures);
disabledFeatures.removeAll(enabledFeatures);

FCollection.forEach(disabledFeatures, disabled);
available.stream()
.map(toFeature())
.distinct()
.sorted(byName())
.filter(f -> !enabledFeatures.contains(f))
.forEach(each -> disabled.apply(each));

}


Expand Down Expand Up @@ -156,11 +162,12 @@ private static <T> T firstOrDefault(final Collection<? extends T> found,
return found.iterator().next();
}



private static Function<ProvidesFeature, Feature> toFeature() {
return a -> a.provides();
}


private Comparator<Feature> byName() {
return (a,b) -> a.name().compareTo(b.name());
}
}

0 comments on commit c7e36f4

Please sign in to comment.