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