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

com.telenav.cactus.maven.util.ProcessResultConverter Maven / Gradle / Ivy

package com.telenav.cactus.maven.util;

import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.function.Supplier;

/**
 * Parses output and exit code from a command into a result object.
 *
 * @param 
 */
public interface ProcessResultConverter
{

    AwaitableCompletionStage onProcessStarted(Supplier description, Process process);

    public static StringProcessResultConverter strings()
    {
        return new StringProcessResultConverterImpl();
    }

    public static StringProcessResultConverter strings(IntPredicate exitCodeTester)
    {
        return new StringProcessResultConverterImpl(exitCodeTester);
    }

    public static ProcessResultConverter exitCodeIsZero()
    {
        return new BooleanProcessResultConverter();
    }

    public static ProcessResultConverter exitCode(IntPredicate pred)
    {
        return new BooleanProcessResultConverter(pred);
    }

    default  ProcessResultConverter map(Function converter)
    {
        return (description, proc) ->
        {
            return AwaitableCompletionStage.of(
                    onProcessStarted(description, proc)
                            .thenApply(converter));
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy