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 private AngleUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
95 final AngleUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
96 {
97 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, new LinearScale(
98 ((LinearScale) referenceUnit.getScale()).getConversionFactorToStandardUnit() * scaleFactorToReferenceUnit),
99 standardUnit);
100 }
101
102
103
104
105
106
107
108
109
110 public AngleUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final AngleUnit referenceUnit,
111 final double scaleFactorToReferenceUnit)
112 {
113 this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
114 }
115
116
117
118
119
120
121
122
123
124
125 private AngleUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
126 final Scale scale, final boolean standardUnit)
127 {
128 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, scale, standardUnit);
129 }
130
131
132 @Override
133 public final AngleUnit getStandardUnit()
134 {
135 return RADIAN;
136 }
137
138
139 @Override
140 public final String getSICoefficientsString()
141 {
142 return "1";
143 }
144
145
146 @Override
147 public int hashCode()
148 {
149 final int prime = 31;
150 int result = super.hashCode();
151 result = prime * result + ((getScale() == null) ? 0 : getScale().hashCode());
152 return result;
153 }
154
155
156 @SuppressWarnings("checkstyle:needbraces")
157 @Override
158 public boolean equals(final Object obj)
159 {
160 if (this == obj)
161 return true;
162 if (!super.equals(obj))
163 return false;
164 if (getClass() != obj.getClass())
165 return false;
166 AngleUnit other = (AngleUnit) obj;
167 if (getScale() == null)
168 {
169 if (other.getScale() != null)
170 return false;
171 }
172 else if (!getScale().equals(other.getScale()))
173 return false;
174 return true;
175 }
176
177
178 @SuppressWarnings("checkstyle:needbraces")
179 @Override
180 public boolean equalsIgnoreNaming(final Object obj)
181 {
182 if (this == obj)
183 return true;
184 if (getClass() != obj.getClass())
185 return false;
186 AngleUnit other = (AngleUnit) obj;
187 if (getScale() == null)
188 {
189 if (other.getScale() != null)
190 return false;
191 }
192 else if (!getScale().equals(other.getScale()))
193 return false;
194 return true;
195 }
196
197
198 }