|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+package se.citerus.dddsample.tracking.core.domain.model.handling;
|
|
|
2
|
+
|
|
|
3
|
+import se.citerus.dddsample.tracking.core.domain.shared.ValueObject;
|
|
|
4
|
+
|
|
|
5
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
6
|
+
|
|
|
7
|
+public class EventSequenceNumber implements ValueObject<EventSequenceNumber> {
|
|
|
8
|
+
|
|
|
9
|
+ private long value;
|
|
|
10
|
+ private static final AtomicLong SEQUENCE = new AtomicLong(System.currentTimeMillis());
|
|
|
11
|
+
|
|
|
12
|
+ private EventSequenceNumber(final long value) {
|
|
|
13
|
+ this.value = value;
|
|
|
14
|
+ }
|
|
|
15
|
+
|
|
|
16
|
+ public static EventSequenceNumber next() {
|
|
|
17
|
+ return new EventSequenceNumber(SEQUENCE.getAndIncrement());
|
|
|
18
|
+ }
|
|
|
19
|
+
|
|
|
20
|
+ public long longValue() {
|
|
|
21
|
+ return value;
|
|
|
22
|
+ }
|
|
|
23
|
+
|
|
|
24
|
+ @Override
|
|
|
25
|
+ public boolean sameValueAs(final EventSequenceNumber other) {
|
|
|
26
|
+ return false;
|
|
|
27
|
+ }
|
|
|
28
|
+
|
|
|
29
|
+ @Override
|
|
|
30
|
+ public boolean equals(Object o) {
|
|
|
31
|
+ if (this == o) return true;
|
|
|
32
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
|
33
|
+
|
|
|
34
|
+ return sameValueAs((EventSequenceNumber) o);
|
|
|
35
|
+ }
|
|
|
36
|
+
|
|
|
37
|
+ @Override
|
|
|
38
|
+ public int hashCode() {
|
|
|
39
|
+ return Long.valueOf(value).hashCode();
|
|
|
40
|
+ }
|
|
|
41
|
+
|
|
|
42
|
+ @Override
|
|
|
43
|
+ public String toString() {
|
|
|
44
|
+ return String.valueOf(value);
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ EventSequenceNumber() {
|
|
|
48
|
+ // Needed by Hibernate
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+}
|