1 package org.djunits.unit;
2
3 import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
4 import static org.djunits.unit.unitsystem.UnitSystem.SI_ACCEPTED;
5 import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
6
7 import org.djunits.unit.scale.GradeScale;
8 import org.djunits.unit.scale.LinearScale;
9 import org.djunits.unit.scale.Scale;
10 import org.djunits.unit.unitsystem.UnitSystem;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class AngleUnit extends Unit<AngleUnit>
26 {
27
28 private static final long serialVersionUID = 20140607L;
29
30
31 public static final AngleUnit SI;
32
33
34 public static final AngleUnit RADIAN;
35
36
37 public static final AngleUnit PERCENT;
38
39
40 public static final AngleUnit DEGREE;
41
42
43 public static final AngleUnit ARCMINUTE;
44
45
46 public static final AngleUnit ARCSECOND;
47
48
49 public static final AngleUnit GRAD;
50
51
52 public static final AngleUnit CENTESIMAL_ARCMINUTE;
53
54
55 public static final AngleUnit CENTESIMAL_ARCSECOND;
56
57 static
58 {
59 SI = new AngleUnit("AngleUnit.rad", SI_DERIVED);
60 RADIAN = SI;
61 DEGREE = new AngleUnit("AngleUnit.deg", SI_ACCEPTED, RADIAN, Math.PI / 180.0);
62 ARCMINUTE = new AngleUnit("AngleUnit.arcmin", SI_ACCEPTED, DEGREE, 1.0 / 60.0);
63 ARCSECOND = new AngleUnit("AngleUnit.arcsec", SI_ACCEPTED, DEGREE, 1.0 / 3600.0);
64 GRAD = new AngleUnit("AngleUnit.grad", OTHER, RADIAN, 2.0 * Math.PI / 400.0);
65 CENTESIMAL_ARCMINUTE = new AngleUnit("AngleUnit.centesimal_arcmin", OTHER, GRAD, 1.0 / 100.0);
66 CENTESIMAL_ARCSECOND = new AngleUnit("AngleUnit.centesimal_arcsec", OTHER, GRAD, 1.0 / 10000.0);
67 PERCENT = new AngleUnit("AngleUnit.perc", OTHER, new GradeScale(0.01));
68
69 }
70
71
72
73
74
75
76 private AngleUnit(final String abbreviationKey, final UnitSystem unitSystem)
77 {
78 super(abbreviationKey, unitSystem);
79 }
80
81
82
83
84
85
86
87
88
89 private AngleUnit(final String abbreviationKey, final UnitSystem unitSystem, final AngleUnit referenceUnit,
90 final double scaleFactorToReferenceUnit)
91 {
92 super(abbreviationKey, unitSystem, new LinearScale(
93 ((LinearScale) referenceUnit.getScale()).getConversionFactorToStandardUnit() * scaleFactorToReferenceUnit));
94 }
95
96
97
98
99
100
101
102
103
104
105 public AngleUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final AngleUnit referenceUnit,
106 final double scaleFactorToReferenceUnit)
107 {
108 super(name, abbreviation, unitSystem, new LinearScale(
109 ((LinearScale) referenceUnit.getScale()).getConversionFactorToStandardUnit() * scaleFactorToReferenceUnit));
110 }
111
112
113
114
115
116
117
118 private AngleUnit(final String abbreviationKey, final UnitSystem unitSystem, final Scale scale)
119 {
120 super(abbreviationKey, unitSystem, scale);
121 }
122
123
124 @Override
125 public final AngleUnit getStandardUnit()
126 {
127 return RADIAN;
128 }
129
130
131 @Override
132 public final String getSICoefficientsString()
133 {
134 return "1";
135 }
136
137
138 @Override
139 public int hashCode()
140 {
141 final int prime = 31;
142 int result = super.hashCode();
143 result = prime * result + ((getScale() == null) ? 0 : getScale().hashCode());
144 return result;
145 }
146
147
148 @SuppressWarnings("checkstyle:needbraces")
149 @Override
150 public boolean equals(final Object obj)
151 {
152 if (this == obj)
153 return true;
154 if (!super.equals(obj))
155 return false;
156 if (getClass() != obj.getClass())
157 return false;
158 AngleUnit other = (AngleUnit) obj;
159 if (getScale() == null)
160 {
161 if (other.getScale() != null)
162 return false;
163 }
164 else if (!getScale().equals(other.getScale()))
165 return false;
166 return true;
167 }
168
169
170 @SuppressWarnings("checkstyle:needbraces")
171 @Override
172 public boolean equalsIgnoreNaming(final Object obj)
173 {
174 if (this == obj)
175 return true;
176 if (getClass() != obj.getClass())
177 return false;
178 AngleUnit other = (AngleUnit) obj;
179 if (getScale() == null)
180 {
181 if (other.getScale() != null)
182 return false;
183 }
184 else if (!getScale().equals(other.getScale()))
185 return false;
186 return true;
187 }
188
189 }