1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package fulmine;
17
18 import static fulmine.util.Utils.COLON;
19 import static fulmine.util.Utils.nullCheck;
20 import static fulmine.util.Utils.string;
21
22 import org.apache.commons.lang.builder.HashCodeBuilder;
23
24 import fulmine.util.reference.is;
25
26
27
28
29
30
31 public class Addressable implements IAddressable
32 {
33
34 private final IType type;
35
36
37 private final IDomain domain;
38
39
40 private final String identity;
41
42
43 private final int hashCode;
44
45
46 private final String address;
47
48
49
50
51
52
53
54 public Addressable(IAddressable id)
55 {
56 this(id.getIdentity(), id.getType(), id.getDomain());
57 }
58
59
60
61
62
63
64
65
66
67
68
69 public Addressable(String identity, IType type, IDomain domain)
70 {
71 super();
72 nullCheck(identity, "No identity");
73 this.type = type;
74 this.domain = domain;
75 this.identity = identity;
76 this.hashCode =
77 new HashCodeBuilder().append(getIdentity()).append(getType()).append(
78 getDomain()).toHashCode();
79 this.address = getIdentity() + COLON + getType() + COLON + getDomain();
80 }
81
82 public final IType getType()
83 {
84 return this.type;
85 }
86
87 public final IDomain getDomain()
88 {
89 return this.domain;
90 }
91
92 public final String getIdentity()
93 {
94 return this.identity;
95 }
96
97 @Override
98 public final String toString()
99 {
100 return string(this, getAddress());
101 }
102
103 @Override
104 public int hashCode()
105 {
106 return this.hashCode;
107 }
108
109 @Override
110 public boolean equals(Object obj)
111 {
112 if (is.same(this, obj))
113 {
114 return true;
115 }
116 if (obj == null)
117 {
118 return false;
119 }
120 if (!(obj instanceof IAddressable))
121 {
122 return false;
123 }
124 final IAddressable other = (IAddressable) obj;
125 return is.eq(getAddress(), other.getAddress());
126 }
127
128 public String getAddress()
129 {
130 return this.address;
131 }
132 }