1 package au.gov.amsa.navigation.ais; 2 3 import com.google.common.base.Optional; 4 import com.google.common.base.Preconditions; 5 6 public class Vessel { 7 8 private long mmsi; 9 private Optional<Integer> imo; 10 private Optional<Integer> shipType; 11 private Optional<Integer> dimensionA; 12 private Optional<Integer> dimensionB; 13 private Optional<Integer> dimensionC; 14 private Optional<Integer> dimensionD; 15 private Optional<Integer> lengthMetres; 16 private Optional<Integer> widthMetres; 17 private Optional<String> nmea; 18 19 private Vessel(long mmsi, Optional<Integer> imo, 20 Optional<Integer> shipType, Optional<Integer> dimensionA, 21 Optional<Integer> dimensionB, Optional<Integer> dimensionC, 22 Optional<Integer> dimensionD, Optional<Integer> lengthMetres, 23 Optional<Integer> widthMetres, Optional<String> nmea) { 24 Preconditions.checkNotNull(imo); 25 Preconditions.checkNotNull(shipType); 26 Preconditions.checkNotNull(dimensionA); 27 Preconditions.checkNotNull(dimensionB); 28 Preconditions.checkNotNull(dimensionC); 29 Preconditions.checkNotNull(dimensionD); 30 Preconditions.checkNotNull(lengthMetres); 31 Preconditions.checkNotNull(widthMetres); 32 Preconditions.checkNotNull(nmea); 33 this.mmsi = mmsi; 34 this.imo = imo; 35 this.shipType = shipType; 36 this.dimensionA = dimensionA; 37 this.dimensionB = dimensionB; 38 this.dimensionC = dimensionC; 39 this.dimensionD = dimensionD; 40 this.lengthMetres = lengthMetres; 41 this.widthMetres = widthMetres; 42 this.nmea = nmea; 43 } 44 45 public long getMmsi() { 46 return mmsi; 47 } 48 49 public Optional<Integer> getImo() { 50 return imo; 51 } 52 53 public Optional<Integer> getShipType() { 54 return shipType; 55 } 56 57 public Optional<Integer> getDimensionA() { 58 return dimensionA; 59 } 60 61 public Optional<Integer> getDimensionB() { 62 return dimensionB; 63 } 64 65 public Optional<Integer> getDimensionC() { 66 return dimensionC; 67 } 68 69 public Optional<Integer> getDimensionD() { 70 return dimensionD; 71 } 72 73 public Optional<Integer> getLengthMetres() { 74 return lengthMetres; 75 } 76 77 public Optional<Integer> getWidthMetres() { 78 return widthMetres; 79 } 80 81 public Optional<String> getNmea() { 82 return nmea; 83 } 84 85 public static Builder builder() { 86 return new Builder(); 87 } 88 89 public static Builder from(Vessel v) { 90 return builder().mmsi(v.mmsi).imo(v.imo).shipType(v.shipType) 91 .dimensionA(v.dimensionA).dimensionB(v.dimensionB) 92 .dimensionC(v.dimensionC).dimensionD(v.dimensionD) 93 .lengthMetres(v.lengthMetres).widthMetres(v.widthMetres) 94 .nmea(v.nmea); 95 } 96 97 public static class Builder { 98 99 private long mmsi; 100 private Optional<Integer> imo = Optional.absent(); 101 private Optional<Integer> shipType = Optional.absent(); 102 private Optional<Integer> dimensionA = Optional.absent(); 103 private Optional<Integer> dimensionB = Optional.absent(); 104 private Optional<Integer> dimensionC = Optional.absent(); 105 private Optional<Integer> dimensionD = Optional.absent(); 106 private Optional<Integer> lengthMetres = Optional.absent(); 107 private Optional<Integer> widthMetres = Optional.absent(); 108 private Optional<String> nmea = Optional.absent(); 109 110 private Builder() { 111 } 112 113 public Builder mmsi(long mmsi) { 114 this.mmsi = mmsi; 115 return this; 116 } 117 118 public Builder imo(Optional<Integer> imo) { 119 this.imo = imo; 120 return this; 121 } 122 123 public Builder shipType(Optional<Integer> shipType) { 124 this.shipType = shipType; 125 return this; 126 } 127 128 public Builder dimensionA(Optional<Integer> dimensionA) { 129 this.dimensionA = dimensionA; 130 return this; 131 } 132 133 public Builder dimensionB(Optional<Integer> dimensionB) { 134 this.dimensionB = dimensionB; 135 return this; 136 } 137 138 public Builder dimensionC(Optional<Integer> dimensionC) { 139 this.dimensionC = dimensionC; 140 return this; 141 } 142 143 public Builder dimensionD(Optional<Integer> dimensionD) { 144 this.dimensionD = dimensionD; 145 return this; 146 } 147 148 public Builder lengthMetres(Optional<Integer> lengthMetres) { 149 this.lengthMetres = lengthMetres; 150 return this; 151 } 152 153 public Builder widthMetres(Optional<Integer> widthMetres) { 154 this.widthMetres = widthMetres; 155 return this; 156 } 157 158 public Builder nmea(Optional<String> nmea) { 159 this.nmea = nmea; 160 return this; 161 } 162 163 public Vessel build() { 164 return new Vessel(mmsi, imo, shipType, dimensionA, dimensionB, 165 dimensionC, dimensionD, lengthMetres, widthMetres, nmea); 166 } 167 168 } 169 170 @Override 171 public String toString() { 172 StringBuilder b = new StringBuilder(); 173 b.append("Vessel [mmsi="); 174 b.append(mmsi); 175 b.append(", imo="); 176 b.append(imo); 177 b.append(", shipType="); 178 b.append(shipType); 179 b.append(", dimensionA="); 180 b.append(dimensionA); 181 b.append(", dimensionB="); 182 b.append(dimensionB); 183 b.append(", dimensionC="); 184 b.append(dimensionC); 185 b.append(", dimensionD="); 186 b.append(dimensionD); 187 b.append(", lengthMetres="); 188 b.append(lengthMetres); 189 b.append(", widthMetres="); 190 b.append(widthMetres); 191 b.append(", nmea="); 192 b.append(nmea); 193 b.append("]"); 194 return b.toString(); 195 } 196 197 198 }