diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2025-05-30 20:10:09 -0500 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2025-05-30 20:30:44 -0500 |
commit | 7db19d307970b73559239ec343c92c7876510c2a (patch) | |
tree | 8b5515e50178e9c683931606745899e33e33ce23 /src/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java | |
parent | 4ff3a48a659aec957c5496923a79c4487d9062ec (diff) |
Ensure LinearUnit&Prefix ==/hash obey contracts
Previously, these classes' equals() and hashCode() methods did not obey
the contracts:
For equals(), I considered two values equal even if there was a very
small deviation, in order to avoid floating-point error. This equals
relation is not transitive (i.e. it is possible that a = b && b = c but
a ≠ c), violating the contract of equals.
This also makes it impossible to properly implement hashCode, as if two
values are equal, they must have the same hash code. The solution I had
provided is an ineffective hack, which could mess with hash maps and
sets.
I have changed the implementation to demand exact equality. I have also
provided equalsApproximately() methods to both classes that use the old
behaviour. Hash codes are only really used for hash maps, and the old
implementation doesn't even achieve its purpose, so I did not add a
method to return the old hash behaviour.
Diffstat (limited to 'src/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java')
0 files changed, 0 insertions, 0 deletions