Untitled

mail@pastecode.io avatar
unknown
java
23 days ago
1.2 kB
4
Indexable
Never
package org.example.streams;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.example.StringsTransformer;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StringTransformersStreams {

    private Logger logger = (Logger) LogManager.getLogger(getClass());

    List<String> data;

    public StringTransformersStreams(List<String> data){
        this.data = data;
    }

    private String transformSingleString(String str, List<StringsTransformer.StringFunction> functions) {
        String currStr = str;

        for (StringsTransformer.StringFunction func : functions) {
            currStr = func.transform(currStr);
        }
        return currStr;
    }

    public List<String> transform(List<StringsTransformer.StringFunction> functions) throws InterruptedException {

        List<String> res = this.data.parallelStream().map(str -> transformSingleString(str, functions)).collect(Collectors.toList());

        logger.info("data=["+ Arrays.toString(this.data.toArray())+"]");
        logger.info("res=["+Arrays.toString(res.toArray())+"]");

        return res;
    }
}
Leave a Comment