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
13
14
15
16
17
18
19
20
21
22 public class OTSSimTimeDouble extends SimTime<Time, Duration, OTSSimTimeDouble> implements Serializable
23 {
24
25 private static final long serialVersionUID = 20140815L;
26
27
28 private Time time;
29
30
31
32
33 public OTSSimTimeDouble(final Time time)
34 {
35 super(time);
36 }
37
38
39 @Override
40 public final void add(final Duration simTime)
41 {
42 this.time = this.time.plus(simTime);
43 }
44
45
46 @Override
47 public final void subtract(final Duration simTime)
48 {
49 this.time = this.time.minus(simTime);
50 }
51
52
53 @Override
54 public final int compareTo(final OTSSimTimeDouble simTime)
55 {
56 return this.time.compareTo(simTime.get());
57 }
58
59
60 @Override
61 public final OTSSimTimeDouble setZero()
62 {
63 this.time = Time.ZERO;
64 return this;
65 }
66
67
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
79 @Override
80 public final void set(final Time value)
81 {
82 this.time = value;
83 }
84
85
86 @Override
87 public final Time get()
88 {
89 return this.time;
90 }
91
92
93
94
95 public final Time getTime()
96 {
97 return new Time(this.time.si, TimeUnit.SI);
98 }
99
100
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
109 @Override
110 public final String toString()
111 {
112 return "OTSSimTimeDouble [time=" + this.time + "]";
113 }
114
115 }