All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pitest.mutationtest.build.CompoundMutationInterceptor Maven / Gradle / Ivy

There is a newer version: 1.17.1
Show newest version
package org.pitest.mutationtest.build;

import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.classpath.CodeSource;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static java.util.Comparator.comparing;

public class CompoundMutationInterceptor implements MutationInterceptor {

  private final List children = new ArrayList<>();

  public CompoundMutationInterceptor(List interceptors) {
    this.children.addAll(interceptors);
    this.children.sort(comparing(MutationInterceptor::type));
  }

  public static MutationInterceptor nullInterceptor() {
    return new CompoundMutationInterceptor(Collections.emptyList());
  }

  public CompoundMutationInterceptor filter(Predicate p) {
    return new CompoundMutationInterceptor(children.stream()
            .filter(p)
            .collect(Collectors.toList()));
  }

  @Override
  public void initialise(CodeSource code) {
    this.children.forEach(each -> each.initialise(code));
  }

  @Override
  public void begin(ClassTree clazz) {
    this.children.forEach(each -> each.begin(clazz));
  }

  @Override
  public Collection intercept(
      Collection mutations, Mutater m) {
    Collection modified = mutations;
    for (final MutationInterceptor each : this.children) {
      modified = each.intercept(modified, m);
    }
    return modified;
  }

  @Override
  public void end() {
    this.children.forEach(MutationInterceptor::end);
  }

  @Override
  public InterceptorType type() {
    return InterceptorType.OTHER;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy