package lan.dk.podcastserver.manager.worker.selector;

import lan.dk.podcastserver.manager.worker.updater.AbstractUpdater;
import lan.dk.podcastserver.manager.worker.updater.NoOpUpdater;
import lan.dk.podcastserver.manager.worker.updater.Updater;
import lombok.Setter;
import org.jadira.usertype.spi.utils.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.Set;

import static java.util.stream.Collectors.toSet;

/**
 * Created by kevin on 06/03/15.
 */
@Service
//@RequiredArgsConstructor(onConstructor = @__(@Autowired) )
public class UpdaterSelector {

    public static final NoOpUpdater NO_OP_UPDATER = new NoOpUpdater();

    @Setter(onMethod = @__(@Autowired))
    private Set<Updater> updaters;
    
    public Updater of(String url) {
        if (StringUtils.isEmpty(url)) {
            return NO_OP_UPDATER;
        }
        
        return updaters
                .stream()
                .min(Comparator.comparing(updater -> updater.compatibility(url)))
                .orElse(NO_OP_UPDATER);
    }

    public Set<AbstractUpdater.Type> types() {
        return updaters.stream().map(Updater::type).collect(toSet());
    }


}

@@ -254,21 +254,38 @@
  lombok.
-Sette
+RequiredArgsConstructo
 r;%0Aimpor
@@ -601,10 +601,8 @@
 ice%0A
-//
 @Req
@@ -768,47 +768,13 @@
     
-@Setter(onMethod = @__(@Autowired))%0A   
+final
  pri

change signature of constructor