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

net.intelie.pipes.ListModule Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
package net.intelie.pipes;

import net.intelie.pipes.util.Iterables;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class ListModule implements Module {
    private static final long serialVersionUID = 1L;
    private final Iterable functions;
    private final String repr;

    public ListModule(Function... functions) {
        this(Arrays.asList(functions));
    }

    public ListModule(Iterable functions) {
        this.functions = Collections.unmodifiableList(StreamSupport
                .stream(functions.spliterator(), false)
                .collect(Collectors.toList()));
        this.repr = makeRepr(functions);
    }

    public static String makeRepr(Iterable functions) {
        List repr = makeReprList(functions);
        return "functions: " + Iterables.join(", ", repr);
    }

    public static List makeReprList(Iterable functions) {
        List repr = new ArrayList<>();
        for (Function function : functions) {
            repr.add(function.description());
        }
        return repr;
    }

    @Override
    public String toString() {
        return repr;
    }

    @Override
    public Iterable functions() {
        return functions;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy