-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path6-11-main.java
39 lines (34 loc) Β· 1.08 KB
/
6-11-main.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
/**
* p220 μμ (λμνμ§ μλ μ½λ)
*/
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 {
return countOrders(parseCommandLine(args));
}
private static CommandLine parseCommandLine(String[] args) {
if (args.length == 0) throw new RuntimeException("νμΌλͺ
μ μ
λ ₯νμΈμ.");
CommandLine result = new CommandLine();
result.filename = args[args.length - 1];
result.onlyCountReady = Stream.of(args).anyMatch(arg -> "-r".equals(arg));
return result;
}
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 static class CommandLine {
boolean onlyCountReady;
String filename;
}