1 package au.gov.amsa.ais.message;
2
3 import com.google.common.base.Optional;
4
5
6 public final class AisShipStaticUtil {
7
8 public static Optional<Integer> lengthMetres(Optional<Integer> a, Optional<Integer> b,
9 Optional<Integer> c, Optional<Integer> d) {
10 if (a.isPresent() && b.isPresent())
11 return Optional.of(a.get() + b.get());
12 else {
13 if (!a.isPresent() && !c.isPresent() && b.isPresent() && d.isPresent())
14 return b;
15 else
16 return Optional.absent();
17 }
18 }
19
20 public static Optional<Integer> lengthMetres(AisShipStatic m) {
21 return lengthMetres(m.getDimensionA(), m.getDimensionB(), m.getDimensionC(),
22 m.getDimensionD());
23 }
24
25 public static Optional<Integer> widthMetres(Optional<Integer> a, Optional<Integer> b,
26 Optional<Integer> c, Optional<Integer> d) {
27 if (c.isPresent() && d.isPresent())
28 return Optional.of(c.get() + d.get());
29 else {
30 if (!a.isPresent() && !c.isPresent() && b.isPresent() && d.isPresent())
31 return d;
32 else
33 return Optional.absent();
34 }
35 }
36
37 public static Optional<Integer> widthMetres(AisShipStatic m) {
38 return widthMetres(m.getDimensionA(), m.getDimensionB(), m.getDimensionC(),
39 m.getDimensionD());
40 }
41 }