-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSIUnit.java
More file actions
346 lines (290 loc) · 7.76 KB
/
SIUnit.java
File metadata and controls
346 lines (290 loc) · 7.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/* Original Licensing Copyright
*
* Contains all International System of Units constants and definitions.
* Copyright (C) 2021 DZ-FSDev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dz_fs_dev.physics;
import java.math.BigDecimal;
import lombok.Getter;
/**
* Contains all International System of Units constants and definitions.
*
* @see <a href=https://physics.nist.gov/cuu/Units/checklist.html>
* NIST SI Unit Rules and Style Conventions</a>
* @author DZ-FSDev
* @since 17.0.2
* @version 0.0.28
*/
public abstract class SIUnit implements IUnit{
/**
* Primary frequency standard in which the photon absorption by transitions between
* the two hyperfine ground states of cesium-133 atoms. Also known as the Cesium Standard.
* <br>
* <p>Measured in Hertz.
*/
final static BigDecimal HYPERFINE_TRANSITION_FREQUENCY_CESIUM = new BigDecimal("9192631770");
/**
* The speed of light in a vacuum.
* <br>
* <p>Measured in Hertz.
*/
final static BigDecimal SPEED_OF_LIGHT = new BigDecimal("299792458");
/**
* Predicts the spectral distribution of thermal black-body radiation.
* <br>
* <p>Measured in Joule seconds.
*/
final static BigDecimal PLANCK = new BigDecimal("6.62607015e-34");
/**
* The magnitude of electric charge carried by a single proton or, single electron.
* <br>
* <p>Measured in Coulombs.
*/
final static BigDecimal ELEMENTARY_CHARGE = new BigDecimal("1.602176634e-19");
/**
* Relates the average relative kinetic energy of particles with the thermodynamic temperature of gases.
* <br>
* <p>Measured in Joules per Kelvin.
*/
final static BigDecimal BOLTZMANN = new BigDecimal("1.380649e-23");
/**
* Relates the number of particles with the amount of substance in said sample.
* <br>
* <p>Measured in Mole<sup>-1</sup>.
*/
final static BigDecimal AVAGADRO = new BigDecimal("6.02214076e+23");
/**
* A measure of how well a light source producing monochromatic 540e<sup>12</sup> Hz radiation
* is visible to the human eye.
* <br>
* <p>Measured in Lumens per Watt.
*/
final static BigDecimal LUMINOUS_EFFICACY = new BigDecimal("683");
/** Electric Current */
static class Ampere extends SIUnit implements IPowable<Ampere>{
public Ampere(Rational order) {
super(order);
}
@Override
public String symbol() {
return "A";
}
@Override
public String name() {
return "Ampere";
}
@Override
public IUnit multiplyBy(IUnit o) {
if(o instanceof Ampere)
return new Ampere(o.getOrder().add(this.getOrder()));
return super.multiplyBy(o);
}
@Override
public Ampere pow(int exponent) {
return pow(new Rational(exponent));
}
@Override
public Ampere pow(Rational exponent) {
if(exponent.doubleValue() == 0)
throw new IllegalArgumentException(
String.format("Cannot raise %s to the power of 0!",
this.getClass().getName()));
return new Ampere(exponent.multiply(this.getOrder()));
}
}
/** Luminous Intensity */
static class Candela extends SIUnit implements IPowable<Candela>{
public Candela(Rational order) {
super(order);
}
@Override
public String symbol() {
return "cd";
}
@Override
public String name() {
return "Candela";
}
@Override
public Candela pow(int exponent) {
return pow(new Rational(exponent));
}
@Override
public Candela pow(Rational exponent) {
if(exponent.doubleValue() == 0)
throw new IllegalArgumentException(
String.format("Cannot raise %s to the power of 0!",
this.getClass().getName()));
return new Candela(exponent.multiply(this.getOrder()));
}
}
/** Thermodynamic Temperature */
static class Kelvin extends SIUnit implements IPowable<Kelvin>{
public Kelvin(Rational order) {
super(order);
}
@Override
public String symbol() {
return "K";
}
@Override
public String name() {
return "Kelvin";
}
@Override
public Kelvin pow(int exponent) {
return pow(new Rational(exponent));
}
@Override
public Kelvin pow(Rational exponent) {
if(exponent.doubleValue() == 0)
throw new IllegalArgumentException(
String.format("Cannot raise %s to the power of 0!",
this.getClass().getName()));
return new Kelvin(exponent.multiply(this.getOrder()));
}
}
/** Mass */
static class Gram extends SIUnit implements IPowable<Gram>{
public Gram(Rational order) {
super(order);
}
@Override
public String symbol() {
return "g";
}
@Override
public String name() {
return "Gram";
}
@Override
public Gram pow(int exponent) {
return pow(new Rational(exponent));
}
@Override
public Gram pow(Rational exponent) {
if(exponent.doubleValue() == 0)
throw new IllegalArgumentException(
String.format("Cannot raise %s to the power of 0!",
this.getClass().getName()));
return new Gram(exponent.multiply(this.getOrder()));
}
}
/** Distance */
static class Meter extends SIUnit implements IPowable<Meter>{
public Meter(Rational order) {
super(order);
}
@Override
public String symbol() {
return "m";
}
@Override
public String name() {
return "Meter";
}
@Override
public Meter pow(int exponent) {
return pow(new Rational(exponent));
}
@Override
public Meter pow(Rational exponent) {
if(exponent.doubleValue() == 0)
throw new IllegalArgumentException(
String.format("Cannot raise %s to the power of 0!",
this.getClass().getName()));
return new Meter(exponent.multiply(this.getOrder()));
}
}
/** Substance */
static class Mole extends SIUnit implements IPowable<Mole>{
public Mole(Rational order) {
super(order);
}
@Override
public String symbol() {
return "mol";
}
@Override
public String name() {
return "Mole";
}
@Override
public Mole pow(int exponent) {
return pow(new Rational(exponent));
}
@Override
public Mole pow(Rational exponent) {
if(exponent.doubleValue() == 0)
throw new IllegalArgumentException(
String.format("Cannot raise %s to the power of 0!",
this.getClass().getName()));
return new Mole(exponent.multiply(this.getOrder()));
}
}
/** Time */
static class Second extends SIUnit implements IPowable<Second>{
public Second(Rational order) {
super(order);
}
@Override
public String symbol() {
return "s";
}
@Override
public String name() {
return "Second";
}
@Override
public Second pow(int exponent) {
return pow(new Rational(exponent));
}
@Override
public Second pow(Rational exponent) {
if(exponent.doubleValue() == 0)
throw new IllegalArgumentException(
String.format("Cannot raise %s to the power of 0!",
this.getClass().getName()));
return new Second(exponent.multiply(this.getOrder()));
}
}
private @Getter Rational order;
/**
* Initializes a new instance of an SIUnit with a specified order.
*
* @param order The order of this SIUnit.
* @since 0.0.19
*/
private SIUnit(Rational order) {
this.order = order;
}
/**
* @since 0.0.7
*/
@Override
public IUnit divideBy(IUnit o) {
// TODO Auto-generated method stub
return null;
}
/**
* @since 0.0.7
*/
@Override
public IUnit multiplyBy(IUnit o) {
// TODO Auto-generated method stub
return null;
}
}