1 package org.djutils.event;
2
3 import java.io.Serializable;
4
5 import org.djutils.exceptions.Throw;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class TimedEvent<T extends Comparable<T> & Serializable> extends Event implements Comparable<TimedEvent<T>>
24 {
25
26 private static final long serialVersionUID = 20140826L;
27
28
29 private final T timeStamp;
30
31
32
33
34
35
36
37 public TimedEvent(final EventType type, final Serializable content, final T timeStamp)
38 {
39 this(type, content, timeStamp, true);
40 }
41
42
43
44
45
46
47
48
49 public TimedEvent(final EventType type, final Serializable content, final T timeStamp, final boolean verifyMetaData)
50 {
51 super(type, content, verifyMetaData);
52 Throw.whenNull(timeStamp, "timeStamp cannot be null");
53 this.timeStamp = timeStamp;
54 }
55
56
57
58
59
60 public T getTimeStamp()
61 {
62 return this.timeStamp;
63 }
64
65 @Override
66 public int hashCode()
67 {
68 final int prime = 31;
69 int result = super.hashCode();
70 result = prime * result + ((this.timeStamp == null) ? 0 : this.timeStamp.hashCode());
71 return result;
72 }
73
74 @Override
75 @SuppressWarnings("checkstyle:needbraces")
76 public boolean equals(final Object obj)
77 {
78 if (this == obj)
79 return true;
80 if (!super.equals(obj))
81 return false;
82 TimedEvent<?> other = (TimedEvent<?>) obj;
83 if (this.timeStamp == null)
84 {
85 if (other.timeStamp != null)
86 return false;
87 }
88 else if (!this.timeStamp.equals(other.timeStamp))
89 return false;
90 return true;
91 }
92
93 @Override
94 public int compareTo(final TimedEvent<T> o)
95 {
96 return this.timeStamp.compareTo(o.getTimeStamp());
97 }
98
99 @Override
100 public String toString()
101 {
102 return "[" + this.getClass().getName() + ";" + this.getType() + ";" + this.getContent() + ";" + this.getTimeStamp()
103 + "]";
104 }
105
106 }