-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelloWorld.java
31 lines (26 loc) · 1.03 KB
/
HelloWorld.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.List;
import java.util.Arrays;
import java.util.stream.Collectors;
public class HelloWorld {
public static void main(String[] args) {
// prepare printing contents
PrintableFactory printableFactory = new PrintableFactory();
List<PrintableType> types = Arrays.asList(
PrintableType.HELLO, PrintableType.COMMA, PrintableType.SPACE,
PrintableType.WORLD, PrintableType.EXCLAMATION_MARK, PrintableType.NEWLINE );
List<Printable> contents = types.stream()
.map(t -> printableFactory.getPrintable(t))
.collect(Collectors.toList());
// add jobs to printer
Printer printer = new PrinterFactory().getPrinter();
for(Printable p : contents) {
if (p instanceof Word) {
printer.addJob(new PrintWordCommand(p));
} else if (p instanceof Char){
printer.addJob(new PrintCharCommand(p));
}
}
// print all the jobs
printer.processAllJobs();
}
}