1 package au.gov.amsa.geo.model;
2
3 import java.util.concurrent.TimeUnit;
4
5 public class SegmentOptions {
6 private final Long acceptAnyFixAfterHours;
7 private final double speedCheckDistanceThresholdNm;
8 private final long speedCheckMinTimeDiffMs;
9 private final double maxSpeedKnots;
10 private final Double maxDistancePerSegmentNm;
11
12 @Override
13 public String toString() {
14 StringBuilder b = new StringBuilder();
15 b.append("SegmentOptions [acceptAnyFixAfterHours=");
16 b.append(acceptAnyFixAfterHours);
17 b.append(", speedCheckDistanceThresholdNm=");
18 b.append(speedCheckDistanceThresholdNm);
19 b.append(", speedCheckMinTimeDiffMs=");
20 b.append(speedCheckMinTimeDiffMs);
21 b.append(", maxSpeedKnots=");
22 b.append(maxSpeedKnots);
23 b.append(", maxDistancePerSegmentNm=");
24 b.append(maxDistancePerSegmentNm);
25 b.append(", maxTimePerSegmentHours=");
26 b.append((double) maxTimePerSegmentMs / TimeUnit.HOURS.toMillis(1));
27 b.append("]");
28 return b.toString();
29 }
30
31 private final Long maxTimePerSegmentMs;
32
33 private SegmentOptions(Long acceptAnyFixAfterHours, double speedCheckDistanceThresholdNm,
34 long speedCheckMinTimeDiffMs, double maxSpeedKnots, Double maxDistancePerSegmentNm,
35 Long maxTimePerSegmentMs) {
36 this.acceptAnyFixAfterHours = acceptAnyFixAfterHours;
37 this.speedCheckDistanceThresholdNm = speedCheckDistanceThresholdNm;
38 this.speedCheckMinTimeDiffMs = speedCheckMinTimeDiffMs;
39 this.maxSpeedKnots = maxSpeedKnots;
40 this.maxDistancePerSegmentNm = maxDistancePerSegmentNm;
41 this.maxTimePerSegmentMs = maxTimePerSegmentMs;
42 }
43
44 public Long acceptAnyFixAfterHours() {
45 return acceptAnyFixAfterHours;
46 }
47
48 public double speedCheckDistanceThresholdNm() {
49 return speedCheckDistanceThresholdNm;
50 }
51
52 public long speedCheckMinTimeDiffMs() {
53 return speedCheckMinTimeDiffMs;
54 }
55
56 public double maxSpeedKnots() {
57 return maxSpeedKnots;
58 }
59
60 public Double maxDistancePerSegmentNm() {
61 return maxDistancePerSegmentNm;
62 }
63
64 public Long maxTimePerSegmentMs() {
65 return maxTimePerSegmentMs;
66 }
67
68 public static Builder builder() {
69 return new Builder();
70 }
71
72 public static SegmentOptions getDefault() {
73 return SegmentOptions.builder().build();
74 }
75
76 public static class Builder {
77
78 private Long acceptAnyFixHours = null;
79 private double speedCheckDistanceThresholdNm = 30;
80 private long speedCheckMinTimeDiffMs = 180000;
81 private double maxSpeedKnots = 50;
82 private Double maxDistancePerSegmentNm = null;
83 private Long maxTimePerSegmentMs = TimeUnit.DAYS.toMillis(1);
84
85 private Builder() {
86 }
87
88 public Builder acceptAnyFixHours(Long acceptAnyFixHours) {
89 this.acceptAnyFixHours = acceptAnyFixHours;
90 return this;
91 }
92
93 public Builder speedCheckDistanceThresholdNm(double speedCheckDistanceThresholdNm) {
94 this.speedCheckDistanceThresholdNm = speedCheckDistanceThresholdNm;
95 return this;
96 }
97
98 public Builder speedCheckMinTimeDiffMs(long speedCheckMinTimeDiffMs) {
99 this.speedCheckMinTimeDiffMs = speedCheckMinTimeDiffMs;
100 return this;
101 }
102
103 public Builder speedCheckMinTimeDiff(long duration, TimeUnit unit) {
104 return speedCheckMinTimeDiffMs(unit.toMillis(duration));
105 }
106
107 public Builder maxSpeedKnots(double maxSpeedKnots) {
108 this.maxSpeedKnots = maxSpeedKnots;
109 return this;
110 }
111
112 public Builder maxDistancePerSegmentNm(Double maxDistancePerSegmentNm) {
113 this.maxDistancePerSegmentNm = maxDistancePerSegmentNm;
114 return this;
115 }
116
117 public Builder maxTimePerSegmentMs(Long maxTimePerSegmentMs) {
118 this.maxTimePerSegmentMs = maxTimePerSegmentMs;
119 return this;
120 }
121
122 public Builder maxTimePerSegment(long duration, TimeUnit unit) {
123 return maxTimePerSegmentMs(unit.toMillis(duration));
124 }
125
126 public SegmentOptions build() {
127 return new SegmentOptions(acceptAnyFixHours, speedCheckDistanceThresholdNm,
128 speedCheckMinTimeDiffMs, maxSpeedKnots, maxDistancePerSegmentNm,
129 maxTimePerSegmentMs);
130 }
131 }
132 }