Created
July 5, 2018 16:52
-
-
Save alexandreaquiles/07994eb3f979e308ba1ed1298d72ccf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum FormatoLivro { | |
PDF, | |
EPUB; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GeradorEPUB implements GeradorLivro { | |
@Override | |
public void gera(Livro livro) { | |
//gera epub... | |
} | |
@Override | |
public FormatoLivro formato() { | |
return FormatoLivro.EPUB; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface GeradorLivro { | |
void gera(Livro livro); | |
FormatoLivro formato(); | |
static GeradorLivro cria(FormatoLivro formato) { | |
Spliterator<GeradorLivro> spliterator = ServiceLoader.load(GeradorLivro.class).spliterator(); | |
return StreamSupport.stream(spliterador, false) | |
.filter(g -> g.formato().equals(formato)) | |
.findFirst() | |
.orElseThrow(() -> new RuntimeException("Não há gerador para o formato: " + formato)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GeradorPDF implements GeradorLivro { | |
@Override | |
public void gera(Livro livro) { | |
//gera pdf... | |
} | |
@Override | |
public FormatoLivro formato() { | |
return FormatoLivro.PDF; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment