1 package se.citerus.dddsample.domain.model.location;
2
3 import org.apache.commons.lang.Validate;
4 import se.citerus.dddsample.domain.shared.Entity;
5
6
7
8
9
10
11
12
13 public final class Location implements Entity<Location> {
14
15 private UnLocode unLocode;
16 private String name;
17
18
19
20
21 public static final Location UNKNOWN = new Location(
22 new UnLocode("XXXXX"), "Unknown location"
23 );
24
25
26
27
28
29
30
31
32 Location(final UnLocode unLocode, final String name) {
33 Validate.notNull(unLocode);
34 Validate.notNull(name);
35
36 this.unLocode = unLocode;
37 this.name = name;
38 }
39
40
41
42
43 public UnLocode unLocode() {
44 return unLocode;
45 }
46
47
48
49
50 public String name() {
51 return name;
52 }
53
54
55
56
57
58 @Override
59 public boolean equals(final Object object) {
60 if (object == null) {
61 return false;
62 }
63 if (this == object) {
64 return true;
65 }
66 if (!(object instanceof Location)) {
67 return false;
68 }
69 Location other = (Location) object;
70 return sameIdentityAs(other);
71 }
72
73 @Override
74 public boolean sameIdentityAs(final Location other) {
75 return this.unLocode.sameValueAs(other.unLocode);
76 }
77
78
79
80
81 @Override
82 public int hashCode() {
83 return unLocode.hashCode();
84 }
85
86 @Override
87 public String toString() {
88 return name + " [" + unLocode + "]";
89 }
90
91 Location() {
92
93 }
94
95 private Long id;
96
97 }