|
|
@@ -108,11 +108,22 @@ public class Cargo {
|
|
108
|
108
|
}
|
|
109
|
109
|
|
|
110
|
110
|
/**
|
|
111
|
|
- * @return True if the cargo has been misdirected,
|
|
112
|
|
- * that is if the cargo is in a location that's not in the itinerary.
|
|
|
111
|
+ * Check if cargo is misdirected.
|
|
|
112
|
+ * <p/>
|
|
|
113
|
+ * <ul>
|
|
|
114
|
+ * <li>A cargo is misdirected if it is in a location that's not in the itinerary.
|
|
|
115
|
+ * <li>A cargo with no itinerary can not be misdirected.
|
|
|
116
|
+ * <li>A cargo that has received no handling events can not be misdirected.
|
|
|
117
|
+ * </ul>
|
|
|
118
|
+ *
|
|
|
119
|
+ * @return <code>true</code> if the cargo has been misdirected,
|
|
113
|
120
|
*/
|
|
114
|
121
|
public boolean isMisdirected() {
|
|
115
|
|
- return itinerary != null && !itinerary.isExpected(deliveryHistory.lastEvent());
|
|
|
122
|
+ final HandlingEvent lastEvent = deliveryHistory.lastEvent();
|
|
|
123
|
+ if (itinerary == null || lastEvent == null)
|
|
|
124
|
+ return false;
|
|
|
125
|
+
|
|
|
126
|
+ return !itinerary.isExpected(lastEvent);
|
|
116
|
127
|
}
|
|
117
|
128
|
|
|
118
|
129
|
public Itinerary itinerary() {
|
|
|
@@ -127,12 +138,12 @@ public class Cargo {
|
|
127
|
138
|
/**
|
|
128
|
139
|
* Entities compare by identity, therefore the trackingId field is the only basis of comparison. For persistence we
|
|
129
|
140
|
* have an id field, but it is not used for identiy comparison.
|
|
130
|
|
- *
|
|
|
141
|
+ * <p/>
|
|
131
|
142
|
* Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
|
|
132
|
143
|
*
|
|
133
|
144
|
* @param other The other cargo.
|
|
134
|
145
|
* @return <code>true</code> if the given cargo's and this cargos's trackingId is the same, regardles of other
|
|
135
|
|
- * attributes.
|
|
|
146
|
+ * attributes.
|
|
136
|
147
|
*/
|
|
137
|
148
|
private boolean sameIdentityAs(Cargo other) {
|
|
138
|
149
|
return trackingId.equals(other.trackingId);
|