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

com.github.mikesafonov.pitest.git.changes.TargetClassToCodeChangeMappingFunction Maven / Gradle / Ivy

The newest version!
package com.github.mikesafonov.pitest.git.changes;

import com.github.mikesafonov.pitest.git.GitChange;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FilenameUtils;

import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

@RequiredArgsConstructor
public class TargetClassToCodeChangeMappingFunction implements Function> {
    private final Set targetClasses;

    @Override
    public Optional apply(GitChange change) {
        String className = toClassName(change.getFileName());
        return targetClasses.stream()
                .filter(className::endsWith)
                .map(s -> new CodeChange(s, change.getLineFrom(), change.getLineTo()))
                .findFirst();
    }

    private static String toClassName(String filename) {
        String name = FilenameUtils.removeExtension(filename);
        return name.replace("/", ".");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy