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