View Javadoc
1   package org.opentrafficsim.core.dsol;
2   
3   import java.io.Serializable;
4   
5   import nl.tudelft.simulation.dsol.simtime.SimTime;
6   
7   import org.djunits.unit.TimeUnit;
8   import org.djunits.value.vdouble.scalar.DoubleScalar;
9   import org.djunits.value.vdouble.scalar.Time;
10  
11  /**
12   * OTS uses a DoubleScalar.Abs<TimeUnit> to represent simulation start time and a DoubleScalar.Rel<timeUnit> to
13   * represent the warmup time and total duration of a simulation.
14   * <p>
15   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision: 1889 $, $LastChangedDate: 2016-04-05 21:30:47 +0200 (Tue, 05 Apr 2016) $, by $Author: pknoppers $,
19   *          initial version Aug 3, 2014 <br>
20   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   */
22  public class OTSSimTimeDouble extends SimTime<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>
23          implements Serializable
24  {
25      /** */
26      private static final long serialVersionUID = 20140815L;
27  
28      /** The time. */
29      private DoubleScalar.Abs<TimeUnit> time;
30  
31      /**
32       * @param time DoubleSclaar.Abs&lt;TimeUnit&gt;
33       */
34      public OTSSimTimeDouble(final DoubleScalar.Abs<TimeUnit> time)
35      {
36          super(time);
37      }
38  
39      /** {@inheritDoc} */
40      @Override
41      public final void add(final DoubleScalar.Rel<TimeUnit> simTime)
42      {
43          this.time = this.time.plus(simTime);
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public final void subtract(final DoubleScalar.Rel<TimeUnit> simTime)
49      {
50          this.time = this.time.minus(simTime);
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public final int compareTo(final OTSSimTimeDouble simTime)
56      {
57          return this.time.compareTo(simTime.get());
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public final OTSSimTimeDouble setZero()
63      {
64          // TODO this.time.setZero();
65          return this;
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public final OTSSimTimeDouble copy()
71      {
72          return new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(this.time.getInUnit(), this.time.getUnit()));
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public final void set(final DoubleScalar.Abs<TimeUnit> value)
78      {
79          this.time = value;
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public final DoubleScalar.Abs<TimeUnit> get()
85      {
86          return this.time;
87      }
88  
89      /**
90       * @return the time as a strongly typed time.
91       */
92      public final Time.Abs getTime()
93      {
94          return new Time.Abs(this.time.si, TimeUnit.SI);
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public final DoubleScalar.Rel<TimeUnit> minus(final OTSSimTimeDouble absoluteTime)
100     {
101         DoubleScalar.Rel<TimeUnit> rel = DoubleScalar.minus(this.time, absoluteTime.get());
102         return rel;
103     }
104 
105 }