|
|
@@ -1,7 +1,5 @@
|
|
1
|
1
|
package se.citerus.dddsample.domain;
|
|
2
|
2
|
|
|
3
|
|
-import org.apache.commons.lang.builder.HashCodeBuilder;
|
|
4
|
|
-
|
|
5
|
3
|
import javax.persistence.*;
|
|
6
|
4
|
import java.util.Comparator;
|
|
7
|
5
|
import java.util.Date;
|
|
|
@@ -80,9 +78,9 @@ public class HandlingEvent {
|
|
80
|
78
|
* Constructor for events that do not have a carrier movement associated.
|
|
81
|
79
|
*
|
|
82
|
80
|
* @param cargo cargo
|
|
83
|
|
- * @param completionTime completion time
|
|
84
|
|
- * @param registrationTime registration time
|
|
85
|
|
- * @param type type of event. Legal values are CLAIM, RECIEVE and CUSTOMS
|
|
|
81
|
+ * @param completionTime completion time, the reported time that the event actually happened (e.g. the receive took place).
|
|
|
82
|
+ * @param registrationTime registration time, the time the message is received
|
|
|
83
|
+ * @param type type of event. Legal values are CLAIM, RECEIVE and CUSTOMS
|
|
86
|
84
|
* @param location where the event took place
|
|
87
|
85
|
*/
|
|
88
|
86
|
public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type, Location location) {
|
|
|
@@ -102,8 +100,8 @@ public class HandlingEvent {
|
|
102
|
100
|
* is the end point.
|
|
103
|
101
|
*
|
|
104
|
102
|
* @param cargo cargo
|
|
105
|
|
- * @param completionTime completion time
|
|
106
|
|
- * @param registrationTime registration time
|
|
|
103
|
+ * @param completionTime completion time, the reported time that the event actually happened (e.g. the receive took place).
|
|
|
104
|
+ * @param registrationTime registration time, the time the message is received
|
|
107
|
105
|
* @param type type of event. Legal values are LOAD and UNLOAD
|
|
108
|
106
|
* @param location where the event took place
|
|
109
|
107
|
* @param carrierMovement carrier movement.
|
|
|
@@ -116,7 +114,6 @@ public class HandlingEvent {
|
|
116
|
114
|
this.location = location;
|
|
117
|
115
|
this.carrierMovement = carrierMovement;
|
|
118
|
116
|
|
|
119
|
|
-
|
|
120
|
117
|
validateType();
|
|
121
|
118
|
}
|
|
122
|
119
|
|
|
|
@@ -149,42 +146,46 @@ public class HandlingEvent {
|
|
149
|
146
|
return this.cargo;
|
|
150
|
147
|
}
|
|
151
|
148
|
|
|
|
149
|
+ public boolean equals(Object o) {
|
|
|
150
|
+ if (this == o) return true;
|
|
|
151
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
|
152
|
+
|
|
|
153
|
+ HandlingEvent event = (HandlingEvent) o;
|
|
|
154
|
+
|
|
|
155
|
+ return sameEventAs(event);
|
|
|
156
|
+ }
|
|
|
157
|
+
|
|
152
|
158
|
/**
|
|
153
|
|
- * @param object to compare
|
|
154
|
|
- * @return True if location, completion time and type are equal.
|
|
|
159
|
+ * Events compare by the attributes that identify the underlying event as opposed to the report of the event.
|
|
|
160
|
+ * Therefore the completion time is part of the comparison but not the registration time.
|
|
|
161
|
+ *
|
|
|
162
|
+ * Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
|
|
|
163
|
+ * Compare this behavior to the entity {@link se.citerus.dddsample.domain.Cargo#sameIdentityAs(Cargo)}
|
|
|
164
|
+ *
|
|
|
165
|
+ * @param other The other hanling event.
|
|
|
166
|
+ * @return <code>true</code> if the given handling event and this event are regarded as the same.
|
|
155
|
167
|
*/
|
|
156
|
|
- @Override
|
|
157
|
|
- public boolean equals(Object object) {
|
|
158
|
|
- if (object == null) {
|
|
|
168
|
+ public boolean sameEventAs(HandlingEvent other) {
|
|
|
169
|
+ if (cargo != null ? !cargo.equals(other.cargo) : other.cargo != null) return false;
|
|
|
170
|
+ if (carrierMovement != null ? !carrierMovement.equals(other.carrierMovement) : other.carrierMovement != null)
|
|
159
|
171
|
return false;
|
|
160
|
|
- }
|
|
161
|
|
- if (!(object instanceof HandlingEvent)) {
|
|
|
172
|
+ if (completionTime != null ? !completionTime.equals(other.completionTime) : other.completionTime != null)
|
|
162
|
173
|
return false;
|
|
163
|
|
- }
|
|
164
|
|
- HandlingEvent other = (HandlingEvent) object;
|
|
165
|
|
- return this.location.equals(other.location) &&
|
|
166
|
|
- this.completionTime.equals(other.completionTime) &&
|
|
167
|
|
- this.type.equals(other.type);
|
|
|
174
|
+ if (location != null ? !location.equals(other.location) : other.location != null) return false;
|
|
|
175
|
+ if (type != other.type) return false;
|
|
|
176
|
+
|
|
|
177
|
+ return true;
|
|
168
|
178
|
}
|
|
169
|
179
|
|
|
170
|
|
- /**
|
|
171
|
|
- * @return Hash code calculated from the same properties as equals().
|
|
172
|
|
- */
|
|
173
|
180
|
@Override
|
|
174
|
181
|
public int hashCode() {
|
|
175
|
|
- return new HashCodeBuilder(7, 39).
|
|
176
|
|
- append(this.location).
|
|
177
|
|
- append(this.completionTime).
|
|
178
|
|
- append(this.type).
|
|
179
|
|
- toHashCode();
|
|
180
|
|
- }
|
|
181
|
|
-
|
|
182
|
|
- /**
|
|
183
|
|
- * @param other to compare
|
|
184
|
|
- * @return True if the ids are equal.
|
|
185
|
|
- */
|
|
186
|
|
- public boolean sameIdentityAs(HandlingEvent other) {
|
|
187
|
|
- return other != null && id.equals(other.id);
|
|
|
182
|
+ int result;
|
|
|
183
|
+ result = (type != null ? type.hashCode() : 0);
|
|
|
184
|
+ result = 31 * result + (carrierMovement != null ? carrierMovement.hashCode() : 0);
|
|
|
185
|
+ result = 31 * result + (location != null ? location.hashCode() : 0);
|
|
|
186
|
+ result = 31 * result + (completionTime != null ? completionTime.hashCode() : 0);
|
|
|
187
|
+ result = 31 * result + (cargo != null ? cargo.hashCode() : 0);
|
|
|
188
|
+ return result;
|
|
188
|
189
|
}
|
|
189
|
190
|
|
|
190
|
191
|
/**
|