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

import javaslang.collection.HashSet;
import javaslang.collection.Set;
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.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Comparator;

/**
 * Created by kevin on 06/03/15.
 */
@Service
@RequiredArgsConstructor
public class UpdaterSelector {

    static final NoOpUpdater NO_OP_UPDATER = new NoOpUpdater();

    private final java.util.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 HashSet.ofAll(updaters).map(Updater::type);
    }


}

@@ -314,47 +314,8 @@
 er;%0A
-import lombok.RequiredArgsConstructor;%0A
 impo
@@ -357,16 +357,16 @@
 ervice;%0A
+
 import o
@@ -487,33 +487,8 @@
 ice%0A
-@RequiredArgsConstructor%0A
 publ
@@ -598,26 +598,16 @@
 e final 
-java.util.
 Set%3CUpda
@@ -619,22 +619,136 @@
 updaters
+;%0A%0A    public UpdaterSelector(java.util.Set%3CUpdater%3E updaters) %7B%0A        this.updaters = HashSet.ofAll(updaters)
 ;%0A    
+%7D%0A
 %0A    pub
@@ -897,34 +897,8 @@
 ers%0A
-                .stream()%0A
     
@@ -913,16 +913,18 @@
     .min
+By
 (Compara
@@ -994,17 +994,20 @@
        .
-o
+getO
 rElse(NO
@@ -1089,38 +1089,24 @@
  return 
-HashSet.ofAll(
 updaters
 ).map(Up
@@ -1097,17 +1097,16 @@
 updaters
-)
 .map(Upd

use javaslang.Set structure instead of simple java Set for types