From 11948a0091be9574dddf744598dda55f8e9e4353 Mon Sep 17 00:00:00 2001 From: Thomas Oster <thomas.oster@rwth-aachen.de> Date: Thu, 20 Dec 2012 09:26:55 +0100 Subject: [PATCH] DitheringAlgorithm has equals mehtod which respects properties --- .../dithering/DitheringAlgorithm.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java b/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java index c266f96..498cd5e 100644 --- a/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java +++ b/src/com/t_oster/liblasercut/dithering/DitheringAlgorithm.java @@ -80,4 +80,43 @@ public abstract class DitheringAlgorithm extends TimeIntensiveOperation implemen @Override public abstract String toString(); + + @Override + public boolean equals(Object o) + { + if (o == null || !getClass().equals(o.getClass())) + { + return false; + } + final DitheringAlgorithm other = (DitheringAlgorithm) o; + String[] own = this.getPropertyKeys(); + String[] ot = other.getPropertyKeys(); + if (own.length != ot.length) + { + return false; + } + for (int i = 0; i < own.length; i++) + { + String key = own[i]; + if (!key.equals(ot[i])) + { + return false; + } + else if (!getProperty(key).equals(other.getProperty(key))) + { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + for (String key : this.getPropertyKeys()) + { + hash += this.getProperty(key).hashCode(); + } + return hash; + } } -- GitLab