#5 - Added equals(…) / hashCode() to Resource/Resources.

This commit is contained in:
Oliver Gierke
2012-08-22 18:33:35 +02:00
parent bc09140769
commit 6c368faa0e
4 changed files with 208 additions and 0 deletions

View File

@@ -95,4 +95,39 @@ public class Resources<T extends Resource<?>> extends ResourceSupport implements
public Iterator<T> iterator() {
return content.iterator();
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceSupport#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !obj.getClass().equals(getClass())) {
return false;
}
Resources<?> that = (Resources<?>) obj;
boolean contentEqual = this.content == null ? that.content == null : this.content.equals(that.content);
return contentEqual ? super.equals(obj) : false;
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceSupport#hashCode()
*/
@Override
public int hashCode() {
int result = super.hashCode();
result += content == null ? 0 : 17 * content.hashCode();
return result;
}
}