1 /*
2 * Copyright (C) 2018 Alberto Irurueta Carro (alberto@irurueta.com)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.irurueta.units;
18
19 /**
20 * Enumerator containing recognized typical acceleration units.
21 */
22 public enum AccelerationUnit {
23 /**
24 * Meters per squared second (m/s^2).
25 */
26 METERS_PER_SQUARED_SECOND,
27
28 /**
29 * Relative to gravitational acceleration (9.81 m/s^2).
30 */
31 G,
32
33 /**
34 * Feet per squared second (ft/s^2).
35 */
36 FEET_PER_SQUARED_SECOND;
37
38 /**
39 * Returns unit system for provided acceleration unit.
40 *
41 * @param unit acceleration unit to be checked.
42 * @return unit system (metric or imperial).
43 * @throws IllegalArgumentException if unit is null or not supported.
44 */
45 @SuppressWarnings("DuplicatedCode")
46 public static UnitSystem getUnitSystem(final AccelerationUnit unit) {
47 if (unit == null) {
48 throw new IllegalArgumentException();
49 }
50
51 if (unit == FEET_PER_SQUARED_SECOND) {
52 return UnitSystem.IMPERIAL;
53 } else {
54 return UnitSystem.METRIC;
55 }
56 }
57
58 /**
59 * Gets all supported metric acceleration units.
60 *
61 * @return all supported metric acceleration units.
62 */
63 public static AccelerationUnit[] getMetricUnits() {
64 return new AccelerationUnit[]{
65 METERS_PER_SQUARED_SECOND,
66 G
67 };
68 }
69
70 /**
71 * Gets all supported imperial acceleration units.
72 *
73 * @return all supported imperial acceleration units.
74 */
75 public static AccelerationUnit[] getImperialUnits() {
76 return new AccelerationUnit[]{
77 FEET_PER_SQUARED_SECOND
78 };
79 }
80
81 /**
82 * Indicates whether provided unit belongs to the metric unit system.
83 *
84 * @param unit acceleration unit to be checked.
85 * @return true if unit belongs to metric unit system.
86 * @throws IllegalArgumentException if unit is null or not supported.
87 */
88 public static boolean isMetric(final AccelerationUnit unit) {
89 return getUnitSystem(unit) == UnitSystem.METRIC;
90 }
91
92 /**
93 * Indicates whether provided unit belongs to the imperial unit system.
94 *
95 * @param unit acceleration unit to be checked.
96 * @return true if unit belongs to imperial unit system.
97 * @throws IllegalArgumentException if unit is null or not supported.
98 */
99 public static boolean isImperial(final AccelerationUnit unit) {
100 return getUnitSystem(unit) == UnitSystem.IMPERIAL;
101 }
102 }