|
@ -0,0 +1,47 @@ |
|
|
|
|
|
package com.cristobalbernal.loladvisor.service; |
|
|
|
|
|
|
|
|
|
|
|
import com.cristobalbernal.loladvisor.dao.LolDao; |
|
|
|
|
|
import com.cristobalbernal.loladvisor.model.Lol; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.function.Predicate; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
|
|
public class LolQueryServices implements LolQueryService { |
|
|
|
|
|
|
|
|
|
|
|
private LolDao dao; |
|
|
|
|
|
|
|
|
|
|
|
private Predicate<Lol> predicate; |
|
|
|
|
|
|
|
|
|
|
|
public void init(){ |
|
|
|
|
|
predicate = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public LolQueryService exec() { |
|
|
|
|
|
return (LolQueryService) dao.findAll() |
|
|
|
|
|
.stream() |
|
|
|
|
|
.filter(predicate) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public LolQueryService anyDificultad(String... dificultad) { |
|
|
|
|
|
Predicate<Lol> lolPredicate = (lol -> Arrays.stream(dificultad).anyMatch(lol.getNombre()::contains)); |
|
|
|
|
|
predicate = (predicate == null) ? lolPredicate : predicate.and(lolPredicate); |
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public LolQueryService anyRol(String... rol) { |
|
|
|
|
|
Predicate<Lol> pAllGenres = (lol -> Arrays.stream(rol).allMatch(lol.getRol()::contains)); |
|
|
|
|
|
predicate = (predicate == null) ? pAllGenres : predicate.and(pAllGenres); |
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
} |