Polished Resources abstraction.
Added correct equals(…)/hashCode() methods to PagedResource, PageMetadata. Polished toString() methods of ResourceSupport, Resource, Resources and PagedResources. Added factory method to PagedResources to easily create a plain instance from a set of entities.
This commit is contained in:
@@ -33,7 +33,7 @@ import org.springframework.util.Assert;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@XmlRootElement(name = "entities")
|
||||
public class Resources<T extends Resource<?>> extends ResourceSupport implements Iterable<T> {
|
||||
public class Resources<T> extends ResourceSupport implements Iterable<T> {
|
||||
|
||||
@XmlAnyElement
|
||||
@XmlElementWrapper
|
||||
@@ -69,7 +69,7 @@ public class Resources<T extends Resource<?>> extends ResourceSupport implements
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Resource<S>, S> Resources<T> fromEntities(Collection<S> content) {
|
||||
public static <T extends Resource<S>, S> Resources<T> fromEntities(Iterable<S> content) {
|
||||
|
||||
Assert.notNull(content);
|
||||
ArrayList<T> resources = new ArrayList<T>();
|
||||
@@ -82,7 +82,7 @@ public class Resources<T extends Resource<?>> extends ResourceSupport implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying {@link Resource}s.
|
||||
* Returns the underlying elements.
|
||||
*
|
||||
* @return the content will never be {@literal null}.
|
||||
*/
|
||||
@@ -99,6 +99,15 @@ public class Resources<T extends Resource<?>> extends ResourceSupport implements
|
||||
return content.iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceSupport#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Resources { content: %s, %s }", getContent(), super.toString());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceSupport#equals(java.lang.Object)
|
||||
@@ -132,5 +141,4 @@ public class Resources<T extends Resource<?>> extends ResourceSupport implements
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user