View Javadoc
1   package org.opentrafficsim.base;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.djutils.exceptions.Throw;
5   
6   /**
7    * An object with a time stamp, where the object is of a specific class.
8    * <p>
9    * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
11   * </p>
12   * @author Alexander Verbraeck
13   * @author Peter Knoppers
14   * @author Wouter Schakel
15   * @param <T> the time stamped object class.
16   * @param object the object
17   * @param timestamp the simulation time stamp
18   */
19  public record TimeStampedObject<T>(T object, Duration timestamp) implements Comparable<TimeStampedObject<?>>
20  {
21  
22      /**
23       * Constructor.
24       * @param object the object
25       * @param timestamp the simulation time stamp
26       */
27      public TimeStampedObject
28      {
29          Throw.whenNull(object, "object");
30          Throw.whenNull(timestamp, "timestamp");
31      }
32  
33      @Override
34      public int compareTo(final TimeStampedObject<?> o)
35      {
36          return this.timestamp.compareTo(o.timestamp);
37      }
38  
39  }