#9 - Added constructors taking Iterable<Link> to resource abstractions.

This commit is contained in:
Oliver Gierke
2012-08-23 23:57:13 +02:00
parent 7646e11a26
commit a4bf7fb4bf
3 changed files with 37 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.hateoas;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import javax.xml.bind.annotation.XmlAttribute;
@@ -46,13 +47,24 @@ public class PagedResources<T> extends Resources<T> {
}
/**
* Creates a new {@link PagedResources} from the given content and {@link PageMetadata}.
* Creates a new {@link PagedResources} from the given content, {@link PageMetadata} and {@link Link}s (optional).
*
* @param content must not be {@literal null}.
* @param metadata
* @param links
*/
public PagedResources(Collection<T> content, PageMetadata metadata, Link... links) {
this(content, metadata, Arrays.asList(links));
}
/**
* Creates a new {@link PagedResources} from the given content {@link PageMetadata} and {@link Link}s.
*
* @param content must not be {@literal null}.
* @param metadata
* @param links
*/
public PagedResources(Collection<T> content, PageMetadata metadata, Iterable<Link> links) {
super(content, links);
this.metadata = metadata;
}

View File

@@ -41,16 +41,26 @@ public class Resource<T> extends ResourceSupport {
}
/**
* Creates a new {@link Resource} with the given content.
* Creates a new {@link Resource} with the given content and {@link Link}s (optional).
*
* @param content must not be {@literal null}.
* @param links the links to add to the {@link Resource}.
*/
public Resource(T content, Link... links) {
this(content, Arrays.asList(links));
}
/**
* Creates a new {@link Resource} with the given content and {@link Link}s.
*
* @param content must not be {@literal null}.
* @param links the links to add to the {@link Resource}.
*/
public Resource(T content, Iterable<Link> links) {
Assert.notNull(content, "Content must not be null!");
this.content = content;
this.add(Arrays.asList(links));
this.add(links);
}
/**

View File

@@ -48,18 +48,28 @@ public class Resources<T> extends ResourceSupport implements Iterable<T> {
}
/**
* Creates a {@link Resources} instance with the given content.
* Creates a {@link Resources} instance with the given content and {@link Link}s (optional).
*
* @param content must not be {@literal null}.
* @param links the links to be added to the {@link Resources}.
*/
public Resources(Collection<T> content, Link... links) {
this(content, Arrays.asList(links));
}
/**
* Creates a {@link Resources} instance with the given content and {@link Link}s.
*
* @param content must not be {@literal null}.
* @param links the links to be added to the {@link Resources}.
*/
public Resources(Collection<T> content, Iterable<Link> links) {
Assert.notNull(content);
this.content = new ArrayList<T>();
this.content.addAll(content);
this.add(Arrays.asList(links));
this.add(links);
}
/**