1 package org.djunits.unit.scale;
2
3 import org.djutils.exceptions.Throw;
4
5
6
7
8
9
10
11
12
13
14
15 public class GradeScale implements Scale
16 {
17
18 private static final long serialVersionUID = 20151011L;
19
20
21 private final double conversionFactorToGrade;
22
23
24
25
26
27
28 public GradeScale(final double conversionFactorToGrade)
29 {
30 Throw.when(conversionFactorToGrade == 0.0 || !Double.isFinite(conversionFactorToGrade), IllegalArgumentException.class,
31 "conversion factor for grade scale cannnot be 0, NaN or infinity");
32 this.conversionFactorToGrade = conversionFactorToGrade;
33 }
34
35 @Override
36 public final double toBaseValue(final double value)
37 {
38 return Math.atan(value * this.conversionFactorToGrade);
39 }
40
41 @Override
42 public final double fromBaseValue(final double value)
43 {
44 return Math.tan(value) / this.conversionFactorToGrade;
45 }
46
47
48
49
50 public final double getConversionFactorToGrade()
51 {
52 return this.conversionFactorToGrade;
53 }
54
55 @Override
56 public boolean isBaseScale()
57 {
58 return false;
59 }
60
61 @Override
62 public int hashCode()
63 {
64 final int prime = 31;
65 int result = 1;
66 long temp;
67 temp = Double.doubleToLongBits(this.conversionFactorToGrade);
68 result = prime * result + (int) (temp ^ (temp >>> 32));
69 return result;
70 }
71
72 @SuppressWarnings("checkstyle:needbraces")
73 @Override
74 public boolean equals(final Object obj)
75 {
76 if (this == obj)
77 return true;
78 if (obj == null)
79 return false;
80 if (getClass() != obj.getClass())
81 return false;
82 GradeScale other = (GradeScale) obj;
83 if (Double.doubleToLongBits(this.conversionFactorToGrade) != Double.doubleToLongBits(other.conversionFactorToGrade))
84 return false;
85 return true;
86 }
87
88 @Override
89 public String toString()
90 {
91 return "GradeScale [conversionFactorToGrade=" + this.conversionFactorToGrade + "]";
92 }
93
94 }