1 package org.sim0mq.message.types;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.TimeUnit;
6 import org.djunits.value.vdouble.scalar.Time;
7 import org.djunits.value.vfloat.scalar.FloatTime;
8
9
10
11
12
13
14
15
16
17
18
19
20 public class NumberTime extends Number implements Serializable
21 {
22
23 private static final long serialVersionUID = 20170424L;
24
25
26 private final Number time;
27
28
29 private final Time doubleScalar;
30
31
32
33
34
35 public NumberTime(final Number time)
36 {
37 this.time = time;
38 this.doubleScalar = new Time(time.doubleValue(), TimeUnit.BASE_SECOND);
39 }
40
41
42
43
44
45 public NumberTime(final Time time)
46 {
47 this.time = time;
48 this.doubleScalar = time;
49 }
50
51
52
53
54
55 public NumberTime(final FloatTime time)
56 {
57 this.time = time;
58 this.doubleScalar = new Time(time.getInUnit(), time.getUnit());
59 }
60
61
62 @Override
63 public int intValue()
64 {
65 return this.time.intValue();
66 }
67
68
69 @Override
70 public long longValue()
71 {
72 return this.time.longValue();
73 }
74
75
76 @Override
77 public float floatValue()
78 {
79 return this.time.floatValue();
80 }
81
82
83 @Override
84 public double doubleValue()
85 {
86 return this.time.doubleValue();
87 }
88
89
90
91
92 public Time getTime()
93 {
94 return this.doubleScalar;
95 }
96
97
98
99
100 public FloatTime getFloatTime()
101 {
102 return new FloatTime((float) this.doubleScalar.getInUnit(), this.doubleScalar.getUnit());
103 }
104 }