# HG changeset patch # User Felix Wolfsteller # Date 1317131193 0 # Node ID 3e7717b6e2bc1db436be11e4a8d2637f8275ad2d # Parent ea9a73782de4594cb035df40f97da0d987ed0c97 Implement equals und hashCode for Recommendation and associates. flys-client/trunk@2841 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ea9a73782de4 -r 3e7717b6e2bc flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Sep 27 13:27:08 2011 +0000 +++ b/flys-client/ChangeLog Tue Sep 27 13:46:33 2011 +0000 @@ -1,3 +1,12 @@ +2011-09-27 Felix Wolfsteller + + Implement equals and hashCode for Recommendation, Recommendation.Facet + and Recommendation.Filter . + + * src/main/java/de/intevation/flys/client/shared/model/Recommendation.java + (equals, hashCode, Filter.equals, Filter.hashCode, Facet.equals) + (Facet.hashCode): New. + 2011-09-27 Ingo Weinzierl flys/issue321 (ÜSK: Aktualisieren der Parameterliste nach Beendigung der Berechnung) diff -r ea9a73782de4 -r 3e7717b6e2bc flys-client/src/main/java/de/intevation/flys/client/shared/model/Recommendation.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Recommendation.java Tue Sep 27 13:27:08 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Recommendation.java Tue Sep 27 13:46:33 2011 +0000 @@ -12,6 +12,7 @@ */ public class Recommendation implements Serializable { + /** Index and name of a facet. */ public static class Facet implements Serializable { protected String name; @@ -32,8 +33,34 @@ public String getIndex() { return index; } + + + @Override + public int hashCode() { + int hash = 0; + if (getName() != null) { + hash += getName().hashCode(); + } + if (getIndex() != null) { + hash += getIndex().hashCode(); + } + return hash; + } + + + @Override + public boolean equals(Object other) { + if (!(other instanceof Facet) || other == null) { + return false; + } + Facet facet = (Facet) other; + return (same(facet.getIndex(), this.getIndex())) + && (same(facet.getName(), this.getName())); + } } // class Facet + + /** Mapping of outnames to Facet-Lists. */ public static class Filter implements Serializable { protected Map> outs; @@ -49,6 +76,25 @@ public Map> getOuts() { return outs; } + + + @Override + public int hashCode() { + if (getOuts() != null) { + return getOuts().hashCode(); + } + return 0; + } + + + @Override + public boolean equals(Object other) { + if (!(other instanceof Filter) || other == null) { + return false; + } + Filter filter = (Filter) other; + return Recommendation.same(filter.getOuts(), this.getOuts()); + } } // class Filter protected String factory; @@ -98,5 +144,55 @@ public void setFilter(Filter filter) { this.filter = filter; } + + + @Override + public int hashCode() { + int hash = 0; + hash += (getFactory() != null) + ? getFactory().hashCode() + : 0; + hash += (getIDs() != null) + ? getIDs().hashCode() + : 0; + hash += (getFilter() != null) + ? getFilter().hashCode() + : 0; + hash += (getMasterArtifact() != null) + ? getMasterArtifact().hashCode() + : 0; + return hash; + } + + + /** + * Null-pointer guarded equals. + * Two null's are assumed equal (returns true); + * @param a Object to compare against parameter b. + * @param b Object to compare against parameter a. + * @return true if either a and b are null or a.equals(b) returns true. + */ + protected static boolean same(Object a, Object b) { + // Do null-check. + if (a == null) { + return b == null; + } else if (b == null) { + return false; + } + return a.equals(b); + } + + + @Override + public boolean equals(Object other) { + if (!(other instanceof Recommendation) || other == null) { + return false; + } + Recommendation rec = (Recommendation) other; + return (same(this.getFactory(), rec.getFactory())) + && (same(this.getIDs(), rec.getIDs())) + && (same(this.getFilter(), rec.getFilter())) + && (same(this.getMasterArtifact(), rec.getMasterArtifact())); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :