View Javadoc
1   package org.opentrafficsim.base;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.value.vdouble.scalar.Time;
6   
7   /**
8    * An object with a time stamp, where the object is of a specific class.
9    * <p>
10   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12   * </p>
13   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
14   * initial version Jan 29, 2016 <br>
15   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17   * @param <C> the time stamped object class.
18   */
19  public class TimeStampedObject<C> implements Serializable
20  {
21      /** */
22      private static final long serialVersionUID = 20160129L;
23  
24      /** The object. */
25      private final C object;
26  
27      /** The time stamp. */
28      private final Time timestamp;
29  
30      /**
31       * Construct a new TimeStampedObject.
32       * @param object C; the object.
33       * @param timestamp Time; the time stamp.
34       */
35      public TimeStampedObject(final C object, final Time timestamp)
36      {
37          this.object = object;
38          this.timestamp = timestamp;
39      }
40  
41      /**
42       * Retrieve the object.
43       * @return C; the object
44       */
45      public final C getObject()
46      {
47          return this.object;
48      }
49  
50      /**
51       * Retrieve the time stamp.
52       * @return Time; the time stamp
53       */
54      public final Time getTimestamp()
55      {
56          return this.timestamp;
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public final String toString()
62      {
63          return "TimeStampedObject [object=" + this.object + ", timestamp=" + this.timestamp + "]";
64      }
65  
66      @Override
67      public int hashCode()
68      {
69          final int prime = 31;
70          int result = 1;
71          result = prime * result + ((object == null) ? 0 : object.hashCode());
72          result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode());
73          return result;
74      }
75  
76      @Override
77      public boolean equals(Object obj)
78      {
79          if (this == obj)
80              return true;
81          if (obj == null)
82              return false;
83          if (getClass() != obj.getClass())
84              return false;
85          TimeStampedObjectrg/opentrafficsim/base/TimeStampedObject.html#TimeStampedObject">TimeStampedObject other = (TimeStampedObject) obj;
86          if (object == null)
87          {
88              if (other.object != null)
89                  return false;
90          }
91          else if (!object.equals(other.object))
92              return false;
93          if (timestamp == null)
94          {
95              if (other.timestamp != null)
96                  return false;
97          }
98          else if (!timestamp.equals(other.timestamp))
99              return false;
100         return true;
101     }
102 
103 }