-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path6-11-main2.java
46 lines (38 loc) Β· 1.09 KB
/
6-11-main2.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* p228 μμ (λμνμ§ μλ μ½λ)
*/
public static void main(String[] args) {
try {
System.out.println(run(args));
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
static void run(String[] args) throws IOException {
CommandLine commandLine = new CommandLine();
return countOrders(commandLine);
}
private static
private static long countOrders(CommandLine commandLine) throws IOException {
File input = Paths.get(commandLine.filename()).toFile();
ObjectMapper mapper = new ObjectMapper();
Order[] orders = mapper.readValue(input, Order[].class);
if(commandLine.onlyCountReady())
return Stream.of(orders).filter(o -> "ready".equals(o.status)).count();
else
return orders.length;
}
private class CommandLine {
String[] args;
public CommandLine(String[] args) {
this.args = args;
if (args.length == 0) throw new RuntimeException("νμΌλͺ
μ μ
λ ₯νμΈμ.");
}
String filename() {
return args[args.length - 1];
}
boolean onlyCountReady() {
return Stream.of(args).anyMatch(arg -> "-r".equals(arg));
}
}