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.opentrafficsim.core.OTS_SCALAR;
10  
11  /**
12   * <p>
13   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * <p>
16   * @version $Revision: 1368 $, $LastChangedDate: 2015-09-02 00:20:20 +0200 (Wed, 02 Sep 2015) $, by $Author: averbraeck $,
17   *          initial version Aug 3, 2014 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   */
20  public class OTSSimTimeDouble extends SimTime<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>
21      implements Serializable, OTS_SCALAR
22  {
23      /** */
24      private static final long serialVersionUID = 20140815L;
25  
26      /** value represents the value in milliseconds. */
27      private DoubleScalar.Abs<TimeUnit> time;
28  
29      /**
30       * @param time DoubleSclaar.Abs&lt;TimeUnit&gt;
31       */
32      public OTSSimTimeDouble(final DoubleScalar.Abs<TimeUnit> time)
33      {
34          super(time);
35      }
36  
37      /** {@inheritDoc} */
38      @Override
39      public final void add(final DoubleScalar.Rel<TimeUnit> simTime)
40      {
41          this.time = this.time.plus(simTime);
42      }
43  
44      /** {@inheritDoc} */
45      @Override
46      public final void subtract(final DoubleScalar.Rel<TimeUnit> simTime)
47      {
48          this.time = this.time.minus(simTime);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public final int compareTo(final OTSSimTimeDouble simTime)
54      {
55          return this.time.compareTo(simTime.get());
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public final OTSSimTimeDouble setZero()
61      {
62          // TODO this.time.setZero();
63          return this;
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public final OTSSimTimeDouble copy()
69      {
70          return new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(this.time.getInUnit(), this.time.getUnit()));
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public final void set(final DoubleScalar.Abs<TimeUnit> value)
76      {
77          this.time = value;
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public final DoubleScalar.Abs<TimeUnit> get()
83      {
84          return this.time;
85      }
86  
87      /**
88       * @return the time as a strongly typed time.
89       */
90      public final Time.Abs getTime()
91      {
92          return new Time.Abs(this.time);
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public final DoubleScalar.Rel<TimeUnit> minus(final OTSSimTimeDouble absoluteTime)
98      {
99          DoubleScalar.Rel<TimeUnit> rel = DoubleScalar.minus(this.time, absoluteTime.get());
100         return rel;
101     }
102 
103 }