1 package au.gov.amsa.ihs.reader;
2
3 import java.io.File;
4
5 public class IhsReaderMain {
6
7
8
9 private static final String GROSS_TONNAGE = "GrossTonnage";
10
11 public static void main(String[] args) {
12 File file = new File("/media/an/ship-data/ihs/608750-2015-04-01.zip");
13
14
15
16 IhsReader.fromZip(file)
17 .groupBy(map -> {
18 String name = map.get("FlagName");
19 if (name == null)
20 name = "UNKNOWN";
21 return name;
22 })
23 .flatMap(g -> g
24 .groupBy(map -> map.containsKey(GROSS_TONNAGE))
25 .flatMap(g2 -> g2.reduce(0L,
26 (total, map) -> map.get(GROSS_TONNAGE) != null
27 ? total + Long.parseLong(map.get(GROSS_TONNAGE)) : total)
28 .map(x -> g.getKey() + "\t" + x)))
29 .doOnNext(System.out::println)
30 .subscribe();
31
32 IhsReader.fromZip(file)
33 .groupBy(map -> {
34 String name = map.get("FlagName");
35 if (name == null)
36 name = "UNKNOWN";
37 return name;
38 })
39 .flatMap(
40 g -> g
41 .groupBy(map -> map.containsKey(GROSS_TONNAGE))
42 .flatMap(g2 -> g2
43 .reduce(0L,
44 (total, map) -> map.get(GROSS_TONNAGE) != null
45 ? total + 1 : total)
46 .map(x -> g.getKey() + "\t" + x)))
47 .doOnNext(System.out::println)
48 .subscribe();
49
50
51
52
53
54
55
56
57
58
59 }
60 }