Package org.springframework.hateoas
Class PagedModel<T>
java.lang.Object
org.springframework.hateoas.RepresentationModel<CollectionModel<T>>
org.springframework.hateoas.CollectionModel<T>
org.springframework.hateoas.PagedModel<T>
- All Implemented Interfaces:
Iterable<T>
,ResolvableTypeProvider
DTO to implement binding response representations of pageable collections.
- Author:
- Oliver Gierke, Greg Turnquist
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Value object for pagination metadata. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor to allow instantiation by reflection.protected
PagedModel
(Collection<T> content, PagedModel.PageMetadata metadata) protected
PagedModel
(Collection<T> content, PagedModel.PageMetadata metadata, Iterable<Link> links) protected
PagedModel
(Collection<T> content, PagedModel.PageMetadata metadata, Iterable<Link> links, ResolvableType fallbackType) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> PagedModel<T>
empty()
Creates an emptyPagedModel
.static <T> PagedModel<T>
Creates an emptyPagedModel
with the given fallback type.static <T> PagedModel<T>
Creates an emptyPagedModel
with the given links.static <T> PagedModel<T>
empty
(ParameterizedTypeReference<T> fallbackElementType) Creates an emptyPagedModel
with the given fallback type.static <T> PagedModel<T>
empty
(ResolvableType fallbackElementType) Creates an emptyPagedModel
with the given fallback type.static <T> PagedModel<T>
Creates an emptyPagedModel
with the given links.static <T> PagedModel<T>
empty
(PagedModel.PageMetadata metadata) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
.static <T> PagedModel<T>
empty
(PagedModel.PageMetadata metadata, Class<?> fallbackType, Class<?>... generics) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and fallback type.static <T> PagedModel<T>
empty
(PagedModel.PageMetadata metadata, Iterable<Link> links) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and links.static <T> PagedModel<T>
empty
(PagedModel.PageMetadata metadata, ParameterizedTypeReference<T> fallbackType) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and fallback type.static <T> PagedModel<T>
empty
(PagedModel.PageMetadata metadata, ResolvableType fallbackType) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and fallback type.static <T> PagedModel<T>
empty
(PagedModel.PageMetadata metadata, Link... links) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and links.boolean
Returns the pagination metadata.Returns the Link pointing to the next page (if set).Returns the Link pointing to the previous page (if set).int
hashCode()
static <T> PagedModel<T>
of
(Collection<T> content, PagedModel.PageMetadata metadata) static <T> PagedModel<T>
of
(Collection<T> content, PagedModel.PageMetadata metadata, Iterable<Link> links) static <T> PagedModel<T>
of
(Collection<T> content, PagedModel.PageMetadata metadata, Link... links) toString()
withFallbackType
(Class<? super T> type, Class<?>... generics) Declares the given type as fallback element type in case the underlying collection is empty.Declares the given type as fallback element type in case the underlying collection is empty.Declares the given type as fallback element type in case the underlying collection is empty.static <T extends EntityModel<S>,
S>
PagedModel<T>wrap
(Iterable<S> content, PagedModel.PageMetadata metadata) Factory method to easily create aPagedModel
instance from a set of entities and pagination metadata.Methods inherited from class org.springframework.hateoas.CollectionModel
empty, getContent, getResolvableType, iterator, of, of, of, wrap
Methods inherited from class org.springframework.hateoas.RepresentationModel
add, add, add, addAllIf, addIf, getLink, getLink, getLinks, getLinks, getLinks, getRequiredLink, getRequiredLink, hasLink, hasLink, hasLinks, mapLink, mapLinkIf, of, of, removeLinks
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
NO_PAGE
-
-
Constructor Details
-
PagedModel
protected PagedModel()Default constructor to allow instantiation by reflection. -
PagedModel
-
PagedModel
protected PagedModel(Collection<T> content, @Nullable PagedModel.PageMetadata metadata, Iterable<Link> links) -
PagedModel
protected PagedModel(Collection<T> content, @Nullable PagedModel.PageMetadata metadata, Iterable<Link> links, @Nullable ResolvableType fallbackType)
-
-
Method Details
-
empty
Creates an emptyPagedModel
.- Type Parameters:
T
-- Returns:
- will never be null.
- Since:
- 1.1
-
empty
Creates an emptyPagedModel
with the given fallback type.- Type Parameters:
T
-- Parameters:
fallbackElementType
- must not be null.generics
- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
- See Also:
-
empty
Creates an emptyPagedModel
with the given fallback type.- Type Parameters:
T
-- Parameters:
fallbackElementType
- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
- See Also:
-
empty
Creates an emptyPagedModel
with the given fallback type.- Type Parameters:
T
-- Parameters:
fallbackElementType
- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
- See Also:
-
empty
Creates an emptyPagedModel
with the given links.- Type Parameters:
T
-- Parameters:
links
- must not be null.- Returns:
- Since:
- 1.1
-
empty
Creates an emptyPagedModel
with the given links.- Type Parameters:
T
-- Parameters:
links
- must not be null.- Returns:
- Since:
- 1.1
-
empty
Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
.- Type Parameters:
T
-- Parameters:
metadata
- can be null.- Returns:
- Since:
- 1.1
-
empty
public static <T> PagedModel<T> empty(@Nullable PagedModel.PageMetadata metadata, Class<?> fallbackType, Class<?>... generics) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and fallback type.- Type Parameters:
T
-- Parameters:
metadata
- can be null.fallbackType
- must not be null.generics
- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
- See Also:
-
empty
public static <T> PagedModel<T> empty(@Nullable PagedModel.PageMetadata metadata, ParameterizedTypeReference<T> fallbackType) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and fallback type.- Type Parameters:
T
-- Parameters:
metadata
- can be null.- Returns:
- Since:
- 1.4
- See Also:
-
empty
public static <T> PagedModel<T> empty(@Nullable PagedModel.PageMetadata metadata, ResolvableType fallbackType) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and fallback type.- Type Parameters:
T
-- Parameters:
metadata
- can be null.fallbackType
- must not be null.- Returns:
- Since:
- 1.4
- See Also:
-
empty
Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and links.- Type Parameters:
T
-- Parameters:
metadata
- can be null.links
- must not be null.- Returns:
- Since:
- 1.1
-
empty
public static <T> PagedModel<T> empty(@Nullable PagedModel.PageMetadata metadata, Iterable<Link> links) Creates an emptyPagedModel
with the givenPagedModel.PageMetadata
and links.- Type Parameters:
T
-- Parameters:
metadata
- can be null.links
- must not be null.- Returns:
- Since:
- 1.1
-
of
public static <T> PagedModel<T> of(Collection<T> content, @Nullable PagedModel.PageMetadata metadata) - Parameters:
content
- must not be null.metadata
- can be null.- Returns:
- will never be null.
-
of
public static <T> PagedModel<T> of(Collection<T> content, @Nullable PagedModel.PageMetadata metadata, Link... links) - Parameters:
content
- must not be null.metadata
- can be null.links
- must not be null.- Returns:
- will never be null.
-
of
public static <T> PagedModel<T> of(Collection<T> content, @Nullable PagedModel.PageMetadata metadata, Iterable<Link> links) - Parameters:
content
- must not be null.metadata
- can be null.links
- must not be null.
-
getMetadata
Returns the pagination metadata.- Returns:
- the metadata
-
wrap
public static <T extends EntityModel<S>,S> PagedModel<T> wrap(Iterable<S> content, PagedModel.PageMetadata metadata) Factory method to easily create aPagedModel
instance from a set of entities and pagination metadata.- Parameters:
content
- must not be null.metadata
-- Returns:
-
getNextLink
Returns the Link pointing to the next page (if set).- Returns:
-
getPreviousLink
Returns the Link pointing to the previous page (if set).- Returns:
-
withFallbackType
Description copied from class:CollectionModel
Declares the given type as fallback element type in case the underlying collection is empty. This allows client components to still apply type matches at runtime.- Overrides:
withFallbackType
in classCollectionModel<T>
- Parameters:
type
- must not be null.- Returns:
- will never be null.
-
withFallbackType
Description copied from class:CollectionModel
Declares the given type as fallback element type in case the underlying collection is empty. This allows client components to still apply type matches at runtime.- Overrides:
withFallbackType
in classCollectionModel<T>
- Parameters:
type
- must not be null.- Returns:
- will never be null.
-
withFallbackType
Description copied from class:CollectionModel
Declares the given type as fallback element type in case the underlying collection is empty. This allows client components to still apply type matches at runtime.- Overrides:
withFallbackType
in classCollectionModel<T>
- Parameters:
type
- must not be null.- Returns:
- will never be null.
-
toString
- Overrides:
toString
in classCollectionModel<T>
-
equals
- Overrides:
equals
in classCollectionModel<T>
-
hashCode
public int hashCode()- Overrides:
hashCode
in classCollectionModel<T>
-