1 package se.citerus.dddsample.domain.model.cargo;
2
3 import org.apache.commons.lang.Validate;
4 import org.apache.commons.lang.builder.EqualsBuilder;
5 import org.apache.commons.lang.builder.HashCodeBuilder;
6 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7 import se.citerus.dddsample.domain.model.location.Location;
8 import se.citerus.dddsample.domain.model.voyage.Voyage;
9 import se.citerus.dddsample.domain.shared.ValueObject;
10
11
12
13
14
15
16
17 public class HandlingActivity implements ValueObject<HandlingActivity> {
18
19
20
21 private HandlingEvent.Type type;
22 private Location location;
23 private Voyage voyage;
24
25 public HandlingActivity(final HandlingEvent.Type type, final Location location) {
26 Validate.notNull(type, "Handling event type is required");
27 Validate.notNull(location, "Location is required");
28
29 this.type = type;
30 this.location = location;
31 }
32
33 public HandlingActivity(final HandlingEvent.Type type, final Location location, final Voyage voyage) {
34 Validate.notNull(type, "Handling event type is required");
35 Validate.notNull(location, "Location is required");
36 Validate.notNull(location, "Voyage is required");
37
38 this.type = type;
39 this.location = location;
40 this.voyage = voyage;
41 }
42
43 public HandlingEvent.Type type() {
44 return type;
45 }
46
47 public Location location() {
48 return location;
49 }
50
51 public Voyage voyage() {
52 return voyage;
53 }
54
55 @Override
56 public boolean sameValueAs(final HandlingActivity other) {
57 return other != null && new EqualsBuilder().
58 append(this.type, other.type).
59 append(this.location, other.location).
60 append(this.voyage, other.voyage).
61 isEquals();
62 }
63
64 @Override
65 public int hashCode() {
66 return new HashCodeBuilder().
67 append(this.type).
68 append(this.location).
69 append(this.voyage).
70 toHashCode();
71 }
72
73 @Override
74 public boolean equals(final Object obj) {
75 if (obj == this) return true;
76 if (obj == null) return false;
77 if (obj.getClass() != this.getClass()) return false;
78
79 HandlingActivity other = (HandlingActivity) obj;
80
81 return sameValueAs(other);
82 }
83
84 HandlingActivity() {
85
86 }
87
88 }