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 final double conversionFactorToStandardUnit;
22
23
24
25
26
27
28 public LinearScale(final double conversionFactorToStandardUnit)
29 {
30 super();
31 this.conversionFactorToStandardUnit = conversionFactorToStandardUnit;
32 }
33
34
35 @SuppressWarnings("checkstyle:designforextension")
36 @Override
37 public double toStandardUnit(final double value)
38 {
39 return value * this.conversionFactorToStandardUnit;
40 }
41
42
43 @SuppressWarnings("checkstyle:designforextension")
44 @Override
45 public double fromStandardUnit(final double value)
46 {
47 return value / this.conversionFactorToStandardUnit;
48 }
49
50
51
52
53 public final double getConversionFactorToStandardUnit()
54 {
55 return this.conversionFactorToStandardUnit;
56 }
57
58
59 @Override
60 @SuppressWarnings("checkstyle:designforextension")
61 public boolean isBaseSIScale()
62 {
63 return this.conversionFactorToStandardUnit == 1.0;
64 }
65
66
67 @Override
68 public int hashCode()
69 {
70 final int prime = 31;
71 int result = 1;
72 long temp;
73 temp = Double.doubleToLongBits(this.conversionFactorToStandardUnit);
74 result = prime * result + (int) (temp ^ (temp >>> 32));
75 return result;
76 }
77
78
79 @SuppressWarnings("checkstyle:needbraces")
80 @Override
81 public boolean equals(final Object obj)
82 {
83 if (this == obj)
84 return true;
85 if (obj == null)
86 return false;
87 if (getClass() != obj.getClass())
88 return false;
89 LinearScale other = (LinearScale) obj;
90 if (Double.doubleToLongBits(this.conversionFactorToStandardUnit) != Double
91 .doubleToLongBits(other.conversionFactorToStandardUnit))
92 return false;
93 return true;
94 }
95
96 }