1 package org.opentrafficsim.base;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Time;
6
7
8
9
10
11
12
13
14
15
16
17 public class TimeStampedObject<C> implements Serializable
18 {
19
20 private static final long serialVersionUID = 20160129L;
21
22
23 private final C object;
24
25
26 private final Time timestamp;
27
28
29
30
31
32
33 public TimeStampedObject(final C object, final Time timestamp)
34 {
35 this.object = object;
36 this.timestamp = timestamp;
37 }
38
39
40
41
42
43 public final C getObject()
44 {
45 return this.object;
46 }
47
48
49
50
51
52 public final Time getTimestamp()
53 {
54 return this.timestamp;
55 }
56
57
58 @Override
59 public final String toString()
60 {
61 return "TimeStampedObject [object=" + this.object + ", timestamp=" + this.timestamp + "]";
62 }
63
64 @Override
65 public int hashCode()
66 {
67 final int prime = 31;
68 int result = 1;
69 result = prime * result + ((object == null) ? 0 : object.hashCode());
70 result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode());
71 return result;
72 }
73
74 @Override
75 public boolean equals(Object obj)
76 {
77 if (this == obj)
78 return true;
79 if (obj == null)
80 return false;
81 if (getClass() != obj.getClass())
82 return false;
83 TimeStampedObject other = (TimeStampedObject) obj;
84 if (object == null)
85 {
86 if (other.object != null)
87 return false;
88 }
89 else if (!object.equals(other.object))
90 return false;
91 if (timestamp == null)
92 {
93 if (other.timestamp != null)
94 return false;
95 }
96 else if (!timestamp.equals(other.timestamp))
97 return false;
98 return true;
99 }
100
101 }