diff --git a/src/main/java/org/springframework/hateoas/CollectionModel.java b/src/main/java/org/springframework/hateoas/CollectionModel.java index b0b8512a..21b8cf1e 100644 --- a/src/main/java/org/springframework/hateoas/CollectionModel.java +++ b/src/main/java/org/springframework/hateoas/CollectionModel.java @@ -81,11 +81,36 @@ public class CollectionModel extends RepresentationModel> * * @param * @return + * @since 1.1 */ public static CollectionModel empty() { return of(Collections.emptyList()); } + /** + * Creates a new empty collection model with the given links. + * + * @param + * @param links must not be {@literal null}. + * @return + * @since 1.1 + */ + public static CollectionModel empty(Link... links) { + return of(Collections.emptyList(), links); + } + + /** + * Creates a new empty collection model with the given links. + * + * @param + * @param links must not be {@literal null}. + * @return + * @since 1.1 + */ + public static CollectionModel empty(Iterable links) { + return of(Collections.emptyList(), links); + } + /** * Creates a {@link CollectionModel} instance with the given content. * diff --git a/src/main/java/org/springframework/hateoas/PagedModel.java b/src/main/java/org/springframework/hateoas/PagedModel.java index b6d61922..0456a2ca 100644 --- a/src/main/java/org/springframework/hateoas/PagedModel.java +++ b/src/main/java/org/springframework/hateoas/PagedModel.java @@ -83,7 +83,31 @@ public class PagedModel extends CollectionModel { * @since 1.1 */ public static PagedModel empty() { - return empty(null); + return empty(Collections.emptyList()); + } + + /** + * Creates an empty {@link PagedModel} with the given links. + * + * @param + * @param links must not be {@literal null}. + * @return + * @since 1.1 + */ + public static PagedModel empty(Link... links) { + return empty((PageMetadata) null, links); + } + + /** + * Creates an empty {@link PagedModel} with the given links. + * + * @param + * @param links must not be {@literal null}. + * @return + * @since 1.1 + */ + public static PagedModel empty(Iterable links) { + return empty((PageMetadata) null, links); } /** @@ -95,7 +119,33 @@ public class PagedModel extends CollectionModel { * @since 1.1 */ public static PagedModel empty(@Nullable PageMetadata metadata) { - return of(Collections.emptyList(), metadata); + return empty(metadata, Collections.emptyList()); + } + + /** + * Creates an empty {@link PagedModel} with the given {@link PageMetadata} and links. + * + * @param + * @param metadata can be {@literal null}. + * @param links must not be {@literal null}. + * @return + * @since 1.1 + */ + public static PagedModel empty(@Nullable PageMetadata metadata, Link... links) { + return empty(Arrays.asList(links)); + } + + /** + * Creates an empty {@link PagedModel} with the given {@link PageMetadata} and links. + * + * @param + * @param metadata can be {@literal null}. + * @param links must not be {@literal null}. + * @return + * @since 1.1 + */ + public static PagedModel empty(@Nullable PageMetadata metadata, Iterable links) { + return of(Collections.emptyList(), metadata, links); } /**