Skip to content

Commit

Permalink
deprecate methods and remove calls to flatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Aug 17, 2023
1 parent 7d01ce8 commit 0e2bfd2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public List<MutationAnalysisUnit> createMutationTestUnits(
final Collection<ClassName> codeClasses) {
final List<MutationAnalysisUnit> tus = new ArrayList<>();

final List<MutationDetails> mutations = FCollection.flatMap(codeClasses, mutationSource::createMutations);
final List<MutationDetails> mutations = codeClasses.stream()
.flatMap(c -> mutationSource.createMutations(c).stream())
.collect(Collectors.toList());

mutations.sort(comparing(MutationDetails::getId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;

import org.pitest.functional.FCollection;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -42,18 +40,17 @@ public class SmartSourceLocator implements SourceLocator {

public SmartSourceLocator(final Collection<Path> roots, Charset inputCharset) {
this.inputCharset = inputCharset;
final Collection<Path> childDirs = FCollection.flatMap(roots, collectChildren(MAX_DEPTH));
final Collection<Path> childDirs = roots.stream()
.flatMap(r -> collectDirectories(r, MAX_DEPTH).stream())
.collect(Collectors.toList());

childDirs.addAll(roots);

this.children = childDirs.stream()
.map(f -> new DirectorySourceLocator(f, this.inputCharset))
.collect(Collectors.toList());
}

private Function<Path, Collection<Path>> collectChildren(final int depth) {
return a -> collectDirectories(a, depth);
}

private Collection<Path> collectDirectories(Path root, int depth) {
try {
if (!Files.exists(root)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -77,8 +78,9 @@ public void shouldAssignTestsFromPrioritiserToMutant() {
}

private List<TestInfo> makeTestInfos(final Integer... times) {
return new ArrayList<>(FCollection.map(Arrays.asList(times),
timeToTestInfo()));
return Arrays.stream(times)
.map(timeToTestInfo())
.collect(Collectors.toList());
}

private Function<Integer, TestInfo> timeToTestInfo() {
Expand Down
15 changes: 11 additions & 4 deletions pitest/src/main/java/org/pitest/functional/FCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
public abstract class FCollection {

@Deprecated
public static <A, B> void mapTo(final Iterable<? extends A> as,
final Function<A, B> f, final Collection<? super B> bs) {
if (as != null) {
Expand All @@ -37,6 +38,7 @@ public static <A, B> void mapTo(final Iterable<? extends A> as,
}
}

@Deprecated
public static <A, B> List<B> map(final Iterable<? extends A> as,
final Function<A, B> f) {
final List<B> bs = emptyList();
Expand All @@ -55,25 +57,24 @@ public static <A, B> void flatMapTo(final Iterable<? extends A> as,
}
}

@Deprecated
public static <A, B> List<B> flatMap(
final Iterable<? extends A> as, final Function<A, ? extends Iterable<B>> f) {
final List<B> bs = emptyList();
flatMapTo(as, f, bs);
return bs;
}

private static <T> List<T> emptyList() {
return new ArrayList<>();
}

@Deprecated
public static <T> List<T> filter(final Iterable<? extends T> xs,
final Predicate<T> predicate) {
final List<T> dest = emptyList();
filter(xs, predicate, dest);
return dest;
}

public static <T> void filter(final Iterable<? extends T> xs,
private static <T> void filter(final Iterable<? extends T> xs,
final Predicate<T> predicate, final Collection<? super T> dest) {
for (final T x : xs) {
if (predicate.test(x)) {
Expand All @@ -82,6 +83,7 @@ public static <T> void filter(final Iterable<? extends T> xs,
}
}

@Deprecated
public static <T> boolean contains(final Iterable<? extends T> xs,
final Predicate<T> predicate) {
for (final T x : xs) {
Expand All @@ -102,6 +104,7 @@ public static <A, B> A fold(final BiFunction<A, B, A> f, final A z,
return p;
}

@Deprecated
public static <T> Collection<T> flatten(
final Iterable<? extends Iterable<? extends T>> ts) {
final List<T> list = new ArrayList<>();
Expand Down Expand Up @@ -144,4 +147,8 @@ public static <A, B> Map<A, Collection<B>> bucket(final Iterable<B> bs,
return bucketed;
}

private static <T> List<T> emptyList() {
return new ArrayList<>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -120,17 +119,18 @@ private boolean isExcludedCategory(final Class<?> a) {

private List<String> getCategories(final Class<?> a) {
final Category c = a.getAnnotation(Category.class);
return FCollection.flatMap(Arrays.asList(c), toCategoryNames());
return Stream.of(c)
.flatMap(toCategoryNames())
.collect(Collectors.toList());
}

private Function<Category, Iterable<String>> toCategoryNames() {
private Function<Category, Stream<String>> toCategoryNames() {
return a -> {
if (a == null) {
return Collections.emptyList();
return Stream.empty();
}
return Stream.of(a.value())
.map(Class::getName)
.collect(Collectors.toList());
.map(Class::getName);
};
}

Expand Down

0 comments on commit 0e2bfd2

Please sign in to comment.