Skip to content

Instantly share code, notes, and snippets.

@cquinn
Created August 14, 2012 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cquinn/3351017 to your computer and use it in GitHub Desktop.
Save cquinn/3351017 to your computer and use it in GitHub Desktop.
Extended Groovy Expando class that has equals and hashCode
// Experimental object that could hold general report results.
class Expandy extends Expando {
boolean equals(Object o) {
if (getProperties().size() != o.getProperties().size()) return false
for (def i = getProperties().entrySet().iterator(); i.hasNext(); ) {
def e = i.next()
if (!o.getProperties().containsKey(e.getKey())) return false
def ov = o.getProperty(e.getKey())
if (ov != e.getValue()) return false
}
return true
}
int hashCode() {
int hc = 29
for (def i = getProperties().entrySet().iterator(); i.hasNext(); ) {
def e = i.next()
hc = 13*hc + e.hashCode()
}
return hc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment