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/BaseUnit.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/unitConverter/unit/BaseUnit.java') 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. * -- cgit v1.2.3