1 package org.djunits.unit;
2
3 import org.djunits.unit.scale.LinearScale;
4 import org.djunits.unit.scale.Scale;
5 import org.djunits.unit.scale.StandardScale;
6 import org.djunits.unit.unitsystem.UnitSystem;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public abstract class LinearUnit<U extends LinearUnit<U>> extends Unit<U>
24 {
25
26 private static final long serialVersionUID = 20151011L;
27
28
29
30
31
32
33
34 public LinearUnit(final String abbreviationKey, final UnitSystem unitSystem)
35 {
36 super(abbreviationKey, unitSystem);
37 }
38
39
40
41
42
43
44
45
46
47 protected LinearUnit(final String abbreviationKey, final UnitSystem unitSystem, final U referenceUnit,
48 final double scaleFactorToReferenceUnit)
49 {
50 super(abbreviationKey, unitSystem, referenceUnit == null ? StandardScale.SCALE
51 : new LinearScale(referenceUnit.getScale().getConversionFactorToStandardUnit() * scaleFactorToReferenceUnit));
52 }
53
54
55
56
57
58
59
60 protected LinearUnit(final String abbreviationKey, final UnitSystem unitSystem, final Scale scale)
61 {
62 super(abbreviationKey, unitSystem, scale);
63 }
64
65
66
67
68
69
70
71 public LinearUnit(final String name, final String abbreviation, final UnitSystem unitSystem)
72 {
73 super(name, abbreviation, unitSystem);
74 }
75
76
77
78
79
80
81
82
83
84
85 protected LinearUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final U referenceUnit,
86 final double scaleFactorToReferenceUnit)
87 {
88 super(name, abbreviation, unitSystem, referenceUnit == null ? StandardScale.SCALE
89 : new LinearScale(referenceUnit.getScale().getConversionFactorToStandardUnit() * scaleFactorToReferenceUnit));
90 }
91
92
93
94
95
96
97
98
99 protected LinearUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final Scale scale)
100 {
101 super(name, abbreviation, unitSystem, scale);
102 }
103
104
105 @Override
106 @SuppressWarnings("checkstyle:designforextension")
107 public LinearScale getScale()
108 {
109 return (LinearScale) super.getScale();
110 }
111
112
113
114
115 public final double getScaleFactor()
116 {
117 return getScale().getConversionFactorToStandardUnit();
118 }
119
120
121 @Override
122 public int hashCode()
123 {
124 final int prime = 31;
125 int result = super.hashCode();
126 long temp;
127 temp = Double.doubleToLongBits(this.getScaleFactor());
128 result = prime * result + (int) (temp ^ (temp >>> 32));
129 return result;
130 }
131
132
133 @SuppressWarnings("checkstyle:needbraces")
134 @Override
135 public boolean equals(final Object obj)
136 {
137 if (this == obj)
138 return true;
139 if (!super.equals(obj))
140 return false;
141 if (getClass() != obj.getClass())
142 return false;
143 LinearUnit<?> other = (LinearUnit<?>) obj;
144 if (Double.doubleToLongBits(this.getScaleFactor()) != Double.doubleToLongBits(other.getScaleFactor()))
145 return false;
146 return true;
147 }
148
149
150 @SuppressWarnings("checkstyle:needbraces")
151 @Override
152 public boolean equalsIgnoreNaming(final Object obj)
153 {
154 if (this == obj)
155 return true;
156 if (getClass() != obj.getClass())
157 return false;
158 LinearUnit<?> other = (LinearUnit<?>) obj;
159 if (Double.doubleToLongBits(getScaleFactor()) != Double.doubleToLongBits(other.getScaleFactor()))
160 return false;
161 return true;
162 }
163
164 }