1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.regex.Matcher;
4
5 import javax.annotation.Generated;
6
7 import org.djunits.Throw;
8 import org.djunits.unit.AngleUnit;
9 import org.djunits.unit.DirectionUnit;
10 import org.djunits.value.util.ValueUtil;
11 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarAbs;
12
13
14
15
16
17
18
19
20
21
22
23 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
24 public class Direction extends AbstractDoubleScalarAbs<DirectionUnit, Direction, AngleUnit, Angle>
25 {
26
27 private static final long serialVersionUID = 20150901L;
28
29
30 public static final Directionscalar/Direction.html#Direction">Direction ZERO = new Direction(0.0, DirectionUnit.DEFAULT);
31
32
33
34
35
36
37 public Direction(final double value, final DirectionUnit unit)
38 {
39 super(value, unit);
40 }
41
42
43
44
45
46 public Directionuble/scalar/Direction.html#Direction">Direction(final Direction value)
47 {
48 super(value);
49 }
50
51
52 @Override
53 public final Direction instantiateAbs(final double value, final DirectionUnit unit)
54 {
55 return new Direction(value, unit);
56 }
57
58
59 @Override
60 public final Angle instantiateRel(final double value, final AngleUnit unit)
61 {
62 return new Angle(value, unit);
63 }
64
65
66
67
68
69
70 public static final Direction instantiateSI(final double value)
71 {
72 return new Direction(value, DirectionUnit.DEFAULT);
73 }
74
75
76
77
78
79
80
81
82 public static Directioncalar/Direction.html#Direction">DirectionDirection.html#Direction">Direction interpolate(final Directioncalar/Direction.html#Direction">Direction zero, final Direction one, final double ratio)
83 {
84 return new Direction(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
85 zero.getDisplayUnit());
86 }
87
88
89
90
91
92
93
94 public static Direction/scalar/Direction.html#Direction">Direction/scalar/Direction.html#Direction">Direction max(final Direction/scalar/Direction.html#Direction">Direction a1, final Direction a2)
95 {
96 return a1.gt(a2) ? a1 : a2;
97 }
98
99
100
101
102
103
104
105
106 public static Direction/scalar/Direction.html#Direction">Direction/scalar/Direction.html#Direction">Direction max(final Direction/scalar/Direction.html#Direction">Direction a1, final Direction a2, final Direction... an)
107 {
108 Direction maxa = a1.gt(a2) ? a1 : a2;
109 for (Direction a : an)
110 {
111 if (a.gt(maxa))
112 {
113 maxa = a;
114 }
115 }
116 return maxa;
117 }
118
119
120
121
122
123
124
125 public static Direction/scalar/Direction.html#Direction">Direction/scalar/Direction.html#Direction">Direction min(final Direction/scalar/Direction.html#Direction">Direction a1, final Direction a2)
126 {
127 return a1.lt(a2) ? a1 : a2;
128 }
129
130
131
132
133
134
135
136
137 public static Direction/scalar/Direction.html#Direction">Direction/scalar/Direction.html#Direction">Direction min(final Direction/scalar/Direction.html#Direction">Direction a1, final Direction a2, final Direction... an)
138 {
139 Direction mina = a1.lt(a2) ? a1 : a2;
140 for (Direction a : an)
141 {
142 if (a.lt(mina))
143 {
144 mina = a;
145 }
146 }
147 return mina;
148 }
149
150
151
152
153
154
155
156
157
158
159 public static Direction valueOf(final String text)
160 {
161 Throw.whenNull(text, "Error parsing Direction: text to parse is null");
162 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Direction: empty text to parse");
163 Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
164 if (matcher.find())
165 {
166 int index = matcher.end();
167 String unitString = text.substring(index).trim();
168 String valueString = text.substring(0, index).trim();
169 DirectionUnit unit = DirectionUnit.BASE.getUnitByAbbreviation(unitString);
170 if (unit != null)
171 {
172 double d = Double.parseDouble(valueString);
173 return new Direction(d, unit);
174 }
175 }
176 throw new IllegalArgumentException("Error parsing Direction from " + text);
177 }
178
179
180
181
182
183
184
185
186
187 public static Direction of(final double value, final String unitString)
188 {
189 Throw.whenNull(unitString, "Error parsing Direction: unitString is null");
190 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Direction: empty unitString");
191 DirectionUnit unit = DirectionUnit.BASE.getUnitByAbbreviation(unitString);
192 if (unit != null)
193 {
194 return new Direction(value, unit);
195 }
196 throw new IllegalArgumentException("Error parsing Direction with unit " + unitString);
197 }
198
199 }