summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2019-01-27 16:05:55 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2019-01-27 16:05:55 -0500
commita6a66e6fb11675e0ea738ad8d0b5a9ba7d2fac2b (patch)
treeb45241f4c56a055148f4a15a47d2d6ff04fd382a
parentff30d9ab06bfc93012b90d24af57505b3d9c70d4 (diff)
HOTFIX: Added equals and hashCode to the unit classes
-rwxr-xr-xsrc/unitConverter/unit/BaseUnit.java18
-rw-r--r--src/unitConverter/unit/LinearUnit.java18
2 files changed, 36 insertions, 0 deletions
diff --git a/src/unitConverter/unit/BaseUnit.java b/src/unitConverter/unit/BaseUnit.java
index d4a1e9c..fe36c45 100755
--- a/src/unitConverter/unit/BaseUnit.java
+++ b/src/unitConverter/unit/BaseUnit.java
@@ -108,6 +108,24 @@ public final class BaseUnit extends AbstractUnit {
return new LinearUnit(this, 1 / divisor);
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof BaseUnit))
+ return false;
+ final BaseUnit other = (BaseUnit) obj;
+ return Objects.equals(this.getSystem(), other.getSystem())
+ && Objects.equals(this.getDimension(), other.getDimension());
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = result * prime + this.getSystem().hashCode();
+ result = result * prime + this.getDimension().hashCode();
+ return result;
+ }
+
/**
* Multiplies this unit by another unit.
*
diff --git a/src/unitConverter/unit/LinearUnit.java b/src/unitConverter/unit/LinearUnit.java
index 6514ff4..b786b3b 100644
--- a/src/unitConverter/unit/LinearUnit.java
+++ b/src/unitConverter/unit/LinearUnit.java
@@ -107,6 +107,15 @@ public final class LinearUnit extends AbstractUnit {
return new LinearUnit(base, this.getConversionFactor() / other.getConversionFactor());
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof LinearUnit))
+ return false;
+ final LinearUnit other = (LinearUnit) obj;
+ return Objects.equals(this.getBase(), other.getBase())
+ && Objects.equals(this.getConversionFactor(), other.getConversionFactor());
+ }
+
/**
* @return conversionFactor
* @since 2018-12-22
@@ -116,6 +125,15 @@ public final class LinearUnit extends AbstractUnit {
return this.conversionFactor;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = result * prime + this.getBase().hashCode();
+ result = result * prime + Double.hashCode(this.getConversionFactor());
+ return result;
+ }
+
/**
* Multiplies this unit by a scalar.
*