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.radian", "AngleUnit.rad", SI_DERIVED);
60 RADIAN = SI;
61 DEGREE = new AngleUnit("AngleUnit.degree", "AngleUnit.deg", SI_ACCEPTED, RADIAN, Math.PI / 180.0, true);
62 ARCMINUTE = new AngleUnit("AngleUnit.arcminute", "AngleUnit.arcmin", SI_ACCEPTED, DEGREE, 1.0 / 60.0, true);
63 ARCSECOND = new AngleUnit("AngleUnit.arcsecond", "AngleUnit.arcsec", SI_ACCEPTED, DEGREE, 1.0 / 3600.0, true);
64 GRAD = new AngleUnit("AngleUnit.gradian", "AngleUnit.grad", OTHER, RADIAN, 2.0 * Math.PI / 400.0, true);
65 CENTESIMAL_ARCMINUTE =
66 new AngleUnit("AngleUnit.centesimal_arcminute", "AngleUnit.centesimal_arcmin", OTHER, GRAD, 1.0 / 100.0, true);
67 CENTESIMAL_ARCSECOND = new AngleUnit("AngleUnit.centesimal_arcsecond", "AngleUnit.centesimal_arcsec", OTHER, GRAD,
68 1.0 / 10000.0, true);
69 PERCENT = new AngleUnit("AngleUnit.percent", "AngleUnit.perc", OTHER, new GradeScale(0.01), true);
70
71 }
72
73
74
75
76
77
78
79 private AngleUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
80 {
81 super(nameKey, abbreviationKey, unitSystem, true);
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 private AngleUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
98 final AngleUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
99 {
100 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, new LinearScale(
101 ((LinearScale) referenceUnit.getScale()).getConversionFactorToStandardUnit() * scaleFactorToReferenceUnit),
102 standardUnit);
103 }
104
105
106
107
108
109
110
111
112
113
114 public AngleUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final AngleUnit referenceUnit,
115 final double scaleFactorToReferenceUnit)
116 {
117 this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131 private AngleUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
132 final Scale scale, final boolean standardUnit)
133 {
134 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, scale, standardUnit);
135 }
136
137
138 @Override
139 public final AngleUnit getStandardUnit()
140 {
141 return RADIAN;
142 }
143
144
145 @Override
146 public final String getSICoefficientsString()
147 {
148 return "1";
149 }
150
151
152 @Override
153 public int hashCode()
154 {
155 final int prime = 31;
156 int result = super.hashCode();
157 result = prime * result + ((getScale() == null) ? 0 : getScale().hashCode());
158 return result;
159 }
160
161
162 @SuppressWarnings("checkstyle:needbraces")
163 @Override
164 public boolean equals(final Object obj)
165 {
166 if (this == obj)
167 return true;
168 if (!super.equals(obj))
169 return false;
170 if (getClass() != obj.getClass())
171 return false;
172 AngleUnit other = (AngleUnit) obj;
173 if (getScale() == null)
174 {
175 if (other.getScale() != null)
176 return false;
177 }
178 else if (!getScale().equals(other.getScale()))
179 return false;
180 return true;
181 }
182
183
184 @SuppressWarnings("checkstyle:needbraces")
185 @Override
186 public boolean equalsIgnoreNaming(final Object obj)
187 {
188 if (this == obj)
189 return true;
190 if (getClass() != obj.getClass())
191 return false;
192 AngleUnit other = (AngleUnit) obj;
193 if (getScale() == null)
194 {
195 if (other.getScale() != null)
196 return false;
197 }
198 else if (!getScale().equals(other.getScale()))
199 return false;
200 return true;
201 }
202
203 }