summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/unit/LinearUnit.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnits/unit/LinearUnit.java')
-rw-r--r--src/main/java/sevenUnits/unit/LinearUnit.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main/java/sevenUnits/unit/LinearUnit.java b/src/main/java/sevenUnits/unit/LinearUnit.java
index 3c3703c..d453a43 100644
--- a/src/main/java/sevenUnits/unit/LinearUnit.java
+++ b/src/main/java/sevenUnits/unit/LinearUnit.java
@@ -227,6 +227,19 @@ public final class LinearUnit extends Unit {
return false;
final LinearUnit other = (LinearUnit) obj;
return Objects.equals(this.getBase(), other.getBase())
+ && Double.compare(this.getConversionFactor(),
+ other.getConversionFactor()) == 0;
+ }
+
+ /**
+ * @return true iff this unit and other are equal,
+ * ignoring small differences caused by floating-point error.
+ *
+ * @apiNote This method is not transitive,
+ * so it cannot be used as an equals method.
+ */
+ public boolean equalsApproximately(final LinearUnit other) {
+ return Objects.equals(this.getBase(), other.getBase())
&& DecimalComparison.equals(this.getConversionFactor(),
other.getConversionFactor());
}
@@ -247,7 +260,7 @@ public final class LinearUnit extends Unit {
@Override
public int hashCode() {
return 31 * this.getBase().hashCode()
- + DecimalComparison.hash(this.getConversionFactor());
+ + Double.hashCode(this.getConversionFactor());
}
/**