|
|
@@ -2,16 +2,17 @@ package se.citerus.dddsample.tracking.core.domain.model.cargo;
|
|
2
|
2
|
|
|
3
|
3
|
import org.apache.commons.lang.StringUtils;
|
|
4
|
4
|
import org.apache.commons.lang.Validate;
|
|
5
|
|
-import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
|
|
6
|
5
|
import se.citerus.dddsample.tracking.core.domain.model.location.Location;
|
|
7
|
6
|
import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
|
|
8
|
|
-import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.claimIn;
|
|
9
|
|
-import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.receiveIn;
|
|
10
|
7
|
import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
|
|
11
|
8
|
import se.citerus.dddsample.tracking.core.domain.patterns.valueobject.ValueObjectSupport;
|
|
12
|
9
|
|
|
13
|
10
|
import java.util.*;
|
|
14
|
11
|
|
|
|
12
|
+import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
|
|
|
13
|
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.claimIn;
|
|
|
14
|
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.receiveIn;
|
|
|
15
|
+
|
|
15
|
16
|
/**
|
|
16
|
17
|
* An itinerary.
|
|
17
|
18
|
*/
|
|
|
@@ -93,7 +94,7 @@ public class Itinerary extends ValueObjectSupport<Itinerary> {
|
|
93
|
94
|
* @return <code>true</code> if the event is expected
|
|
94
|
95
|
*/
|
|
95
|
96
|
boolean isExpectedActivity(final HandlingActivity handlingActivity) {
|
|
96
|
|
- return legMatchOf(handlingActivity).leg() != null;
|
|
|
97
|
+ return matchLeg(handlingActivity).leg() != null;
|
|
97
|
98
|
}
|
|
98
|
99
|
|
|
99
|
100
|
/**
|
|
|
@@ -172,7 +173,7 @@ public class Itinerary extends ValueObjectSupport<Itinerary> {
|
|
172
|
173
|
if (previousActivity == null) {
|
|
173
|
174
|
return receiveIn(firstLeg().loadLocation());
|
|
174
|
175
|
} else {
|
|
175
|
|
- return deriveFromMatchingLeg(previousActivity, legMatchOf(previousActivity).leg());
|
|
|
176
|
+ return deriveFromMatchingLeg(previousActivity, matchLeg(previousActivity).leg());
|
|
176
|
177
|
}
|
|
177
|
178
|
}
|
|
178
|
179
|
|
|
|
@@ -182,8 +183,8 @@ public class Itinerary extends ValueObjectSupport<Itinerary> {
|
|
182
|
183
|
* @return The activity which is strictly prior to the other, according to the itinerary, or null if neither is strictly prior.
|
|
183
|
184
|
*/
|
|
184
|
185
|
HandlingActivity strictlyPriorOf(final HandlingActivity handlingActivity1, final HandlingActivity handlingActivity2) {
|
|
185
|
|
- final LegMatch match1 = legMatchOf(handlingActivity1);
|
|
186
|
|
- final LegMatch match2 = legMatchOf(handlingActivity2);
|
|
|
186
|
+ final LegActivityMatch match1 = matchLeg(handlingActivity1);
|
|
|
187
|
+ final LegActivityMatch match2 = matchLeg(handlingActivity2);
|
|
187
|
188
|
final int compared = match1.compareTo(match2);
|
|
188
|
189
|
|
|
189
|
190
|
if (compared < 0) {
|
|
|
@@ -213,13 +214,13 @@ public class Itinerary extends ValueObjectSupport<Itinerary> {
|
|
213
|
214
|
* @param handlingActivity handling activity
|
|
214
|
215
|
* @return The leg match of this handling activity. Never null.
|
|
215
|
216
|
*/
|
|
216
|
|
- LegMatch legMatchOf(final HandlingActivity handlingActivity) {
|
|
|
217
|
+ LegActivityMatch matchLeg(final HandlingActivity handlingActivity) {
|
|
217
|
218
|
if (handlingActivity == null) {
|
|
218
|
|
- return LegMatch.noMatch(handlingActivity, this);
|
|
|
219
|
+ return LegActivityMatch.noMatch(handlingActivity, this);
|
|
219
|
220
|
} else if (handlingActivity.type() == RECEIVE) {
|
|
220
|
|
- return LegMatch.ifLoadLocationSame(firstLeg(), handlingActivity, this);
|
|
|
221
|
+ return LegActivityMatch.ifLoadLocationSame(firstLeg(), handlingActivity, this);
|
|
221
|
222
|
} else if (handlingActivity.type() == CLAIM) {
|
|
222
|
|
- return LegMatch.ifUnloadLocationSame(lastLeg(), handlingActivity, this);
|
|
|
223
|
+ return LegActivityMatch.ifUnloadLocationSame(lastLeg(), handlingActivity, this);
|
|
223
|
224
|
} else {
|
|
224
|
225
|
return findLegMatchingActivity(handlingActivity);
|
|
225
|
226
|
}
|
|
|
@@ -239,14 +240,14 @@ public class Itinerary extends ValueObjectSupport<Itinerary> {
|
|
239
|
240
|
return legs.get(legs.size() - 1);
|
|
240
|
241
|
}
|
|
241
|
242
|
|
|
242
|
|
- private LegMatch findLegMatchingActivity(final HandlingActivity handlingActivity) {
|
|
|
243
|
+ private LegActivityMatch findLegMatchingActivity(final HandlingActivity handlingActivity) {
|
|
243
|
244
|
for (Leg leg : legs) {
|
|
244
|
245
|
if (leg.matchesActivity(handlingActivity)) {
|
|
245
|
|
- return LegMatch.match(leg, handlingActivity, this);
|
|
|
246
|
+ return LegActivityMatch.match(leg, handlingActivity, this);
|
|
246
|
247
|
}
|
|
247
|
248
|
}
|
|
248
|
249
|
|
|
249
|
|
- return LegMatch.noMatch(handlingActivity, this);
|
|
|
250
|
+ return LegActivityMatch.noMatch(handlingActivity, this);
|
|
250
|
251
|
}
|
|
251
|
252
|
|
|
252
|
253
|
private HandlingActivity deriveFromMatchingLeg(final HandlingActivity handlingActivity, final Leg matchingLeg) {
|