1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.DurationUnit;
6 import org.djunits.unit.TimeUnit;
7 import org.djunits.value.vfloat.scalar.base.FloatScalarAbs;
8 import org.djutils.base.NumberParser;
9 import org.djutils.exceptions.Throw;
10
11 import jakarta.annotation.Generated;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
32 public class FloatTime extends FloatScalarAbs<TimeUnit, FloatTime, DurationUnit, FloatDuration>
33 {
34
35 private static final long serialVersionUID = 20150901L;
36
37
38 public static final FloatTime ZERO = new FloatTime(0.0f, TimeUnit.DEFAULT);
39
40
41
42
43
44
45 public FloatTime(final float value, final TimeUnit unit)
46 {
47 super(value, unit);
48 }
49
50
51
52
53
54
55 public FloatTime(final double value, final TimeUnit unit)
56 {
57 super((float) value, unit);
58 }
59
60
61
62
63
64 public FloatTime(final FloatTime value)
65 {
66 super(value);
67 }
68
69 @Override
70 public final FloatTime instantiateAbs(final float value, final TimeUnit unit)
71 {
72 return new FloatTime(value, unit);
73 }
74
75 @Override
76 public final FloatDuration instantiateRel(final float value, final DurationUnit unit)
77 {
78 return new FloatDuration(value, unit);
79 }
80
81
82
83
84
85
86 public static final FloatTime instantiateSI(final float value)
87 {
88 return new FloatTime(value, TimeUnit.DEFAULT);
89 }
90
91
92
93
94
95
96
97
98 public static FloatTime interpolate(final FloatTime zero, final FloatTime one, final float ratio)
99 {
100 return new FloatTime(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
101 zero.getDisplayUnit());
102 }
103
104
105
106
107
108
109
110 public static FloatTime max(final FloatTime a1, final FloatTime a2)
111 {
112 return a1.gt(a2) ? a1 : a2;
113 }
114
115
116
117
118
119
120
121
122 public static FloatTime max(final FloatTime a1, final FloatTime a2, final FloatTime... an)
123 {
124 FloatTime maxa = a1.gt(a2) ? a1 : a2;
125 for (FloatTime a : an)
126 {
127 if (a.gt(maxa))
128 {
129 maxa = a;
130 }
131 }
132 return maxa;
133 }
134
135
136
137
138
139
140
141 public static FloatTime min(final FloatTime a1, final FloatTime a2)
142 {
143 return a1.lt(a2) ? a1 : a2;
144 }
145
146
147
148
149
150
151
152
153 public static FloatTime min(final FloatTime a1, final FloatTime a2, final FloatTime... an)
154 {
155 FloatTime mina = a1.lt(a2) ? a1 : a2;
156 for (FloatTime a : an)
157 {
158 if (a.lt(mina))
159 {
160 mina = a;
161 }
162 }
163 return mina;
164 }
165
166
167
168
169
170
171
172
173
174
175 public static FloatTime valueOf(final String text)
176 {
177 Throw.whenNull(text, "Error parsing FloatTime: text to parse is null");
178 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatTime: empty text to parse");
179 try
180 {
181 NumberParser numberParser = new NumberParser().lenient().trailing();
182 float f = numberParser.parseFloat(text);
183 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
184 TimeUnit unit = TimeUnit.BASE.getUnitByAbbreviation(unitString);
185 if (unit == null)
186 throw new IllegalArgumentException("Unit " + unitString + " not found");
187 return new FloatTime(f, unit);
188 }
189 catch (Exception exception)
190 {
191 throw new IllegalArgumentException(
192 "Error parsing FloatTime from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
193 exception);
194 }
195 }
196
197
198
199
200
201
202
203
204
205 public static FloatTime of(final float value, final String unitString)
206 {
207 Throw.whenNull(unitString, "Error parsing FloatTime: unitString is null");
208 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatTime: empty unitString");
209 TimeUnit unit = TimeUnit.BASE.getUnitByAbbreviation(unitString);
210 if (unit != null)
211 {
212 return new FloatTime(value, unit);
213 }
214 throw new IllegalArgumentException("Error parsing FloatTime with unit " + unitString);
215 }
216
217 }