#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

@@ -54,4 +54,37 @@ public class Resource<T> extends ResourceSupport {
public T getContent() {
return content;
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceSupport#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || !obj.getClass().equals(getClass())) {
return false;
}
Resource<?> that = (Resource<?>) 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;
}
}