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

internal.heylogs.maven.plugin.MojoFunction Maven / Gradle / Ivy

There is a newer version: 0.9.2
Show newest version
package internal.heylogs.maven.plugin;

import lombok.NonNull;
import nbbrd.design.StaticFactoryMethod;
import nbbrd.heylogs.Extractor;
import org.apache.maven.plugin.MojoExecutionException;

import java.time.LocalDate;
import java.util.function.Function;
import java.util.regex.Pattern;

@FunctionalInterface
public interface MojoFunction {

    Y applyWithMojo(X x) throws MojoExecutionException;

    static  @NonNull MojoFunction of(@NonNull Function function, @NonNull String errorMessage) {
        return x -> {
            try {
                return function.apply(x);
            } catch (IllegalArgumentException ex) {
                throw new MojoExecutionException(errorMessage, ex);
            }
        };
    }

    @StaticFactoryMethod
    static @NonNull MojoFunction onPattern(@NonNull String errorMessage) {
        return of(Pattern::compile, errorMessage);
    }

    @StaticFactoryMethod
    static @NonNull MojoFunction onLocalDate(@NonNull String errorMessage) {
        return of(Extractor::parseLocalDate, errorMessage);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy