Package org.springframework.hateoas
Class SlicedModel<T>
java.lang.Object
org.springframework.hateoas.RepresentationModel<CollectionModel<T>>
org.springframework.hateoas.CollectionModel<T>
org.springframework.hateoas.SlicedModel<T>
- All Implemented Interfaces:
Iterable<T>
,ResolvableTypeProvider
DTO to implement binding response representations of Slice collections.
- Since:
- 2.1
- Author:
- Michael Schout, Oliver Drotbohm
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Value object for slice metadata. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor to allow instantiation by reflection.protected
SlicedModel
(Collection<T> content, SlicedModel.SliceMetadata metadata) protected
SlicedModel
(Collection<T> content, SlicedModel.SliceMetadata metadata, Iterable<Link> links) protected
SlicedModel
(Collection<T> content, SlicedModel.SliceMetadata metadata, Iterable<Link> links, ResolvableType fallbackType) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SlicedModel<T>
empty()
Creates an emptySlicedModel
.static <T> SlicedModel<T>
Creates an emptySlicedModel
with the given fallback type.static <T> SlicedModel<T>
Creates an emptySlicedModel
with the given links.static <T> SlicedModel<T>
empty
(ParameterizedTypeReference<T> fallbackElementType) Creates an emptySlicedModel
with the given fallback type.static <T> SlicedModel<T>
empty
(ResolvableType fallbackElementType) Creates an emptySlicedModel
with the given fallback type.static <T> SlicedModel<T>
Creates an emptySlicedModel
with the given links.static <T> SlicedModel<T>
empty
(SlicedModel.SliceMetadata metadata) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
.static <T> SlicedModel<T>
empty
(SlicedModel.SliceMetadata metadata, Class<?> fallbackType, Class<?>... generics) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and fallback type.static <T> SlicedModel<T>
empty
(SlicedModel.SliceMetadata metadata, Iterable<Link> links) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and links.static <T> SlicedModel<T>
empty
(SlicedModel.SliceMetadata metadata, ParameterizedTypeReference<T> fallbackType) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and fallback type.static <T> SlicedModel<T>
empty
(SlicedModel.SliceMetadata metadata, ResolvableType fallbackType) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and fallback type.static <T> SlicedModel<T>
empty
(SlicedModel.SliceMetadata metadata, Link... links) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and links.boolean
Returns the pagination metadata.Returns theLink
pointing to the next slice (if set).Returns theLink
pointing to the previous slice (if set).int
hashCode()
static <T> SlicedModel<T>
of
(Collection<T> content, SlicedModel.SliceMetadata metadata) static <T> SlicedModel<T>
of
(Collection<T> content, SlicedModel.SliceMetadata metadata, Iterable<Link> links) static <T> SlicedModel<T>
of
(Collection<T> content, SlicedModel.SliceMetadata 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>
SlicedModel<T>wrap
(Iterable<S> content, SlicedModel.SliceMetadata metadata) Factory method to easily create aSlicedModel
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_SLICE
-
-
Constructor Details
-
SlicedModel
protected SlicedModel()Default constructor to allow instantiation by reflection. -
SlicedModel
-
SlicedModel
protected SlicedModel(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links) -
SlicedModel
protected SlicedModel(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links, @Nullable ResolvableType fallbackType)
-
-
Method Details
-
empty
Creates an emptySlicedModel
.- Type Parameters:
T
- the payload type.- Returns:
- will never be null.
-
empty
Creates an emptySlicedModel
with the given fallback type.- Type Parameters:
T
- the payload type.- Parameters:
fallbackElementType
- must not be null.generics
- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
Creates an emptySlicedModel
with the given fallback type.- Type Parameters:
T
- the payload type.- Parameters:
fallbackElementType
- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
Creates an emptySlicedModel
with the given fallback type.- Type Parameters:
T
- the payload type.- Parameters:
fallbackElementType
- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
Creates an emptySlicedModel
with the given links.- Type Parameters:
T
- the payload type.- Parameters:
links
- must not be null.- Returns:
- will never be null.
-
empty
Creates an emptySlicedModel
with the given links.- Type Parameters:
T
- the payload type.- Parameters:
links
- must not be null.- Returns:
- will never be null.
-
empty
Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
.- Type Parameters:
T
- the payload type.- Parameters:
metadata
- can be null.- Returns:
- will never be null.
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, Class<?> fallbackType, Class<?>... generics) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and fallback type.- Type Parameters:
T
- the payload type.- Parameters:
metadata
- can be null.fallbackType
- must not be null.generics
- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, ParameterizedTypeReference<T> fallbackType) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and fallback type.- Type Parameters:
T
- the payload type.- Parameters:
metadata
- can be null.- Returns:
- will never be null.
- See Also:
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, ResolvableType fallbackType) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and fallback type.- Type Parameters:
T
-- Parameters:
metadata
- can be null.fallbackType
- must not be null.- Returns:
- See Also:
-
empty
Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and links.- Type Parameters:
T
-- Parameters:
metadata
- can be null.links
- must not be null.- Returns:
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links) Creates an emptySlicedModel
with the givenSlicedModel.SliceMetadata
and links.- Type Parameters:
T
- the payload type.- Parameters:
metadata
- can be null.links
- must not be null.- Returns:
- will never be null.
-
of
public static <T> SlicedModel<T> of(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata) - Type Parameters:
T
- the payload type.- Parameters:
content
- must not be null.metadata
- can be null.- Returns:
- will never be null.
-
of
public static <T> SlicedModel<T> of(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Link... links) - Type Parameters:
T
- the payload type.- Parameters:
content
- must not be null.metadata
- can be null.links
- must not be null.- Returns:
- will never be null.
-
of
public static <T> SlicedModel<T> of(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links) - Type Parameters:
T
- the payload type.- Parameters:
content
- must not be null.metadata
- can be null.links
- must not be null.- Returns:
- will never be null.
-
wrap
public static <T extends EntityModel<S>,S> SlicedModel<T> wrap(Iterable<S> content, SlicedModel.SliceMetadata metadata) Factory method to easily create aSlicedModel
instance from a set of entities and pagination metadata.- Type Parameters:
T
- the nestedEntityModel
type.S
- the actual payload type.- Parameters:
content
- must not be null.metadata
-- Returns:
- will never be null.
-
getMetadata
Returns the pagination metadata.- Returns:
- the metadata can be null.
-
getNextLink
Returns theLink
pointing to the next slice (if set).- Returns:
- will never be null.
-
getPreviousLink
Returns theLink
pointing to the previous slice (if set).- 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.
-
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>
-