From a6a66e6fb11675e0ea738ad8d0b5a9ba7d2fac2b Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 27 Jan 2019 16:05:55 -0500 Subject: HOTFIX: Added equals and hashCode to the unit classes --- src/unitConverter/unit/LinearUnit.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/unitConverter/unit/LinearUnit.java') 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. * -- cgit v1.2.3