View Javadoc
1   package org.opentrafficsim.core.dsol;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.TimeUnit;
6   import org.djunits.value.vdouble.scalar.Duration;
7   import org.djunits.value.vdouble.scalar.Time;
8   
9   import nl.tudelft.simulation.dsol.simtime.SimTime;
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-2016 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: 2441 $, $LastChangedDate: 2016-11-02 11:22:48 +0100 (Wed, 02 Nov 2016) $, by $Author: averbraeck $,
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<Time, Duration, OTSSimTimeDouble> implements Serializable
23  {
24      /** */
25      private static final long serialVersionUID = 20140815L;
26  
27      /** The time. */
28      private Time time;
29  
30      /**
31       * @param time DoubleSclaar.Abs&lt;TimeUnit&gt;
32       */
33      public OTSSimTimeDouble(final Time time)
34      {
35          super(time);
36      }
37  
38      /** {@inheritDoc} */
39      @Override
40      public final void add(final Duration simTime)
41      {
42          this.time = this.time.plus(simTime);
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      public final void subtract(final Duration simTime)
48      {
49          this.time = this.time.minus(simTime);
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public final int compareTo(final OTSSimTimeDouble simTime)
55      {
56          return this.time.compareTo(simTime.get());
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public final OTSSimTimeDouble setZero()
62      {
63          this.time = Time.ZERO;
64          return this;
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public final OTSSimTimeDouble copy()
70      {
71          if (this.time.getUnit().equals(this.time.getUnit().getStandardUnit()))
72          {
73              return new OTSSimTimeDouble(this.time);
74          }
75          return new OTSSimTimeDouble(new Time(this.time.getInUnit(), this.time.getUnit()));
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public final void set(final Time value)
81      {
82          this.time = value;
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public final Time get()
88      {
89          return this.time;
90      }
91  
92      /**
93       * @return the time as a strongly typed time.
94       */
95      public final Time getTime()
96      {
97          return new Time(this.time.si, TimeUnit.SI);
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public final Duration minus(final OTSSimTimeDouble absoluteTime)
103     {
104         Duration rel = this.time.minus(absoluteTime.get());
105         return rel;
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     public final String toString()
111     {
112         return "OTSSimTimeDouble [time=" + this.time + "]";
113     }
114 
115 }