1 package org.djunits.unit.scale;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 public class LinearScale implements Scale
19 {
20
21 private static final long serialVersionUID = 1L;
22
23
24 private final double conversionFactorToStandardUnit;
25
26
27
28
29
30
31 public LinearScale(final double conversionFactorToStandardUnit)
32 {
33 super();
34 this.conversionFactorToStandardUnit = conversionFactorToStandardUnit;
35 }
36
37
38 @SuppressWarnings("checkstyle:designforextension")
39 @Override
40 public double toStandardUnit(final double value)
41 {
42 return value * this.conversionFactorToStandardUnit;
43 }
44
45
46 @SuppressWarnings("checkstyle:designforextension")
47 @Override
48 public double fromStandardUnit(final double value)
49 {
50 return value / this.conversionFactorToStandardUnit;
51 }
52
53
54
55
56 public final double getConversionFactorToStandardUnit()
57 {
58 return this.conversionFactorToStandardUnit;
59 }
60
61
62 @Override
63 @SuppressWarnings("checkstyle:designforextension")
64 public boolean isBaseSIScale()
65 {
66 return this.conversionFactorToStandardUnit == 1.0;
67 }
68
69
70 @Override
71 public int hashCode()
72 {
73 final int prime = 31;
74 int result = 1;
75 long temp;
76 temp = Double.doubleToLongBits(this.conversionFactorToStandardUnit);
77 result = prime * result + (int) (temp ^ (temp >>> 32));
78 return result;
79 }
80
81
82 @SuppressWarnings("checkstyle:needbraces")
83 @Override
84 public boolean equals(final Object obj)
85 {
86 if (this == obj)
87 return true;
88 if (obj == null)
89 return false;
90 if (getClass() != obj.getClass())
91 return false;
92 LinearScale other = (LinearScale) obj;
93 if (Double.doubleToLongBits(this.conversionFactorToStandardUnit) != Double
94 .doubleToLongBits(other.conversionFactorToStandardUnit))
95 return false;
96 return true;
97 }
98
99 }