#1241 - Additional factory methods for CollectionModel and PagedModel.

Added overloads of ….empty() to allow adding links right on construction.
This commit is contained in:
Oliver Drotbohm
2020-03-27 14:52:19 +01:00
parent 8f98519e07
commit 6c09839cca
2 changed files with 77 additions and 2 deletions

View File

@@ -81,11 +81,36 @@ public class CollectionModel<T> extends RepresentationModel<CollectionModel<T>>
*
* @param <T>
* @return
* @since 1.1
*/
public static <T> CollectionModel<T> empty() {
return of(Collections.emptyList());
}
/**
* Creates a new empty collection model with the given links.
*
* @param <T>
* @param links must not be {@literal null}.
* @return
* @since 1.1
*/
public static <T> CollectionModel<T> empty(Link... links) {
return of(Collections.emptyList(), links);
}
/**
* Creates a new empty collection model with the given links.
*
* @param <T>
* @param links must not be {@literal null}.
* @return
* @since 1.1
*/
public static <T> CollectionModel<T> empty(Iterable<Link> links) {
return of(Collections.emptyList(), links);
}
/**
* Creates a {@link CollectionModel} instance with the given content.
*

View File

@@ -83,7 +83,31 @@ public class PagedModel<T> extends CollectionModel<T> {
* @since 1.1
*/
public static <T> PagedModel<T> empty() {
return empty(null);
return empty(Collections.emptyList());
}
/**
* Creates an empty {@link PagedModel} with the given links.
*
* @param <T>
* @param links must not be {@literal null}.
* @return
* @since 1.1
*/
public static <T> PagedModel<T> empty(Link... links) {
return empty((PageMetadata) null, links);
}
/**
* Creates an empty {@link PagedModel} with the given links.
*
* @param <T>
* @param links must not be {@literal null}.
* @return
* @since 1.1
*/
public static <T> PagedModel<T> empty(Iterable<Link> links) {
return empty((PageMetadata) null, links);
}
/**
@@ -95,7 +119,33 @@ public class PagedModel<T> extends CollectionModel<T> {
* @since 1.1
*/
public static <T> PagedModel<T> 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 <T>
* @param metadata can be {@literal null}.
* @param links must not be {@literal null}.
* @return
* @since 1.1
*/
public static <T> PagedModel<T> empty(@Nullable PageMetadata metadata, Link... links) {
return empty(Arrays.asList(links));
}
/**
* Creates an empty {@link PagedModel} with the given {@link PageMetadata} and links.
*
* @param <T>
* @param metadata can be {@literal null}.
* @param links must not be {@literal null}.
* @return
* @since 1.1
*/
public static <T> PagedModel<T> empty(@Nullable PageMetadata metadata, Iterable<Link> links) {
return of(Collections.emptyList(), metadata, links);
}
/**