Skip to content

Commit

Permalink
Merge pull request #1249 from hcoles/feature/more_fcollection_removal
Browse files Browse the repository at this point in the history
remove FCollection calls
  • Loading branch information
hcoles authored Aug 23, 2023
2 parents 1d81ffa + eaa21c5 commit e52bbe2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public void add(final MutationTestSummaryData data) {
}

public Collection<TestInfo> getTests() {
final Set<TestInfo> uniqueTests = new HashSet<>();
FCollection.flatMapTo(this.mutations.values(), mutationToTargettedTests(),
uniqueTests);
return uniqueTests;
return this.mutations.values().stream()
.flatMap(a -> a.getDetails().getTestsInOrder().stream())
.distinct()
.collect(Collectors.toList());
}

public String getFileName() {
Expand Down Expand Up @@ -145,10 +145,6 @@ private long getNumberOfMutationsDetected() {
return count;
}

private Function<MutationResult, Iterable<TestInfo>> mutationToTargettedTests() {
return a -> a.getDetails().getTestsInOrder();
}

private static Map<MutationIdentifier, MutationResult> resultsToMap(Collection<MutationResult> results) {
return results.stream().collect(Collectors.toMap(mr -> mr.getDetails().getId(), Function.identity()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static <A, B> List<B> map(final Iterable<? extends A> as,
return bs;
}

@Deprecated
public static <A, B> void flatMapTo(final Iterable<? extends A> as,
final Function<A, ? extends Iterable<B>> f, final Collection<? super B> bs) {
if (as != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package org.pitest.mutationtest.engine.gregor.config;

import org.pitest.functional.FCollection;
import org.pitest.help.Help;
import org.pitest.help.PitHelpError;
import org.pitest.mutationtest.engine.gregor.MethodMutatorFactory;
Expand Down Expand Up @@ -42,6 +41,7 @@
import java.util.TreeSet;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.pitest.functional.Streams.asStream;

Expand Down Expand Up @@ -120,11 +120,13 @@ public static Collection<MethodMutatorFactory> fromStrings(
.filter(s -> !s.startsWith("-"))
.collect(Collectors.toList());

final Set<MethodMutatorFactory> unique = new TreeSet<>(compareId());
FCollection.flatMapTo(inclusions, fromString(MUTATORS), unique);
Set<MethodMutatorFactory> unique = inclusions.stream()
.flatMap(fromString(MUTATORS))
.collect(Collectors.toCollection(() -> new TreeSet<>(compareId())));

final Set<MethodMutatorFactory> excluded = new TreeSet<>(compareId());
FCollection.flatMapTo(exclusions, fromString(MUTATORS), excluded);
Set<MethodMutatorFactory> excluded = exclusions.stream()
.flatMap(fromString(MUTATORS))
.collect(Collectors.toCollection(() -> new TreeSet<>(compareId())));

unique.removeAll(excluded);

Expand All @@ -135,18 +137,18 @@ private static Comparator<? super MethodMutatorFactory> compareId() {
return Comparator.comparing(MethodMutatorFactory::getGloballyUniqueId);
}

private static Function<String, Iterable<MethodMutatorFactory>> fromString(Map<String, List<MethodMutatorFactory>> mutators) {
private static Function<String, Stream<MethodMutatorFactory>> fromString(Map<String, List<MethodMutatorFactory>> mutators) {
return a -> {

if (a.equals("ALL")) {
return all();
return all().stream();
}

final Iterable<MethodMutatorFactory> i = mutators.get(a);
final List<MethodMutatorFactory> i = mutators.get(a);
if (i == null) {
throw new PitHelpError(Help.UNKNOWN_MUTATOR, a);
}
return i;
return i.stream();
};
}

Expand Down

0 comments on commit e52bbe2

Please sign in to comment.