001package org.jadira.scanner.core.concurrent;
002
003import java.util.List;
004import java.util.stream.Collectors;
005
006import org.jadira.scanner.core.api.Projector;
007
008import jsr166y.RecursiveTask;
009
010public class ProjectorTask<T> extends RecursiveTask<List<T>> {
011
012    private static final long serialVersionUID = -5338937563634945167L;
013
014    private final Projector<T> projector;
015    private final List<T> inputs;
016
017    public ProjectorTask(final Projector<T> projector, final List<T> inputs) {
018
019        this.projector = projector;
020        this.inputs = inputs;
021    }
022
023    @Override
024    public List<T> compute() {
025
026        List<T> result = inputs.stream()
027                .flatMap( t -> projector.project(t).stream() )
028                .collect( Collectors.toList() );
029        
030        return result;
031    }
032}